From: <mrp...@us...> - 2014-04-03 21:33:00
|
Revision: 8038 http://sourceforge.net/p/bigdata/code/8038 Author: mrpersonick Date: 2014-04-03 21:32:58 +0000 (Thu, 03 Apr 2014) Log Message: ----------- added an analytic to produce a connected subgraph between a source and one or more targets Added Paths: ----------- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.rq branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.ttl branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.ttl branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.rq branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.ttl branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.rq branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.ttl Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,220 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Sep 16, 2009 + */ + +package com.bigdata.rdf.sail.graph; + +import java.io.InputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.apache.commons.io.IOUtils; +import org.apache.log4j.Logger; +import org.openrdf.model.URI; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.rio.RDFFormat; + +import com.bigdata.rdf.axioms.NoAxioms; +import com.bigdata.rdf.sail.BigdataSail; +import com.bigdata.rdf.sail.BigdataSailRepository; +import com.bigdata.rdf.sail.BigdataSailRepositoryConnection; +import com.bigdata.rdf.sail.ProxyBigdataSailTestCase; +import com.bigdata.rdf.vocab.BaseVocabulary; +import com.bigdata.rdf.vocab.NoVocabulary; +import com.bigdata.rdf.vocab.RDFSVocabulary; +import com.bigdata.rdf.vocab.VocabularyDecl; + +public class TestPaths extends ProxyBigdataSailTestCase { + + protected static final Logger log = Logger.getLogger(TestPaths.class); + + protected static final boolean INFO = log.isInfoEnabled(); + + @Override + public Properties getProperties() { + + Properties props = super.getProperties(); + + props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); + props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName()); + props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false"); + props.setProperty(BigdataSail.Options.JUSTIFY, "false"); + props.setProperty(BigdataSail.Options.TEXT_INDEX, "false"); + + return props; + + } + + /** + * + */ + public TestPaths() { + } + + /** + * @param arg0 + */ + public TestPaths(String arg0) { + super(arg0); + } + + protected void load(final BigdataSailRepositoryConnection cxn, final String resource) throws Exception { + + final InputStream is = getClass().getResourceAsStream(resource); + + cxn.add(is, "", RDFFormat.TURTLE); + + } + + protected InputStream open(final String resource) throws Exception { + + return getClass().getResourceAsStream(resource); + + } + +// public void testSimpleBFS() throws Exception { +// +// final BigdataSail sail = getSail(); +// sail.initialize(); +// final BigdataSailRepository repo = new BigdataSailRepository(sail); +// +// final BigdataSailRepositoryConnection cxn = repo.getConnection(); +// cxn.setAutoCommit(false); +// +// try { +// +// cxn.add(open("paths1.ttl"), "", RDFFormat.TURTLE); +// cxn.commit(); +// +// log.trace("\n"+sail.getDatabase().dumpStore()); +// +// final String query = IOUtils.toString(open("paths1.rq")); +// +// log.trace("\n"+query); +// +// final TupleQuery tqr = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); +// +// final TupleQueryResult result = tqr.evaluate(); +// +// while (result.hasNext()) { +// +// log.trace(result.next()); +// +// } +// +// result.close(); +// +// } finally { +// cxn.close(); +// sail.__tearDownUnitTest(); +// } +// +// } +// +// public void testSimpleSSSP() throws Exception { +// +// final BigdataSail sail = getSail(); +// sail.initialize(); +// final BigdataSailRepository repo = new BigdataSailRepository(sail); +// +// final BigdataSailRepositoryConnection cxn = repo.getConnection(); +// cxn.setAutoCommit(false); +// +// try { +// +// cxn.add(open("paths2.ttl"), "", RDFFormat.TURTLE); +// cxn.commit(); +// +// log.trace("\n"+sail.getDatabase().dumpStore()); +// +// final String query = IOUtils.toString(open("paths2.rq")); +// +// log.trace("\n"+query); +// +// final TupleQuery tqr = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); +// +// final TupleQueryResult result = tqr.evaluate(); +// +// while (result.hasNext()) { +// +// log.trace(result.next()); +// +// } +// +// result.close(); +// +// } finally { +// cxn.close(); +// sail.__tearDownUnitTest(); +// } +// +// } + + public void testPaths() throws Exception { + + final BigdataSail sail = getSail(); + sail.initialize(); + final BigdataSailRepository repo = new BigdataSailRepository(sail); + + final BigdataSailRepositoryConnection cxn = repo.getConnection(); + cxn.setAutoCommit(false); + + try { + + cxn.add(open("paths4.ttl"), "", RDFFormat.TURTLE); + cxn.commit(); + + log.trace("\n"+sail.getDatabase().dumpStore()); + + final String query = IOUtils.toString(open("paths4.rq")); + + log.trace("\n"+query); + + final TupleQuery tqr = cxn.prepareTupleQuery(QueryLanguage.SPARQL, query); + + final TupleQueryResult result = tqr.evaluate(); + + while (result.hasNext()) { + + log.trace(result.next()); + + } + + result.close(); + + } finally { + cxn.close(); + sail.__tearDownUnitTest(); + } + + } + +} Property changes on: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/TestPaths.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.rq =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.rq (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.rq 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,11 @@ +PREFIX gas: <http://www.bigdata.com/rdf/gas#> +SELECT * { + SERVICE gas:service { + gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.BFS" . + gas:program gas:in </:source> . # starting point + gas:program gas:target </:target> . # target vertices + gas:program gas:out ?v . # bound to the visited vertices. + gas:program gas:out1 ?depth . # bound to the depth of the visited vertices. + gas:program gas:out2 ?pred . # bound to the predecessor. + } +} order by ?depth \ No newline at end of file Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.ttl =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.ttl (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths1.ttl 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,13 @@ +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix bd: <http://www.bigdata.com/rdf#> . +@prefix : <:> . + +# first path +:source :edge :a . +:a :edge :b . +:b :edge :target . + +# second path +:source :edge :c . +:c :edge :d . +:d :edge :target . Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.rq 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,11 @@ +PREFIX gas: <http://www.bigdata.com/rdf/gas#> +SELECT * { + SERVICE gas:service { + gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" . + gas:program gas:in </:source> . # starting point + gas:program gas:target </:target> . # target vertices + gas:program gas:out ?s . # bound to the visited vertices. + gas:program gas:out1 ?distance . # bound to the distance of the visited vertices. + gas:program gas:out2 ?pred . # bound to the predecessor + } +} order by ?distance \ No newline at end of file Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.ttl =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.ttl (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths2.ttl 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,22 @@ +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix bd: <http://www.bigdata.com/rdf#> . +@prefix : <:> . + +# first path, length = 2 +:source :edge :a . +:a :edge :b . +:b :edge :target . + +# second path, length = 2 +:source :edge :c . +:c :edge :d . +:d :edge :target . + +# third path, length = 3 +:source :edge :e . +:e :edge :f . +:f :edge :g . +:g :edge :target . + +# extraneous +:target :edge :extraneous . Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.rq =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.rq (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.rq 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,16 @@ +PREFIX gas: <http://www.bigdata.com/rdf/gas#> +SELECT * { + SERVICE gas:service { + gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.PATHS" . + gas:program gas:in </:target> . # starting point + gas:program gas:target </:source> . # target vertices + gas:program gas:traversalDirection "Reverse" . + gas:program gas:maxIterationsAfterTargets 2 . + # set this to something that reasonably constrains the runtime + gas:program gas:maxVisited 100000 . + gas:program gas:out ?s . # bound to the visited vertices. + gas:program gas:out1 ?depth . # bound to the depth + } + #?s </:edge> ?o . + #filter(!sameTerm(?s,</:target>)) . +} order by ?depth \ No newline at end of file Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.ttl =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.ttl (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths3.ttl 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,33 @@ +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix bd: <http://www.bigdata.com/rdf#> . +@prefix : <:> . + +# first path, length = 2 +:source :edge :a . +:a :edge :b . +:b :edge :target . + +# second path, length = 2 +:source :edge :c . +:c :edge :d . +:d :edge :target . + +# third path, length = 3 +:source :edge :e . +:e :edge :f . +:f :edge :g . +:g :edge :target . + +# third path, length = 4 +:source :edge :h . +:h :edge :i . +:i :edge :j . +:j :edge :k . +:k :edge :target . + +# extraneous +:target :edge :extraneous . + +# cycle +:b :edge :cycle . +:cycle :edge :a . Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.rq =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.rq (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.rq 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,18 @@ +PREFIX gas: <http://www.bigdata.com/rdf/gas#> +SELECT * { + SERVICE gas:service { + gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.PATHS" . + gas:program gas:in </:target> . # starting point + gas:program gas:target </:source1> . # target vertices + gas:program gas:target </:source2> . # target vertices + gas:program gas:traversalDirection "Reverse" . + # gas:program gas:maxIterations 2 . + gas:program gas:maxIterationsAfterTargets 0 . + # set this to something that reasonably constrains the runtime + gas:program gas:maxVisited 100000 . + gas:program gas:out ?s . # bound to the visited vertices. + gas:program gas:out1 ?depth . # bound to the depth + } + ?s </:edge> ?o . + filter(?s != </:target>) . +} order by ?depth \ No newline at end of file Added: branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.ttl =================================================================== --- branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.ttl (rev 0) +++ branches/RDR/bigdata-sails/src/test/com/bigdata/rdf/sail/graph/paths4.ttl 2014-04-03 21:32:58 UTC (rev 8038) @@ -0,0 +1,36 @@ +@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . +@prefix bd: <http://www.bigdata.com/rdf#> . +@prefix : <:> . + +# first path from source1, length = 2 +:source1 :edge :b . +:b :edge :a . +:a :edge :target . + +# second path from source1, length = 3 +:source1 :edge :e . +:e :edge :d . +:d :edge :c . +:c :edge :target . + +# first path from source2, length = 3 +:source2 :edge :h . +:h :edge :g . +:g :edge :f . +:f :edge :target . + +# second path from source2, length = 4 +:source2 :edge :l . +:l :edge :k . +:k :edge :j . +:j :edge :i . +:i :edge :target . + +# only path from source3, length = 5 +:source3 :edge :z . +:z :edge :y . +:y :edge :x . +:x :edge :w . +:w :edge :v . +:v :edge :target . + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |