|
From: <tho...@us...> - 2013-09-12 21:01:05
|
Revision: 7402
http://bigdata.svn.sourceforge.net/bigdata/?rev=7402&view=rev
Author: thompsonbry
Date: 2013-09-12 21:00:56 +0000 (Thu, 12 Sep 2013)
Log Message:
-----------
Added a very simple graph model for GAS graph mining. It uses a collection of vertices and linked hash sets for the in-edges, out-edges, and property values. This passes the basic "TestGather". I have written an extension to load data into this. It is ready for testing against a larger data set. The purpose is to replace the memory sail, which is way to slow when loading the data, and provide a basis for understanding the overhead associated with graph traversal versus object decoding as a pre-cursor to an exploration of column-wise indexing for graph mining.
See #629 (Graph Mining API)
Modified Paths:
--------------
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/sail/SAILGASRunner.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/AbstractGraphFixture.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GASUtil.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/TestAll.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASRunner.java
Added Paths:
-----------
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASRunner.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphFixture.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/package.html
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/AbstractRAMGraphTestCase.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestAll.java
branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestGather.java
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,360 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.impl.ram;
+
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.ValueFactoryImpl;
+import org.openrdf.sail.SailException;
+
+import com.bigdata.rdf.graph.EdgesEnum;
+import com.bigdata.rdf.graph.IGASContext;
+import com.bigdata.rdf.graph.IGASProgram;
+import com.bigdata.rdf.graph.IGraphAccessor;
+import com.bigdata.rdf.graph.impl.GASEngine;
+import com.bigdata.rdf.graph.impl.util.VertexDistribution;
+
+import cutthecrap.utils.striterators.EmptyIterator;
+import cutthecrap.utils.striterators.IStriterator;
+import cutthecrap.utils.striterators.Striterator;
+
+public class RAMGASEngine extends GASEngine {
+
+ public RAMGASEngine(int nthreads) {
+ super(nthreads);
+ }
+
+ /**
+ * Returns <code>false</code>. There is no intrinsic ordering that can
+ * improve access for this implementation.
+ */
+ @Override
+ public boolean getSortFrontier() {
+ return false;
+ }
+
+ /**
+ * A simple RDF graph model suitable for graph mining algorithms.
+ *
+ * TODO This model does not support link weights. It was developed to
+ * provide an implementation without any object encode/decode overhead that
+ * could be used to explore the possible performance of GAS algorithms under
+ * Java.
+ *
+ * @author <a href="mailto:tho...@us...">Bryan
+ * Thompson</a>
+ */
+ static public class RAMGraph {
+
+ private final ValueFactory vf;
+ public ValueFactory getValueFactory() {
+ return vf;
+ }
+
+ /**
+ * From a vertex, we can visit the in-edges, out-edges, or attribute
+ * values. These things are organized into three sets of statements. A
+ * non-thread-safe collection is used to provide the distinct semantics
+ * for those sets and fast traversal. This design precludes the ability
+ * to concurrently modify the graph during graph traversal operations.
+ */
+ static private class Vertex {
+
+ /** The {@link Value} for that {@link Vertex}. */
+ final private Value v;
+ /**
+ * The distinct set of in-edges for this {@link Vertex}.
+ * <p>
+ * The {@link Statement#getObject()} for each {@link Statement} in
+ * this collection will be the {@link #v}.
+ */
+ private Set<Statement> inEdges = null;
+ /**
+ * The distinct set of out-edges for this {@link Vertex}.
+ * <p>
+ * The {@link Statement#getSubject()} for each {@link Statement} in
+ * this collection will be the {@link #v}.
+ */
+ private Set<Statement> outEdges = null;
+ /**
+ * The distinct set of property values for this {@link Vertex}.
+ * <p>
+ * The {@link Statement#getSubject()} for each {@link Statement} in
+ * this collection will be the {@link #v}.
+ * <p>
+ * The {@link Statement#getObject()} for each {@link Statement} in
+ * this collection will be a {@link URI}.
+ */
+ private Set<Statement> attribs = null;
+
+ public Vertex(final Value v) {
+ if (v == null)
+ throw new NullPointerException();
+ this.v = v;
+ }
+ @Override
+ public String toString() {
+ return "Vertex{" + v + ",inEdges=" + getInEdgeCount()
+ + ",outEdges=" + getOutEdgeCount() + ",attribs="
+ + getAttribCount() + "}";
+ }
+
+ private boolean addAttrib(final Statement s) {
+ if (attribs == null) {
+ attribs = new LinkedHashSet<Statement>();
+ }
+ return attribs.add(s);
+ }
+
+ private boolean addOutEdge(final Statement s) {
+ if (outEdges == null) {
+ outEdges = new LinkedHashSet<Statement>();
+ }
+ return outEdges.add(s);
+ }
+
+ private boolean addInEdge(final Statement s) {
+ if (inEdges == null) {
+ inEdges = new LinkedHashSet<Statement>();
+ }
+ return inEdges.add(s);
+ }
+
+ public int getAttribCount() {
+ return attribs == null ? 0 : attribs.size();
+ }
+
+ public int getInEdgeCount() {
+ return inEdges == null ? 0 : inEdges.size();
+ }
+
+ public int getOutEdgeCount() {
+ return outEdges == null ? 0 : outEdges.size();
+ }
+
+ public Iterator<Statement> inEdges() {
+ if (inEdges == null)
+ return EmptyIterator.DEFAULT;
+ return inEdges.iterator();
+ }
+
+ public Iterator<Statement> outEdges() {
+ if (outEdges == null)
+ return EmptyIterator.DEFAULT;
+ return outEdges.iterator();
+ }
+
+ public Iterator<Statement> attribs() {
+ if (attribs == null)
+ return EmptyIterator.DEFAULT;
+ return attribs.iterator();
+ }
+
+ }
+
+ /**
+ * The vertices.
+ */
+ private final ConcurrentMap<Value,Vertex> vertices;
+
+ public RAMGraph() {
+
+ vertices = new ConcurrentHashMap<Value, Vertex>();
+
+ vf = new ValueFactoryImpl();
+
+ }
+
+ /**
+ * Lookup / create a vertex.
+ *
+ * @param x
+ * The {@link Value}.
+ * @param create
+ * when <code>true</code> the {@link Vertex} will be created
+ * if it does not exist.
+ *
+ * @return The {@link Vertex}.
+ */
+ private Vertex get(final Value x, final boolean create) {
+
+ Vertex v = vertices.get(x);
+
+ if (v == null && create) {
+
+ final Vertex oldVal = vertices
+ .putIfAbsent(x, v = new Vertex(x));
+
+ if (oldVal != null) {
+
+ // lost data race.
+ v = oldVal;
+
+ }
+
+ }
+
+ return v;
+
+ }
+
+ public boolean add(final Statement st) {
+
+ final Resource s = st.getSubject();
+
+ final Value o = st.getObject();
+
+ boolean modified = false;
+ if (o instanceof URI) {
+ // Edge
+ modified|=get(s, true/* create */).addOutEdge(st);
+ modified|=get(o, true/* create */).addInEdge(st);
+ } else {
+ // Property value.
+ modified|=get(s, true/* create */).addAttrib(st);
+ }
+ return modified;
+
+ }
+
+ public Iterator<Statement> inEdges(final Value v) {
+ final Vertex x = get(v, false/* create */);
+ if (x == null)
+ return EmptyIterator.DEFAULT;
+ return x.inEdges();
+ }
+
+ public Iterator<Statement> outEdges(final Value v) {
+ final Vertex x = get(v, false/* create */);
+ if (x == null)
+ return EmptyIterator.DEFAULT;
+ return x.outEdges();
+ }
+ public Iterator<Statement> attribs(final Value v) {
+ final Vertex x = get(v, false/* create */);
+ if (x == null)
+ return EmptyIterator.DEFAULT;
+ return x.attribs();
+ }
+
+ } // class RAMGraph
+
+ static public class RAMGraphAccessor implements IGraphAccessor {
+
+ private final RAMGraph g;
+
+ public RAMGraphAccessor(final RAMGraph g) {
+ if (g == null)
+ throw new IllegalArgumentException();
+ this.g = g;
+ }
+
+ @Override
+ public void advanceView() {
+ // NOP
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<Statement> getEdges(final IGASContext<?, ?, ?> p,
+ final Value u, final EdgesEnum edges) {
+
+ try {
+ switch (edges) {
+ case NoEdges:
+ return EmptyIterator.DEFAULT;
+ case InEdges:
+ return getEdges(true/* inEdges */, p, u);
+ case OutEdges:
+ return getEdges(false/* inEdges */, p, u);
+ case AllEdges: {
+ final IStriterator a = getEdges(true/* inEdges */, p, u);
+ final IStriterator b = getEdges(false/* outEdges */, p, u);
+ a.append(b);
+ return a;
+ }
+ default:
+ throw new UnsupportedOperationException(edges.name());
+ }
+ } catch (SailException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private IStriterator getEdges(final boolean inEdges,
+ final IGASContext<?, ?, ?> ctx, final Value u)
+ throws SailException {
+
+ final URI linkTypeIV = (URI) ctx.getGASProgram().getLinkType();
+ if(linkTypeIV != null) {
+ /*
+ * FIXME RDR: We need to use a union of access paths for link
+ * attributes for the generic SAIL since it does not have the
+ * concept of statements about statements. This will require
+ * applying the access paths that will visit the appropriate
+ * reified triples. This needs to be done for both the standard
+ * path and the POS optimization code path.
+ */
+ throw new UnsupportedOperationException();
+ }
+ final Striterator sitr;
+ if(inEdges) {
+ sitr = new Striterator(g.get(u, false/*create*/).inEdges());
+ } else {
+ sitr = new Striterator(g.get(u, false/*create*/).outEdges());
+ }
+ /*
+ * Optionally wrap the program specified filter.
+ */
+ return ((IGASProgram) ctx.getGASProgram()).constrainFilter(ctx,
+ sitr);
+
+ }
+
+ @Override
+ public VertexDistribution getDistribution(final Random r) {
+
+ final VertexDistribution sample = new VertexDistribution(r);
+
+ for (Value v : g.vertices.keySet()) {
+
+ if (v instanceof Resource) {
+
+ sample.addSample((Resource) v);
+
+ }
+
+ }
+
+ return sample;
+
+ }
+
+ }
+
+}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASRunner.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASRunner.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASRunner.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,130 @@
+package com.bigdata.rdf.graph.impl.ram;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.log4j.Logger;
+
+import com.bigdata.rdf.graph.IGASEngine;
+import com.bigdata.rdf.graph.IGraphAccessor;
+import com.bigdata.rdf.graph.impl.ram.RAMGASEngine.RAMGraph;
+import com.bigdata.rdf.graph.impl.ram.RAMGASEngine.RAMGraphAccessor;
+import com.bigdata.rdf.graph.impl.util.GASRunnerBase;
+
+/**
+ * Class for running GAS performance tests against the SAIL.
+ *
+ * @author <a href="mailto:tho...@us...">Bryan Thompson</a>
+ */
+public class RAMGASRunner<VS, ES, ST> extends GASRunnerBase<VS, ES, ST> {
+
+ private static final Logger log = Logger.getLogger(RAMGASRunner.class);
+
+ public RAMGASRunner(String[] args) throws ClassNotFoundException {
+ super(args);
+ }
+
+ protected class RAMOptionData extends GASRunnerBase<VS, ES, ST>.OptionData {
+
+ final private RAMGraph g = new RAMGraph();
+
+ public RAMGraph getGraph() {
+ synchronized(g) {
+ /*
+ * Note: Synchronization pattern is intended to provide
+ * visibility for graph traversal following a load of data into
+ * the graph.
+ */
+ return g;
+ }
+ }
+
+ @Override
+ public void init() throws Exception {
+
+ super.init();
+
+ }
+
+ @Override
+ public void shutdown() {
+
+ }
+ @Override
+ public boolean handleArg(final AtomicInteger i, final String[] args) {
+ if (super.handleArg(i, args)) {
+ return true;
+ }
+// final String arg = args[i.get()];
+// if (arg.equals("-bufferMode")) {
+// final String s = args[i.incrementAndGet()];
+// bufferModeOverride = BufferMode.valueOf(s);
+// } else if (arg.equals("-namespace")) {
+// final String s = args[i.incrementAndGet()];
+// namespaceOverride = s;
+// } else {
+// return false;
+// }
+ return false;
+ }
+
+ @Override
+ public void report(final StringBuilder sb) {
+ // NOP
+ }
+
+ } // class SAILOptionData
+
+ @Override
+ protected RAMOptionData newOptionData() {
+
+ return new RAMOptionData();
+
+ }
+
+ @Override
+ protected IGASEngine newGASEngine() {
+
+ return new RAMGASEngine(getOptionData().nthreads);
+
+ }
+
+ @Override
+ protected void loadFiles() throws Exception {
+
+ final RAMOptionData opt = getOptionData();
+
+ final String[] resources = opt.loadSet.toArray(new String[0]);
+
+ new RAMGraphLoader(opt.getGraph()).loadGraph(null/* fallback */,
+ resources);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected RAMOptionData getOptionData() {
+
+ return (RAMOptionData) super.getOptionData();
+
+ }
+
+ @Override
+ protected IGraphAccessor newGraphAccessor() {
+
+ return new RAMGraphAccessor(getOptionData().g);
+
+ }
+
+ /**
+ * Performance testing harness.
+ *
+ * @see #GASRunner(String[])
+ */
+ @SuppressWarnings("rawtypes")
+ public static void main(final String[] args) throws Exception {
+
+ new RAMGASRunner(args).call();
+
+ }
+
+}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphFixture.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphFixture.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphFixture.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,68 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.impl.ram;
+
+import org.openrdf.sail.Sail;
+import org.openrdf.sail.SailConnection;
+import org.openrdf.sail.SailException;
+import org.openrdf.sail.memory.MemoryStore;
+
+import com.bigdata.rdf.graph.IGASEngine;
+import com.bigdata.rdf.graph.IGraphAccessor;
+import com.bigdata.rdf.graph.impl.ram.RAMGASEngine.RAMGraph;
+import com.bigdata.rdf.graph.impl.sail.SAILGASEngine.SAILGraphAccessor;
+import com.bigdata.rdf.graph.util.AbstractGraphFixture;
+
+public class RAMGraphFixture extends AbstractGraphFixture {
+
+ private RAMGraph g;
+
+ public RAMGraphFixture() throws SailException {
+ g = new RAMGraph();
+ }
+
+ public Sail getSail() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Return the {@link RAMGraphFixture}.
+ */
+ public RAMGraph getGraph() {
+ return g;
+ }
+
+ @Override
+ public void destroy() throws SailException {
+ g = null;
+ }
+
+ @Override
+ public IGASEngine newGASEngine(int nthreads) {
+
+ return new RAMGASEngine(nthreads);
+
+ }
+
+ @Override
+ public IGraphAccessor newGraphAccessor(SailConnection cxnIsIgnored) {
+
+// return new RAMGraphAccessor(cxnIsIgnored);
+ throw new UnsupportedOperationException();
+
+ }
+
+}
\ No newline at end of file
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,55 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.impl.ram;
+
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.sail.SailException;
+
+import com.bigdata.rdf.graph.impl.ram.RAMGASEngine.RAMGraph;
+import com.bigdata.rdf.graph.util.GraphLoader;
+
+public class RAMGraphLoader extends GraphLoader {
+
+ private final RAMGraph g;
+
+ public RAMGraphLoader(final RAMGraph g) {
+ if (g == null)
+ throw new IllegalArgumentException();
+ this.g = g;
+ }
+
+ @Override
+ protected AddStatementHandler newStatementHandler() {
+ return new RAMStatementHandler();
+ }
+
+ private class RAMStatementHandler extends AddStatementHandler {
+
+ @Override
+ protected void addStatement(final Statement stmt, final Resource[] c)
+ throws RDFHandlerException {
+
+ g.add(stmt);
+
+ ntriples++;
+
+ }
+
+ }
+
+}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/package.html
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/package.html (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/package.html 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,14 @@
+<html>
+<head>
+<title>GAS Engine for RAM</title>
+</head>
+<body>
+ <p>This is an implementation of the GAS API for the Java concurrency
+ class. This package is designed to have no object encoding and
+ decoding overhead and to support high concurrency operations on the
+ graph. It does NOT implement the SAIL. Instead, it provides an RDF
+ graph abstraction using the openrdf data model that support efficient
+ operations for the GAS API (basically, efficient access to the
+ in-edges, out-edges, and attribute values).</p>
+</body>
+</html>
\ No newline at end of file
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/sail/SAILGASRunner.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/sail/SAILGASRunner.java 2013-09-12 17:07:59 UTC (rev 7401)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/sail/SAILGASRunner.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -1,3 +1,18 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
package com.bigdata.rdf.graph.impl.sail;
import java.util.concurrent.atomic.AtomicInteger;
@@ -13,7 +28,7 @@
import com.bigdata.rdf.graph.IGraphAccessor;
import com.bigdata.rdf.graph.impl.sail.SAILGASEngine.SAILGraphAccessor;
import com.bigdata.rdf.graph.impl.util.GASRunnerBase;
-import com.bigdata.rdf.graph.util.GASUtil;
+import com.bigdata.rdf.graph.util.SailGraphLoader;
/**
* Class for running GAS performance tests against the SAIL.
@@ -136,7 +151,7 @@
SailConnection cxn = null;
try {
cxn = opt.cxn;
- new GASUtil().loadGraph(cxn, null/* fallback */, resources);
+ new SailGraphLoader(cxn).loadGraph(null/* fallback */, resources);
cxn.commit();
ok = true;
} finally {
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/AbstractGraphFixture.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/AbstractGraphFixture.java 2013-09-12 17:07:59 UTC (rev 7401)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/AbstractGraphFixture.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -28,7 +28,7 @@
SailConnection cxn = null;
try {
cxn = getSail().getConnection();
- new GASUtil().loadGraph(cxn, null/* fallback */, resources);
+ new SailGraphLoader(cxn).loadGraph(null/* fallback */, resources);
cxn.commit();
ok = true;
} finally {
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GASUtil.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GASUtil.java 2013-09-12 17:07:59 UTC (rev 7401)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GASUtil.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -15,34 +15,11 @@
*/
package com.bigdata.rdf.graph.util;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import org.apache.log4j.Logger;
-import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.Value;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFHandlerException;
-import org.openrdf.rio.RDFParseException;
-import org.openrdf.rio.RDFParser;
-import org.openrdf.rio.RDFParserFactory;
-import org.openrdf.rio.RDFParserRegistry;
-import org.openrdf.rio.helpers.RDFHandlerBase;
-import org.openrdf.sail.SailConnection;
-import org.openrdf.sail.SailException;
import cutthecrap.utils.striterators.EmptyIterator;
@@ -53,7 +30,7 @@
*/
public class GASUtil {
- private static final Logger log = Logger.getLogger(GASUtil.class);
+// private static final Logger log = Logger.getLogger(GASUtil.class);
/**
* The average fan out of the frontier.
@@ -113,306 +90,4 @@
@SuppressWarnings({ "unchecked" })
public static final Iterator<Statement> EMPTY_EDGES_ITERATOR = EmptyIterator.DEFAULT;
- /**
- * Return the best guess at the {@link RDFFormat} for a resource.
- * <p>
- * Note: This handles the .gz and .zip extensions.
- *
- * @param n
- * The name of the resource.
- * @param rdfFormat
- * The fallback format (optional).
- *
- * @return The best guess format.
- */
- private RDFFormat guessRDFFormat(final String n, final RDFFormat rdfFormat) {
-
- RDFFormat fmt = RDFFormat.forFileName(n);
-
- if (fmt == null && n.endsWith(".zip")) {
- fmt = RDFFormat.forFileName(n.substring(0, n.length() - 4));
- }
-
- if (fmt == null && n.endsWith(".gz")) {
- fmt = RDFFormat.forFileName(n.substring(0, n.length() - 3));
- }
-
- if (fmt == null) // fallback
- fmt = rdfFormat;
-
- return fmt;
-
- }
-
- public void loadGraph(final SailConnection cxn, final RDFFormat fallback,
- final String... resources) throws Exception {
-
- if (resources != null) {
-
- for (String resource : resources) {
-
- loadGraph(cxn, fallback, resource);
-
- }
-
- }
-
- }
-
- /**
- * Load a resource from the classpath, the file system, or a URI. GZ
- * compressed files are decompressed. Directories are processed recursively.
- * The entries in a ZIP archive are processed. Resources that are not
- * recognized as some {@link RDFFormat} will be ignored unless the
- * <i>fallback</i> argument is given, in which case that format will be
- * <em>assumed</em> for such resources.
- *
- * @param cxn
- * The connection used to load the data.
- * @param resource
- * A resource on the class path, a file or a directory, or a URI.
- * @param fallback
- * The default {@link RDFFormat} to be assumed (optional).
- *
- * @throws IOException
- * @throws URISyntaxException
- * @throws RDFHandlerException
- * @throws RDFParseException
- */
- public void loadGraph(final SailConnection cxn, final RDFFormat fallback,
- final String resource) throws IOException, URISyntaxException,
- RDFParseException, RDFHandlerException {
-
- if (log.isInfoEnabled())
- log.info("Loading: " + resource);
-
- String baseURI = null;
-
- InputStream is = null;
- try {
-
- // try the classpath
- is = getClass().getResourceAsStream(resource);
-
- if (is != null) {
-
- // set for resource on classpath.
- baseURI = getClass().getResource(resource).toURI().toString();
-
- } else {
-
- // try file system.
- final File file = new File(resource);
-
- if (file.exists()) {
-
- if (file.isDirectory()) {
-
- /*
- * Recursion.
- */
-
- final File[] a = file.listFiles();
-
- for (File f : a) {
-
- loadGraph(cxn, fallback, f.toString());
-
- }
-
- }
-
- is = new FileInputStream(file);
-
- // set for file as URI.
- baseURI = file.toURI().toString();
-
- } else {
-
- throw new FileNotFoundException(
- "Could not locate resource: " + resource);
-
- }
-
- }
-
- if (resource.endsWith(".gz")) {
-
- is = new GZIPInputStream(is);
-
- } else if (resource.endsWith(".zip")) {
-
- final ZipInputStream zis = new ZipInputStream(is);
-
- try {
-
- ZipEntry e;
-
- while ((e = zis.getNextEntry()) != null) {
-
- if (e.isDirectory()) {
-
- // skip directories.
- continue;
- }
-
- baseURI = resource + "/" + e.getName();
-
- loadFromStream(cxn, zis, resource, baseURI, fallback);
-
- final RDFFormat format = guessRDFFormat(e.getName(),
- fallback);
-
- if (format == null) {
-
- if (log.isInfoEnabled())
- log.info("Skipping non-RDF entry: resource="
- + resource + ", entry=" + e.getName());
-
- continue;
-
- }
-
- }
-
- return;
-
- } finally {
-
- zis.close();
-
- }
-
- }
-
- loadFromStream(cxn, is, resource, baseURI, fallback);
-
- } finally {
-
- if (is != null) {
-
- try {
- is.close();
- } catch (Throwable t) {
- log.error(t);
- }
-
- }
-
- }
-
- }
-
- private void loadFromStream(final SailConnection cxn, final InputStream is,
- final String resource, final String baseURI,
- final RDFFormat fallback) throws RDFParseException,
- RDFHandlerException, IOException {
-
- // guess at the RDF Format
- final RDFFormat rdfFormat = guessRDFFormat(resource, fallback);
-
- if (rdfFormat == null) {
-
- if (log.isInfoEnabled())
- log.info("Skipping non-RDF resource: " + resource);
-
- return;
-
- }
-
- /*
- * Obtain a buffered reader on the input stream.
- */
- final Reader reader = new BufferedReader(new InputStreamReader(
- is));
-
- try {
-
- final RDFParserFactory rdfParserFactory = RDFParserRegistry
- .getInstance().get(rdfFormat);
-
- final RDFParser rdfParser = rdfParserFactory.getParser();
-
- rdfParser.setStopAtFirstError(false);
-
- final AddStatementHandler h = new AddStatementHandler(cxn);
-
- rdfParser.setRDFHandler(h);
-
- /*
- * Run the parser, which will cause statements to be
- * inserted.
- */
-
- rdfParser.parse(reader, baseURI);
-
- if (log.isInfoEnabled())
- log.info("Done: " + resource + ", nread=" + h.ntriples);
-
- } finally {
-
- try {
- reader.close();
- } catch (Throwable t) {
- log.error(t);
- }
-
- }
-
- }
-
- /**
- * Helper class adds statements to the sail as they are visited by a parser.
- */
- private static class AddStatementHandler extends RDFHandlerBase {
-
- private final SailConnection conn;
- /**
- * Only used if the statements themselves do not have a context.
- */
- private final Resource[] defaultContext;
-
- private long ntriples = 0;
-
- /**
- *
- * @param conn
- */
- public AddStatementHandler(final SailConnection conn) {
- this.conn = conn;
- this.defaultContext = new Resource[0];
- }
-
- public void handleStatement(final Statement stmt)
- throws RDFHandlerException {
-
- final Resource[] c = (Resource[])
- (stmt.getContext() == null
- ? defaultContext
- : new Resource[] { stmt.getContext() });
-
- try {
-
- conn.addStatement(//
- stmt.getSubject(), //
- stmt.getPredicate(), //
- stmt.getObject(), //
- c
- );
-
- if (c == null || c.length == 0)
- ntriples++;
- else
- ntriples += c.length;
-
- } catch (SailException e) {
-
- throw new RDFHandlerException(e);
-
- }
-
- }
-
- }
-
}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,340 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.util;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URISyntaxException;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.log4j.Logger;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.rio.RDFParser;
+import org.openrdf.rio.RDFParserFactory;
+import org.openrdf.rio.RDFParserRegistry;
+import org.openrdf.rio.helpers.RDFHandlerBase;
+
+/**
+ * Utility to load data into a graph.
+ *
+ * @author <a href="mailto:tho...@us...">Bryan Thompson</a>
+ */
+abstract public class GraphLoader {
+
+ private static final Logger log = Logger.getLogger(GASUtil.class);
+
+ /**
+ * Return the best guess at the {@link RDFFormat} for a resource.
+ * <p>
+ * Note: This handles the .gz and .zip extensions.
+ *
+ * @param n
+ * The name of the resource.
+ * @param rdfFormat
+ * The fallback format (optional).
+ *
+ * @return The best guess format.
+ */
+ private RDFFormat guessRDFFormat(final String n, final RDFFormat rdfFormat) {
+
+ RDFFormat fmt = RDFFormat.forFileName(n);
+
+ if (fmt == null && n.endsWith(".zip")) {
+ fmt = RDFFormat.forFileName(n.substring(0, n.length() - 4));
+ }
+
+ if (fmt == null && n.endsWith(".gz")) {
+ fmt = RDFFormat.forFileName(n.substring(0, n.length() - 3));
+ }
+
+ if (fmt == null) // fallback
+ fmt = rdfFormat;
+
+ return fmt;
+
+ }
+
+ public void loadGraph(final RDFFormat fallback,
+ final String... resources) throws Exception {
+
+ if (resources != null) {
+
+ for (String resource : resources) {
+
+ loadGraph(fallback, resource);
+
+ }
+
+ }
+
+ }
+
+ /**
+ * Load a resource from the classpath, the file system, or a URI. GZ
+ * compressed files are decompressed. Directories are processed recursively.
+ * The entries in a ZIP archive are processed. Resources that are not
+ * recognized as some {@link RDFFormat} will be ignored unless the
+ * <i>fallback</i> argument is given, in which case that format will be
+ * <em>assumed</em> for such resources.
+ *
+ * @param resource
+ * A resource on the class path, a file or a directory, or a URI.
+ * @param fallback
+ * The default {@link RDFFormat} to be assumed (optional).
+ *
+ * @throws IOException
+ * @throws URISyntaxException
+ * @throws RDFHandlerException
+ * @throws RDFParseException
+ */
+ public void loadGraph(final RDFFormat fallback,
+ final String resource) throws IOException, URISyntaxException,
+ RDFParseException, RDFHandlerException {
+
+ if (log.isInfoEnabled())
+ log.info("Loading: " + resource);
+
+ String baseURI = null;
+
+ InputStream is = null;
+ try {
+
+ // try the classpath
+ is = getClass().getResourceAsStream(resource);
+
+ if (is != null) {
+
+ // set for resource on classpath.
+ baseURI = getClass().getResource(resource).toURI().toString();
+
+ } else {
+
+ // try file system.
+ final File file = new File(resource);
+
+ if (file.exists()) {
+
+ if (file.isDirectory()) {
+
+ /*
+ * Recursion.
+ */
+
+ final File[] a = file.listFiles();
+
+ for (File f : a) {
+
+ loadGraph(fallback, f.toString());
+
+ }
+
+ }
+
+ is = new FileInputStream(file);
+
+ // set for file as URI.
+ baseURI = file.toURI().toString();
+
+ } else {
+
+ throw new FileNotFoundException(
+ "Could not locate resource: " + resource);
+
+ }
+
+ }
+
+ if (resource.endsWith(".gz")) {
+
+ is = new GZIPInputStream(is);
+
+ } else if (resource.endsWith(".zip")) {
+
+ final ZipInputStream zis = new ZipInputStream(is);
+
+ try {
+
+ ZipEntry e;
+
+ while ((e = zis.getNextEntry()) != null) {
+
+ if (e.isDirectory()) {
+
+ // skip directories.
+ continue;
+ }
+
+ baseURI = resource + "/" + e.getName();
+
+ loadFromStream(zis, resource, baseURI, fallback);
+
+ final RDFFormat format = guessRDFFormat(e.getName(),
+ fallback);
+
+ if (format == null) {
+
+ if (log.isInfoEnabled())
+ log.info("Skipping non-RDF entry: resource="
+ + resource + ", entry=" + e.getName());
+
+ continue;
+
+ }
+
+ }
+
+ return;
+
+ } finally {
+
+ zis.close();
+
+ }
+
+ }
+
+ loadFromStream(is, resource, baseURI, fallback);
+
+ } finally {
+
+ if (is != null) {
+
+ try {
+ is.close();
+ } catch (Throwable t) {
+ log.error(t);
+ }
+
+ }
+
+ }
+
+ }
+
+ private void loadFromStream(final InputStream is,
+ final String resource, final String baseURI,
+ final RDFFormat fallback) throws RDFParseException,
+ RDFHandlerException, IOException {
+
+ // guess at the RDF Format
+ final RDFFormat rdfFormat = guessRDFFormat(resource, fallback);
+
+ if (rdfFormat == null) {
+
+ if (log.isInfoEnabled())
+ log.info("Skipping non-RDF resource: " + resource);
+
+ return;
+
+ }
+
+ /*
+ * Obtain a buffered reader on the input stream.
+ */
+ final Reader reader = new BufferedReader(new InputStreamReader(
+ is));
+
+ try {
+
+ final RDFParserFactory rdfParserFactory = RDFParserRegistry
+ .getInstance().get(rdfFormat);
+
+ final RDFParser rdfParser = rdfParserFactory.getParser();
+
+ rdfParser.setStopAtFirstError(false);
+
+ final AddStatementHandler h = newStatementHandler();
+
+ rdfParser.setRDFHandler(h);
+
+ /*
+ * Run the parser, which will cause statements to be
+ * inserted.
+ */
+
+ rdfParser.parse(reader, baseURI);
+
+ if (log.isInfoEnabled())
+ log.info("Done: " + resource + ", nread=" + h.ntriples);
+
+ } finally {
+
+ try {
+ reader.close();
+ } catch (Throwable t) {
+ log.error(t);
+ }
+
+ }
+
+ }
+
+ /**
+ * Factory for the helper class that adds statements to the target
+ * graph.
+ */
+ protected abstract AddStatementHandler newStatementHandler();
+
+ /**
+ * Helper class adds statements to the sail as they are visited by a parser.
+ */
+ protected abstract class AddStatementHandler extends RDFHandlerBase {
+
+ /**
+ * Only used if the statements themselves do not have a context.
+ */
+ private final Resource[] defaultContext;
+
+ protected long ntriples = 0;
+
+ /**
+ *
+ * @param conn
+ */
+ public AddStatementHandler() {
+ this.defaultContext = new Resource[0];
+ }
+
+ public void handleStatement(final Statement stmt)
+ throws RDFHandlerException {
+
+ final Resource[] c = (Resource[])
+ (stmt.getContext() == null
+ ? defaultContext
+ : new Resource[] { stmt.getContext() });
+
+ addStatement(stmt, c);
+
+ }
+
+ abstract protected void addStatement(final Statement stmt,
+ final Resource[] c) throws RDFHandlerException;
+
+ }
+
+}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,78 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.util;
+
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.rio.RDFHandlerException;
+import org.openrdf.sail.SailConnection;
+import org.openrdf.sail.SailException;
+
+public class SailGraphLoader extends GraphLoader {
+
+ /**
+ * The connection used to load the data.
+ */
+ private final SailConnection cxn;
+
+ /**
+ *
+ * @param cxn
+ * The connection used to load the data.
+ */
+ public SailGraphLoader(final SailConnection cxn) {
+
+ this.cxn = cxn;
+
+ }
+
+ @Override
+ protected AddStatementHandler newStatementHandler() {
+
+ return new SailStatementHandler();
+
+ }
+
+ private class SailStatementHandler extends AddStatementHandler {
+
+ @Override
+ protected void addStatement(final Statement stmt, final Resource[] c)
+ throws RDFHandlerException {
+
+ try {
+
+ cxn.addStatement(//
+ stmt.getSubject(), //
+ stmt.getPredicate(), //
+ stmt.getObject(), //
+ c);
+
+ if (c == null || c.length == 0)
+ ntriples++;
+ else
+ ntriples += c.length;
+
+ } catch (SailException e) {
+
+ throw new RDFHandlerException(e);
+
+ }
+
+ }
+
+ }
+
+}
Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/TestAll.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/TestAll.java 2013-09-12 17:07:59 UTC (rev 7401)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/TestAll.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -51,6 +51,8 @@
suite.addTest(com.bigdata.rdf.graph.impl.sail.TestAll.suite());
+ suite.addTest(com.bigdata.rdf.graph.impl.ram.TestAll.suite());
+
suite.addTest(com.bigdata.rdf.graph.analytics.TestAll.suite());
return suite;
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/AbstractRAMGraphTestCase.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/AbstractRAMGraphTestCase.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/AbstractRAMGraphTestCase.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,164 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.impl.ram;
+
+import org.openrdf.model.URI;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.vocabulary.RDF;
+import org.openrdf.model.vocabulary.RDFS;
+
+import com.bigdata.rdf.graph.AbstractGraphTestCase;
+import com.bigdata.rdf.graph.impl.ram.RAMGASEngine.RAMGraph;
+import com.bigdata.rdf.graph.util.IGraphFixture;
+import com.bigdata.rdf.graph.util.IGraphFixtureFactory;
+
+public class AbstractRAMGraphTestCase extends AbstractGraphTestCase {
+
+// private static final Logger log = Logger
+// .getLogger(AbstractGraphTestCase.class);
+
+ public AbstractRAMGraphTestCase() {
+ }
+
+ public AbstractRAMGraphTestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected IGraphFixtureFactory getGraphFixtureFactory() {
+
+ return new IGraphFixtureFactory() {
+
+ @Override
+ public IGraphFixture newGraphFixture() throws Exception {
+ return new RAMGraphFixture();
+ }
+
+ };
+
+ }
+
+ @Override
+ protected RAMGraphFixture getGraphFixture() {
+
+ return (RAMGraphFixture) super.getGraphFixture();
+
+ }
+
+ /**
+ * A small foaf data set relating some of the project contributors (triples
+ * mode data).
+ *
+ * @see {@value #smallGraph}
+ *
+ * @author <a href="mailto:tho...@us...">Bryan Thompson</a>
+ */
+ protected class SmallGraphProblem {
+
+ private final URI rdfType, rdfsLabel, foafKnows, foafPerson, mike,
+ bryan, martyn, dc;
+
+ /**
+ * The data:
+ *
+ * <pre>
+ * @prefix : <http://www.bigdata.com/> .
+ * @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+ * @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ * @prefix foaf: <http://xmlns.com/foaf/0.1/> .
+ *
+ * #: {
+ * :Mike rdf:type foaf:Person .
+ * :Bryan rdf:type foaf:Person .
+ * :Martyn rdf:type foaf:Person .
+ *
+ * :Mike rdfs:label "Mike" .
+ * :Bryan rdfs:label "Bryan" .
+ * :DC rdfs:label "DC" .
+ *
+ * :Mike foaf:knows :Bryan .
+ * :Bryan foaf:knows :Mike .
+ * :Bryan foaf:knows :Martyn .
+ * :Martyn foaf:knows :Bryan .
+ * #}
+ * </pre>
+ */
+ public SmallGraphProblem() throws Exception {
+
+ final RAMGraph g = getGraphFixture().getGraph();
+
+ final ValueFactory vf = g.getValueFactory();
+
+ rdfType = vf.createURI(RDF.TYPE.stringValue());
+ rdfsLabel = vf.createURI(RDFS.LABEL.stringValue());
+ foafKnows = vf.createURI("http://xmlns.com/foaf/0.1/knows");
+ foafPerson = vf.createURI("http://xmlns.com/foaf/0.1/Person");
+ mike = vf.createURI("http://www.bigdata.com/Mike");
+ bryan = vf.createURI("http://www.bigdata.com/Bryan");
+ martyn = vf.createURI("http://www.bigdata.com/Martyn");
+ dc = vf.createURI("http://www.bigdata.com/DC");
+
+ g.add(vf.createStatement(mike, rdfType, foafPerson));
+ g.add(vf.createStatement(bryan, rdfType, foafPerson));
+ g.add(vf.createStatement(martyn, rdfType, foafPerson));
+
+ g.add(vf.createStatement(mike, rdfsLabel, vf.createLiteral("Mike")));
+ g.add(vf.createStatement(bryan, rdfsLabel, vf.createLiteral("Bryan")));
+ g.add(vf.createStatement(dc, rdfsLabel, vf.createLiteral("DC")));
+
+ g.add(vf.createStatement(mike, foafKnows, bryan));
+ g.add(vf.createStatement(bryan, foafKnows, mike));
+ g.add(vf.createStatement(bryan, foafKnows, martyn));
+ g.add(vf.createStatement(martyn, foafKnows, bryan));
+
+ }
+
+ public URI getRdfType() {
+ return rdfType;
+ }
+
+ public URI getFoafKnows() {
+ return foafKnows;
+ }
+
+ public URI getFoafPerson() {
+ return foafPerson;
+ }
+
+ public URI getMike() {
+ return mike;
+ }
+
+ public URI getBryan() {
+ return bryan;
+ }
+
+ public URI getMartyn() {
+ return martyn;
+ }
+
+ }
+
+ /**
+ * Load and setup the {@link SmallGraphProblem}.
+ */
+ protected SmallGraphProblem setupSmallGraphProblem() throws Exception {
+
+ return new SmallGraphProblem();
+
+ }
+
+}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestAll.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestAll.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestAll.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,64 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+package com.bigdata.rdf.graph.impl.ram;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Aggregates test suites into increasing dependency order.
+ *
+ * @author <a href="mailto:tho...@us...">Bryan Thompson</a>
+ * @version $Id: TestAll.java 6116 2012-03-13 20:39:17Z thompsonbry $
+ */
+public class TestAll extends TestCase {
+
+ /**
+ *
+ */
+ public TestAll() {
+ }
+
+ /**
+ * @param arg0
+ */
+ public TestAll(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * Returns a test that will run each of the implementation specific test
+ * suites in turn.
+ */
+ public static Test suite()
+ {
+
+ final TestSuite suite = new TestSuite("SAIL Graph Engine");
+
+ /*
+ * Only core functionality tests for the SAIL backend belong here. The
+ * analytic test suites are written to the SAIL backend so there is good
+ * coverage there.
+ */
+
+ suite.addTestSuite(TestGather.class);
+
+ return suite;
+
+ }
+
+}
Added: branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestGather.java
===================================================================
--- branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestGather.java (rev 0)
+++ branches/BIGDATA_RELEASE_1_3_0/bigdata-gas/src/test/com/bigdata/rdf/graph/impl/ram/TestGather.java 2013-09-12 21:00:56 UTC (rev 7402)
@@ -0,0 +1,311 @@
+/**
+ Copyright (C) SYSTAP, LLC 2006-2012. All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permission...
[truncated message content] |