|
From: <tho...@us...> - 2014-02-20 00:07:59
|
Revision: 7854
http://sourceforge.net/p/bigdata/code/7854
Author: thompsonbry
Date: 2014-02-20 00:07:56 +0000 (Thu, 20 Feb 2014)
Log Message:
-----------
Exposed the ValueFactory to the GraphLoader abstract to support RDR, which needs to be able to create statements about statements using a bigdata custom value factory.
Added a weighted SSSP test case. This test fails. It will pass once I modify the test and the Bigdata GAS Engine implementation to support the RDR access paths.
@See #526 (RDR)
Modified Paths:
--------------
branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java
branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java
branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java
branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java
branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASRunner.java
branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGraphFixture.java
branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/AbstractBigdataGraphTestCase.java
branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestSSSP.java
Added Paths:
-----------
branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallWeightedGraph.ttl
branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/weightedSmallGraph.png
Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java
===================================================================
--- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGASEngine.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -36,8 +36,6 @@
import com.bigdata.rdf.graph.IGraphAccessor;
import com.bigdata.rdf.graph.impl.GASEngine;
import com.bigdata.rdf.graph.impl.util.VertexDistribution;
-import com.bigdata.rdf.internal.IV;
-import com.bigdata.rdf.store.AbstractTripleStore;
import cutthecrap.utils.striterators.EmptyIterator;
import cutthecrap.utils.striterators.IStriterator;
Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java
===================================================================
--- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/impl/ram/RAMGraphLoader.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -17,6 +17,7 @@
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
+import org.openrdf.model.ValueFactory;
import org.openrdf.rio.RDFHandlerException;
import com.bigdata.rdf.graph.impl.ram.RAMGASEngine.RAMGraph;
@@ -61,5 +62,10 @@
}
}
+
+ @Override
+ protected ValueFactory getValueFactory() {
+ return g.getValueFactory();
+ }
}
Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java
===================================================================
--- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/GraphLoader.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -31,6 +31,7 @@
import org.apache.log4j.Logger;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
+import org.openrdf.model.ValueFactory;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;
@@ -95,6 +96,12 @@
}
/**
+ * Return the {@link ValueFactory} that will be set on the {@link RDFParser}
+ * . This is necessary for the RDR parser.
+ */
+ abstract protected ValueFactory getValueFactory();
+
+ /**
* 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
@@ -280,6 +287,14 @@
rdfParser.setStopAtFirstError(false);
+ final ValueFactory vf = getValueFactory();
+
+ if (vf != null) {
+
+ rdfParser.setValueFactory(vf);
+
+ }
+
final AddStatementHandler h = newStatementHandler();
rdfParser.setRDFHandler(h);
@@ -332,6 +347,7 @@
this.defaultContext = new Resource[0];
}
+ @Override
public void handleStatement(final Statement stmt)
throws RDFHandlerException {
Modified: branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java
===================================================================
--- branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-gas/src/java/com/bigdata/rdf/graph/util/SailGraphLoader.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -17,6 +17,7 @@
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
+import org.openrdf.model.ValueFactory;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.sail.SailConnection;
import org.openrdf.sail.SailException;
@@ -75,4 +76,11 @@
}
+ @Override
+ protected ValueFactory getValueFactory() {
+
+ return null;
+
+ }
+
}
Added: branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallWeightedGraph.ttl
===================================================================
--- branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallWeightedGraph.ttl (rev 0)
+++ branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallWeightedGraph.ttl 2014-02-20 00:07:56 UTC (rev 7854)
@@ -0,0 +1,24 @@
+# A graph using the RDR syntax to express link weights.
+#
+@prefix bd: <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/> .
+
+ bd:1 foaf:knows bd:2 .
+<<bd:1 foaf:knows bd:2 >> bd:weight "100"^^xsd:int .
+
+ bd:1 foaf:knows bd:3 .
+<<bd:1 foaf:knows bd:3 >> bd:weight "100"^^xsd:int .
+
+ bd:2 foaf:knows bd:4 .
+<<bd:2 foaf:knows bd:4 >> bd:weight "50"^^xsd:int .
+
+ bd:3 foaf:knows bd:4 .
+<<bd:3 foaf:knows bd:4 >> bd:weight "100"^^xsd:int .
+
+ bd:3 foaf:knows bd:5 .
+<<bd:3 foaf:knows bd:5 >> bd:weight "100"^^xsd:int .
+
+ bd:4 foaf:knows bd:5 .
+<<bd:4 foaf:knows bd:5 >> bd:weight "25"^^xsd:int .
Added: branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/weightedSmallGraph.png
===================================================================
(Binary files differ)
Index: branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/weightedSmallGraph.png
===================================================================
--- branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/weightedSmallGraph.png 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/weightedSmallGraph.png 2014-02-20 00:07:56 UTC (rev 7854)
Property changes on: branches/RDR/bigdata-gas/src/test/com/bigdata/rdf/graph/data/weightedSmallGraph.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASRunner.java
===================================================================
--- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASRunner.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGASRunner.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -21,9 +21,9 @@
import com.bigdata.rdf.graph.IGASProgram;
import com.bigdata.rdf.graph.IGraphAccessor;
import com.bigdata.rdf.graph.impl.bd.BigdataGASEngine.BigdataGraphAccessor;
+import com.bigdata.rdf.graph.impl.bd.BigdataGraphFixture.BigdataSailGraphLoader;
import com.bigdata.rdf.graph.impl.util.GASRunnerBase;
import com.bigdata.rdf.graph.util.GraphLoader;
-import com.bigdata.rdf.graph.util.SailGraphLoader;
import com.bigdata.rdf.sail.BigdataSail;
import com.bigdata.rdf.store.AbstractTripleStore;
@@ -517,7 +517,7 @@
boolean ok = false;
final SailConnection cxn = sail.getUnisolatedConnection();
try {
- final GraphLoader loader = new SailGraphLoader(cxn);
+ final GraphLoader loader = new BigdataSailGraphLoader(cxn);
for (String f : loadSet) {
loader.loadGraph(null/* fallback */, f/* resource */);
}
Modified: branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGraphFixture.java
===================================================================
--- branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGraphFixture.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-rdf/src/java/com/bigdata/rdf/graph/impl/bd/BigdataGraphFixture.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -2,13 +2,16 @@
import java.util.Properties;
+import org.openrdf.model.ValueFactory;
import org.openrdf.sail.SailConnection;
import org.openrdf.sail.SailException;
import com.bigdata.rdf.graph.IGraphAccessor;
import com.bigdata.rdf.graph.impl.bd.BigdataGASEngine.BigdataGraphAccessor;
import com.bigdata.rdf.graph.util.AbstractGraphFixture;
+import com.bigdata.rdf.graph.util.SailGraphLoader;
import com.bigdata.rdf.sail.BigdataSail;
+import com.bigdata.rdf.sail.BigdataSail.BigdataSailConnection;
import com.bigdata.rdf.store.AbstractTripleStore;
public class BigdataGraphFixture extends AbstractGraphFixture {
@@ -58,6 +61,13 @@
}
@Override
+ protected SailGraphLoader newSailGraphLoader(SailConnection cxn) {
+
+ return new BigdataSailGraphLoader(cxn);
+
+ }
+
+ @Override
public BigdataGASEngine newGASEngine(final int nthreads) {
return new BigdataGASEngine(sail, nthreads);
@@ -71,5 +81,28 @@
.getIndexManager());
}
+
+ public static class BigdataSailGraphLoader extends SailGraphLoader {
+ private final ValueFactory valueFactory;
+
+ public BigdataSailGraphLoader(SailConnection cxn) {
+
+ super(cxn);
+
+ // Note: Needed for RDR.
+ this.valueFactory = ((BigdataSailConnection) cxn).getBigdataSail()
+ .getValueFactory();
+
+ }
+
+ @Override
+ protected ValueFactory getValueFactory() {
+
+ return valueFactory;
+
+ }
+
+ }
+
}
\ No newline at end of file
Modified: branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/AbstractBigdataGraphTestCase.java
===================================================================
--- branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/AbstractBigdataGraphTestCase.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/AbstractBigdataGraphTestCase.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -66,7 +66,7 @@
}
- private Properties getProperties() {
+ protected Properties getProperties() {
final Properties p = new Properties();
@@ -190,4 +190,93 @@
}
+ /**
+ * A small weighted graph data set.
+ *
+ * @see {@value #smallWeightedGraph}
+ *
+ * @author <a href="mailto:tho...@us...">Bryan Thompson</a>
+ */
+ protected class SmallWeightedGraphProblem {
+
+ /**
+ * The data file.
+ */
+ static private final String smallWeightedGraph = "bigdata-gas/src/test/com/bigdata/rdf/graph/data/smallWeightedGraph.ttl";
+
+ private final BigdataURI foafKnows, v1, v2, v3, v4, v5;
+
+ public SmallWeightedGraphProblem() throws Exception {
+
+ getGraphFixture().loadGraph(smallWeightedGraph);
+
+ final BigdataSail sail = getGraphFixture().getSail();
+
+ final ValueFactory vf = sail.getValueFactory();
+
+ foafKnows = (BigdataURI) vf
+ .createURI("http://xmlns.com/foaf/0.1/knows");
+
+ v1 = (BigdataURI) vf.createURI("http://www.bigdata.com/1");
+ v2 = (BigdataURI) vf.createURI("http://www.bigdata.com/2");
+ v3 = (BigdataURI) vf.createURI("http://www.bigdata.com/3");
+ v4 = (BigdataURI) vf.createURI("http://www.bigdata.com/4");
+ v5 = (BigdataURI) vf.createURI("http://www.bigdata.com/5");
+
+ final BigdataValue[] terms = new BigdataValue[] { foafKnows, v1,
+ v2, v3, v4, v5 };
+
+ // batch resolve existing IVs.
+ ((BigdataSail) sail).getDatabase().getLexiconRelation()
+ .addTerms(terms, terms.length, true/* readOnly */);
+
+ for (BigdataValue v : terms) {
+ if (v.getIV() == null)
+ fail("Did not resolve: " + v);
+ }
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ public IV getFoafKnows() {
+ return foafKnows.getIV();
+ }
+
+ @SuppressWarnings("rawtypes")
+ public IV getV1() {
+ return v1.getIV();
+ }
+
+ @SuppressWarnings("rawtypes")
+ public IV getV2() {
+ return v2.getIV();
+ }
+
+ @SuppressWarnings("rawtypes")
+ public IV getV3() {
+ return v3.getIV();
+ }
+
+ @SuppressWarnings("rawtypes")
+ public IV getV4() {
+ return v4.getIV();
+ }
+
+ @SuppressWarnings("rawtypes")
+ public IV getV5() {
+ return v5.getIV();
+ }
+
+
+ }
+
+ /**
+ * Load and setup the {@link SmallWeightedGraphProblem}.
+ */
+ protected SmallWeightedGraphProblem setupSmallWeightedGraphProblem() throws Exception {
+
+ return new SmallWeightedGraphProblem();
+
+ }
+
}
Modified: branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestSSSP.java
===================================================================
--- branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestSSSP.java 2014-02-20 00:04:21 UTC (rev 7853)
+++ branches/RDR/bigdata-rdf/src/test/com/bigdata/rdf/graph/impl/bd/TestSSSP.java 2014-02-20 00:07:56 UTC (rev 7854)
@@ -82,5 +82,49 @@
}
}
+
+ /**
+ * A unit test based on graph with link weights.
+ */
+ public void test_sssp_weightedGraph() throws Exception {
+
+ final SmallWeightedGraphProblem p = setupSmallWeightedGraphProblem();
+ final IGASEngine gasEngine = getGraphFixture()
+ .newGASEngine(1/* nthreads */);
+
+ try {
+
+ final IGraphAccessor graphAccessor = getGraphFixture()
+ .newGraphAccessor(null/* ignored */);
+
+ final IGASContext<SSSP.VS, SSSP.ES, Integer> gasContext = gasEngine
+ .newGASContext(graphAccessor, new SSSP());
+
+ final IGASState<SSSP.VS, SSSP.ES, Integer> gasState = gasContext.getGASState();
+
+ // Initialize the froniter.
+ gasState.setFrontier(gasContext, p.getV1());
+
+ // Converge.
+ gasContext.call();
+
+ assertEquals(0, gasState.getState(p.getV1()).dist());
+
+ assertEquals(100, gasState.getState(p.getV2()).dist());
+
+ assertEquals(100, gasState.getState(p.getV3()).dist());
+
+ assertEquals(125, gasState.getState(p.getV4()).dist());
+
+ assertEquals(125, gasState.getState(p.getV5()).dist());
+
+ } finally {
+
+ gasEngine.shutdownNow();
+
+ }
+
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|