You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rya.apache.org by mi...@apache.org on 2016/03/14 20:15:37 UTC
[2/3] incubator-rya git commit: RYA-34 fixing inference with mongo db
RYA-34 fixing inference with mongo db
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/efcae829
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/efcae829
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/efcae829
Branch: refs/heads/develop
Commit: efcae829c97e78b122b0d27586dd2a74e00005c3
Parents: c4d44eb
Author: pujav65 <pu...@gmail.com>
Authored: Mon Feb 29 15:15:52 2016 -0500
Committer: Aaron Mihalik <mi...@alum.mit.edu>
Committed: Mon Mar 14 14:40:47 2016 -0400
----------------------------------------------------------------------
.../mvm/rya/sail/config/RyaSailFactory.java | 39 +-
.../external/AccumuloIndexSetTest2.java | 804 +++++++++++++++++++
.../PrecompJoinOptimizerIntegrationTest.java | 484 +++++++++++
.../src/main/java/MongoRyaDirectExample.java | 40 +-
.../inference/InferenceEngine.java | 1 +
5 files changed, 1350 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/efcae829/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java b/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
index f4f770a..bc11a79 100644
--- a/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
+++ b/extras/indexing/src/main/java/mvm/rya/sail/config/RyaSailFactory.java
@@ -1,5 +1,11 @@
package mvm.rya.sail.config;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.hadoop.conf.Configuration;
+import org.openrdf.sail.Sail;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -23,49 +29,48 @@ package mvm.rya.sail.config;
import mvm.rya.accumulo.AccumuloRdfConfiguration;
import mvm.rya.accumulo.AccumuloRyaDAO;
import mvm.rya.api.RdfCloudTripleStoreConfiguration;
+import mvm.rya.api.persist.RyaDAO;
import mvm.rya.api.persist.RyaDAOException;
import mvm.rya.indexing.accumulo.ConfigUtils;
import mvm.rya.mongodb.MongoDBRdfConfiguration;
import mvm.rya.mongodb.MongoDBRyaDAO;
import mvm.rya.rdftriplestore.RdfCloudTripleStore;
-
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.Connector;
-import org.apache.hadoop.conf.Configuration;
-import org.openrdf.sail.Sail;
+import mvm.rya.rdftriplestore.inference.InferenceEngine;
+import mvm.rya.rdftriplestore.inference.InferenceEngineException;
public class RyaSailFactory {
public static Sail getInstance(Configuration conf) throws AccumuloException,
- AccumuloSecurityException, RyaDAOException {
+ AccumuloSecurityException, RyaDAOException, InferenceEngineException {
return getRyaSail(conf);
}
- private static Sail getRyaSail(Configuration config) throws AccumuloException, AccumuloSecurityException, RyaDAOException {
+ private static Sail getRyaSail(Configuration config) throws AccumuloException, AccumuloSecurityException, RyaDAOException, InferenceEngineException {
RdfCloudTripleStore store = new RdfCloudTripleStore();
+ RyaDAO crdfdao = null;
+ RdfCloudTripleStoreConfiguration conf;
if (ConfigUtils.getUseMongo(config)) {
- MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration(config);
+ conf = new MongoDBRdfConfiguration(config);
conf.setTablePrefix(config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX));
ConfigUtils.setIndexers(conf);
- MongoDBRyaDAO crdfdao = new MongoDBRyaDAO(conf);
+ crdfdao = new MongoDBRyaDAO((MongoDBRdfConfiguration)conf);
crdfdao.init();
conf.setDisplayQueryPlan(true);
store.setRyaDAO(crdfdao);
} else {
Connector connector = ConfigUtils.getConnector(config);
- AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
- crdfdao.setConnector(connector);
+ crdfdao = new AccumuloRyaDAO();
+ ((AccumuloRyaDAO)crdfdao).setConnector(connector);
- AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(config);
+ conf = new AccumuloRdfConfiguration(config);
conf.setTablePrefix(config.get(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX)); // sets
// TablePrefixLayoutStrategy
ConfigUtils.setIndexers(conf);
@@ -75,6 +80,14 @@ public class RyaSailFactory {
crdfdao.init();
store.setRyaDAO(crdfdao);
}
+
+ if (conf.isInfer()){
+ InferenceEngine inferenceEngine = new InferenceEngine();
+ inferenceEngine.setConf(conf);
+ inferenceEngine.setRyaDAO(crdfdao);
+ inferenceEngine.init();
+ store.setInferenceEngine(inferenceEngine);
+ }
return store;
}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/efcae829/extras/indexing/src/test/java/mvm/rya/indexing/external/AccumuloIndexSetTest2.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/external/AccumuloIndexSetTest2.java b/extras/indexing/src/test/java/mvm/rya/indexing/external/AccumuloIndexSetTest2.java
new file mode 100644
index 0000000..54beecd
--- /dev/null
+++ b/extras/indexing/src/test/java/mvm/rya/indexing/external/AccumuloIndexSetTest2.java
@@ -0,0 +1,804 @@
+package mvm.rya.indexing.external;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Assert;
+import mvm.rya.accumulo.AccumuloRdfConfiguration;
+import mvm.rya.api.persist.RyaDAOException;
+import mvm.rya.indexing.RyaSailFactory;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.external.tupleSet.AccumuloIndexSet;
+import mvm.rya.rdftriplestore.inference.InferenceEngineException;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.mock.MockInstance;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.model.impl.LiteralImpl;
+import org.openrdf.model.impl.URIImpl;
+import org.openrdf.model.vocabulary.RDF;
+import org.openrdf.model.vocabulary.RDFS;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.MalformedQueryException;
+import org.openrdf.query.QueryEvaluationException;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.QueryResultHandlerException;
+import org.openrdf.query.TupleQueryResultHandler;
+import org.openrdf.query.TupleQueryResultHandlerException;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.repository.sail.SailRepositoryConnection;
+import org.openrdf.sail.Sail;
+import org.openrdf.sail.SailException;
+
+public class AccumuloIndexSetTest2 {
+
+ private SailRepositoryConnection conn;
+ private SailRepository repo;
+ private Connector accCon;
+ String tablePrefix = "table_";
+ AccumuloRdfConfiguration conf;
+ URI sub, sub2, obj, obj2, subclass, subclass2, talksTo;
+
+ @Before
+ public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException,
+ MalformedQueryException, AccumuloException, AccumuloSecurityException, TableExistsException,
+ RyaDAOException, InferenceEngineException {
+
+ conf = new AccumuloRdfConfiguration();
+ conf.set(ConfigUtils.USE_PCJ, "true");
+ conf.set(ConfigUtils.USE_MOCK_INSTANCE, "true");
+ conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "instance");
+ conf.setTablePrefix(tablePrefix);
+ conf.setPcjTables(Arrays.asList("table1", "table2"));
+
+ Sail sail = RyaSailFactory.getInstance(conf);
+ repo = new SailRepository(sail);
+ repo.initialize();
+ conn = repo.getConnection();
+
+ sub = new URIImpl("uri:entity");
+ subclass = new URIImpl("uri:class");
+ obj = new URIImpl("uri:obj");
+ talksTo = new URIImpl("uri:talksTo");
+
+ conn.add(sub, RDF.TYPE, subclass);
+ conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(sub, talksTo, obj);
+
+ sub2 = new URIImpl("uri:entity2");
+ subclass2 = new URIImpl("uri:class2");
+ obj2 = new URIImpl("uri:obj2");
+
+ conn.add(sub2, RDF.TYPE, subclass2);
+ conn.add(sub2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(sub2, talksTo, obj2);
+
+ accCon = new MockInstance("instance").getConnector("root", new PasswordToken("".getBytes()));
+ accCon.tableOperations().create("table1");
+ accCon.tableOperations().create("table2");
+
+ }
+
+ @After
+ public void close() throws RepositoryException, AccumuloException, AccumuloSecurityException,
+ TableNotFoundException {
+
+ conf = null;
+ conn.close();
+ accCon.tableOperations().delete(tablePrefix + "spo");
+ accCon.tableOperations().delete(tablePrefix + "po");
+ accCon.tableOperations().delete(tablePrefix + "osp");
+
+ if (accCon.tableOperations().exists("table1")) {
+ accCon.tableOperations().delete("table1");
+ }
+
+ if (accCon.tableOperations().exists("table2")) {
+ accCon.tableOperations().delete("table2");
+ }
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder2() throws RepositoryException, MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException,
+ TupleQueryResultHandlerException {
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?o ?l " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarInvalidOrder() throws RepositoryException, MalformedQueryException,
+ SailException, QueryEvaluationException, MutationsRejectedException, TableNotFoundException,
+ TupleQueryResultHandlerException {
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?e ?c ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?o ?l " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder1() throws MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException, RepositoryException,
+ TupleQueryResultHandlerException {
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?c ?l ?f ?o" //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ // @Test
+ public void testEvaluateTwoIndexThreeVarsDiffLabel() throws RepositoryException, MalformedQueryException,
+ SailException, QueryEvaluationException, MutationsRejectedException, TableNotFoundException,
+ TupleQueryResultHandlerException {
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ // TODO Auto-generated method stub
+ String indexSparqlString = ""//
+ + "SELECT ?dog ?pig ?owl " //
+ + "{" //
+ + " ?pig a ?dog . "//
+ + " ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?owl "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?c ?l ?f ?o" //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder2() throws RepositoryException, MalformedQueryException,
+ SailException, QueryEvaluationException, MutationsRejectedException, TableNotFoundException,
+ TupleQueryResultHandlerException {
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ // TODO Auto-generated method stub
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?o ?f ?e ?c ?l " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder3ThreeBindingSet() throws TupleQueryResultHandlerException,
+ QueryEvaluationException, MalformedQueryException, RepositoryException, SailException,
+ MutationsRejectedException, TableNotFoundException {
+
+ URI sub3 = new URIImpl("uri:entity3");
+ URI subclass3 = new URIImpl("uri:class3");
+ URI obj3 = new URIImpl("uri:obj3");
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+ URI superclass3 = new URIImpl("uri:superclass3");
+
+ conn.add(sub3, RDF.TYPE, subclass3);
+ conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
+ conn.add(sub3, talksTo, obj3);
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(subclass3, RDF.TYPE, superclass3);
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?o ?f ?l ?e ?c " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(3, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder5ThreeBindingSet() throws MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException, RepositoryException,
+ TupleQueryResultHandlerException {
+
+ URI sub3 = new URIImpl("uri:entity3");
+ URI subclass3 = new URIImpl("uri:class3");
+ URI obj3 = new URIImpl("uri:obj3");
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+ URI superclass3 = new URIImpl("uri:superclass3");
+
+ conn.add(sub3, RDF.TYPE, subclass3);
+ conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
+ conn.add(sub3, talksTo, obj3);
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(subclass3, RDF.TYPE, superclass3);
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ // TODO Auto-generated method stub
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?o ?f ?e ?l ?c " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(3, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder4ThreeBindingSet() throws MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException, RepositoryException,
+ TupleQueryResultHandlerException {
+
+ URI sub3 = new URIImpl("uri:entity3");
+ URI subclass3 = new URIImpl("uri:class3");
+ URI obj3 = new URIImpl("uri:obj3");
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+ URI superclass3 = new URIImpl("uri:superclass3");
+
+ conn.add(sub3, RDF.TYPE, subclass3);
+ conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
+ conn.add(sub3, talksTo, obj3);
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(subclass3, RDF.TYPE, superclass3);
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ // TODO Auto-generated method stub
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?o ?f ?c ?e ?l " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(3, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder6ThreeBindingSet() throws MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException, RepositoryException,
+ TupleQueryResultHandlerException {
+
+ URI sub3 = new URIImpl("uri:entity3");
+ URI subclass3 = new URIImpl("uri:class3");
+ URI obj3 = new URIImpl("uri:obj3");
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+ URI superclass3 = new URIImpl("uri:superclass3");
+
+ conn.add(sub3, RDF.TYPE, subclass3);
+ conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
+ conn.add(sub3, talksTo, obj3);
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(subclass3, RDF.TYPE, superclass3);
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?c ?l ?e ?o ?f " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(3, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder7ThreeBindingSet() throws MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException, RepositoryException,
+ TupleQueryResultHandlerException {
+
+ URI sub3 = new URIImpl("uri:entity3");
+ URI subclass3 = new URIImpl("uri:class3");
+ URI obj3 = new URIImpl("uri:obj3");
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+ URI superclass3 = new URIImpl("uri:superclass3");
+
+ conn.add(sub3, RDF.TYPE, subclass3);
+ conn.add(sub3, RDFS.LABEL, new LiteralImpl("label3"));
+ conn.add(sub3, talksTo, obj3);
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(subclass3, RDF.TYPE, superclass3);
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(obj3, RDFS.LABEL, new LiteralImpl("label3"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?c ?e ?l " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?o ?l ?c ?e ?f " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(3, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateOneIndex() throws RepositoryException, MalformedQueryException, SailException,
+ QueryEvaluationException, MutationsRejectedException, TableNotFoundException,
+ TupleQueryResultHandlerException {
+
+ String indexSparqlString = ""//
+ + "SELECT ?dog ?pig ?duck " //
+ + "{" //
+ + " ?pig a ?dog . "//
+ + " ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck "//
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ @Test
+ public void testEvaluateTwoIndexThreeVarOrder3() throws RepositoryException, MalformedQueryException,
+ SailException, QueryEvaluationException, MutationsRejectedException, TableNotFoundException,
+ TupleQueryResultHandlerException {
+
+ URI superclass = new URIImpl("uri:superclass");
+ URI superclass2 = new URIImpl("uri:superclass2");
+
+ conn.add(subclass, RDF.TYPE, superclass);
+ conn.add(subclass2, RDF.TYPE, superclass2);
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+ String indexSparqlString = ""//
+ + "SELECT ?dog ?pig ?duck " //
+ + "{" //
+ + " ?pig a ?dog . "//
+ + " ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?o ?f ?e ?c ?l " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?f ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. "//
+ + " ?c a ?f . " //
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, "table1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, "table2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+ }
+
+ public static class CountingResultHandler implements TupleQueryResultHandler {
+ private int count = 0;
+
+ public int getCount() {
+ return count;
+ }
+
+ public void resetCount() {
+ this.count = 0;
+ }
+
+ @Override
+ public void startQueryResult(List<String> arg0) throws TupleQueryResultHandlerException {
+ }
+
+ @Override
+ public void handleSolution(BindingSet arg0) throws TupleQueryResultHandlerException {
+ count++;
+ }
+
+ @Override
+ public void endQueryResult() throws TupleQueryResultHandlerException {
+ }
+
+ @Override
+ public void handleBoolean(boolean arg0) throws QueryResultHandlerException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void handleLinks(List<String> arg0) throws QueryResultHandlerException {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/efcae829/extras/indexing/src/test/java/mvm/rya/indexing/external/PrecompJoinOptimizerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/external/PrecompJoinOptimizerIntegrationTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/external/PrecompJoinOptimizerIntegrationTest.java
index 4eaa279..dff310a 100644
--- a/extras/indexing/src/test/java/mvm/rya/indexing/external/PrecompJoinOptimizerIntegrationTest.java
+++ b/extras/indexing/src/test/java/mvm/rya/indexing/external/PrecompJoinOptimizerIntegrationTest.java
@@ -22,8 +22,15 @@ package mvm.rya.indexing.external;
import java.util.List;
import mvm.rya.api.persist.RyaDAOException;
+<<<<<<< HEAD
import mvm.rya.indexing.external.tupleSet.PcjTables.PcjException;
import mvm.rya.indexing.external.tupleSet.PcjTables.PcjVarOrderFactory;
+=======
+import mvm.rya.indexing.RyaSailFactory;
+import mvm.rya.indexing.accumulo.ConfigUtils;
+import mvm.rya.indexing.external.tupleSet.AccumuloIndexSet;
+import mvm.rya.rdftriplestore.inference.InferenceEngineException;
+>>>>>>> RYA-34 fixing inference with mongo db
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
@@ -492,4 +499,481 @@ public class PrecompJoinOptimizerIntegrationTest {
}
}
+=======
+ private SailRepositoryConnection conn;
+ private SailRepository repo;
+ private Connector accCon;
+ String tablePrefix = "table_";
+ AccumuloRdfConfiguration conf;
+ URI sub, sub2, obj,obj2,subclass, subclass2, talksTo;
+
+
+
+
+ @Before
+ public void init() throws RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException, MalformedQueryException,
+ AccumuloException, AccumuloSecurityException, TableExistsException, RyaDAOException, InferenceEngineException {
+
+ conf = new AccumuloRdfConfiguration();
+ conf.set(ConfigUtils.USE_PCJ, "true");
+ conf.set(ConfigUtils.USE_MOCK_INSTANCE,"true");
+ conf.set(ConfigUtils.CLOUDBASE_INSTANCE, "instance");
+ conf.setTablePrefix(tablePrefix);
+
+ Sail sail = RyaSailFactory.getInstance(conf);
+ repo = new SailRepository(sail);
+ repo.initialize();
+ conn = repo.getConnection();
+
+ sub = new URIImpl("uri:entity");
+ subclass = new URIImpl("uri:class");
+ obj = new URIImpl("uri:obj");
+ talksTo = new URIImpl("uri:talksTo");
+
+ conn.add(sub, RDF.TYPE, subclass);
+ conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(sub, talksTo, obj);
+
+ sub2 = new URIImpl("uri:entity2");
+ subclass2 = new URIImpl("uri:class2");
+ obj2 = new URIImpl("uri:obj2");
+
+ conn.add(sub2, RDF.TYPE, subclass2);
+ conn.add(sub2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(sub2, talksTo, obj2);
+
+ accCon = new MockInstance("instance").getConnector("root",new PasswordToken("".getBytes()));
+
+ }
+
+
+ @After
+ public void close() throws RepositoryException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
+
+ conf = null;
+ conn.close();
+ accCon.tableOperations().delete(tablePrefix + "spo");
+ accCon.tableOperations().delete(tablePrefix + "po");
+ accCon.tableOperations().delete(tablePrefix + "osp");
+ }
+
+
+
+ @Test
+ public void testEvaluateSingeIndex() throws TupleQueryResultHandlerException, QueryEvaluationException,
+ MalformedQueryException, RepositoryException, AccumuloException,
+ AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX1")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX1");
+ }
+ accCon.tableOperations().create(tablePrefix + "INDEX1");
+
+ String indexSparqlString = ""//
+ + "SELECT ?e ?l ?c " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ AccumuloIndexSet ais = new AccumuloIndexSet(indexSparqlString, conn, accCon, tablePrefix + "INDEX1");
+
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+ + " ?e <uri:talksTo> ?o . "//
+ + "}";//
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+// Scanner scan = accCon.createScanner(tablePrefix + "spo", new Authorizations("U"));
+//
+// for(Entry<Key,Value> e: scan) {
+// System.out.println(e.getKey().getRow());
+// }
+
+ Assert.assertEquals(2, crh.getCount());
+
+
+ }
+
+
+
+
+
+
+ @Test
+ public void testEvaluateTwoIndexTwoVarOrder1() throws AccumuloException, AccumuloSecurityException,
+ TableExistsException, RepositoryException, MalformedQueryException, SailException, QueryEvaluationException,
+ TableNotFoundException, TupleQueryResultHandlerException, RyaDAOException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX1")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX1");
+ }
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX2")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX2");
+ }
+
+ accCon.tableOperations().create(tablePrefix + "INDEX1");
+ accCon.tableOperations().create(tablePrefix + "INDEX2");
+
+
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+
+
+ String indexSparqlString = ""//
+ + "SELECT ?e ?l ?c " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?o ?l " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?o " //
+ + "{" //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, tablePrefix + "INDEX1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, tablePrefix + "INDEX2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(2, crh.getCount());
+
+
+
+
+ }
+
+
+ @Test
+ public void testEvaluateSingeFilterIndex() throws TupleQueryResultHandlerException, QueryEvaluationException,
+ MalformedQueryException, RepositoryException, AccumuloException,
+ AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX1")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX1");
+ }
+ accCon.tableOperations().create(tablePrefix + "INDEX1");
+
+ String indexSparqlString = ""//
+ + "SELECT ?e ?l ?c " //
+ + "{" //
+ + " Filter(?e = <uri:entity>) " //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ AccumuloIndexSet ais = new AccumuloIndexSet(indexSparqlString, conn, accCon, tablePrefix + "INDEX1");
+
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?l ?o " //
+ + "{" //
+ + " Filter(?e = <uri:entity>) " //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
+ + " ?e <uri:talksTo> ?o . "//
+ + "}";//
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(1, crh.getCount());
+
+
+ }
+
+
+
+
+ @Test
+ public void testEvaluateSingeFilterWithUnion() throws TupleQueryResultHandlerException, QueryEvaluationException,
+ MalformedQueryException, RepositoryException, AccumuloException,
+ AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX2")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX2");
+ }
+ accCon.tableOperations().create(tablePrefix + "INDEX2");
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?l ?c " //
+ + "{" //
+ + " Filter(?l = \"label2\") " //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, tablePrefix + "INDEX2");
+
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?o ?m ?l" //
+ + "{" //
+ + " Filter(?l = \"label2\") " //
+ + " ?e <uri:talksTo> ?o . "//
+ + " { ?e a ?c . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?m }"//
+ + " UNION { ?e a ?c . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l }"//
+ + "}";//
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(1, crh.getCount());
+
+
+ }
+
+
+
+ @Test
+ public void testEvaluateSingeFilterWithLeftJoin() throws TupleQueryResultHandlerException, QueryEvaluationException,
+ MalformedQueryException, RepositoryException, AccumuloException,
+ AccumuloSecurityException, TableExistsException, RyaDAOException, SailException, TableNotFoundException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX1")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX1");
+ }
+ accCon.tableOperations().create(tablePrefix + "INDEX1");
+
+ String indexSparqlString1 = ""//
+ + "SELECT ?e ?l ?c " //
+ + "{" //
+ + " Filter(?l = \"label3\") " //
+ + " ?e a ?c . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+
+ URI sub3 = new URIImpl("uri:entity3");
+ URI subclass3 = new URIImpl("uri:class3");
+ conn.add(sub3, RDF.TYPE, subclass3);
+ conn.add(sub3,RDFS.LABEL, new LiteralImpl("label3"));
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString1, conn, accCon, tablePrefix + "INDEX1");
+
+ String queryString = ""//
+ + "SELECT ?e ?c ?o ?m ?l" //
+ + "{" //
+ + " Filter(?l = \"label3\") " //
+ + " ?e a ?c . " //
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " //
+ + " OPTIONAL { ?e <uri:talksTo> ?o . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?m }"//
+ + "}";//
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(1, crh.getCount());
+
+
+ }
+
+
+
+
+
+
+
+ @Test
+ public void testEvaluateTwoIndexUnionFilter() throws AccumuloException, AccumuloSecurityException,
+ TableExistsException, RepositoryException, MalformedQueryException, SailException, QueryEvaluationException,
+ TableNotFoundException, TupleQueryResultHandlerException, RyaDAOException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX1")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX1");
+ }
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX2")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX2");
+ }
+
+ accCon.tableOperations().create(tablePrefix + "INDEX1");
+ accCon.tableOperations().create(tablePrefix + "INDEX2");
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(sub, RDF.TYPE, obj);
+ conn.add(sub2, RDF.TYPE, obj2);
+
+
+ String indexSparqlString = ""//
+ + "SELECT ?e ?l ?o " //
+ + "{" //
+ + " Filter(?l = \"label2\") " //
+ + " ?e a ?o . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?l ?o " //
+ + "{" //
+ + " Filter(?l = \"label2\") " //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?c ?e ?l ?o " //
+ + "{" //
+ + " Filter(?l = \"label2\") " //
+ + " ?e a ?c . "//
+ + " { ?e a ?o . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l }"//
+ + " UNION { ?e <uri:talksTo> ?o . ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l }"//
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, tablePrefix + "INDEX1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, tablePrefix + "INDEX2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+ Assert.assertEquals(6, crh.getCount());
+
+
+
+ }
+
+
+
+
+
+ @Test
+ public void testEvaluateTwoIndexLeftJoinUnionFilter() throws AccumuloException, AccumuloSecurityException,
+ TableExistsException, RepositoryException, MalformedQueryException, SailException, QueryEvaluationException,
+ TableNotFoundException, TupleQueryResultHandlerException, RyaDAOException {
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX1")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX1");
+ }
+
+ if (accCon.tableOperations().exists(tablePrefix + "INDEX2")) {
+ accCon.tableOperations().delete(tablePrefix + "INDEX2");
+ }
+
+ accCon.tableOperations().create(tablePrefix + "INDEX1");
+ accCon.tableOperations().create(tablePrefix + "INDEX2");
+
+ conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
+ conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
+ conn.add(sub, RDF.TYPE, obj);
+ conn.add(sub2, RDF.TYPE, obj2);
+
+ URI livesIn = new URIImpl("uri:livesIn");
+ URI city = new URIImpl("uri:city");
+ URI city2 = new URIImpl("uri:city2");
+ URI city3 = new URIImpl("uri:city3");
+ conn.add(sub,livesIn,city);
+ conn.add(sub2,livesIn,city2);
+ conn.add(sub2,livesIn,city3);
+ conn.add(sub,livesIn,city3);
+
+
+ String indexSparqlString = ""//
+ + "SELECT ?e ?l ?o " //
+ + "{" //
+ + " ?e a ?o . "//
+ + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String indexSparqlString2 = ""//
+ + "SELECT ?e ?l ?o " //
+ + "{" //
+ + " ?e <uri:talksTo> ?o . "//
+ + " ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
+ + "}";//
+
+ String queryString = ""//
+ + "SELECT ?c ?e ?l ?o " //
+ + "{" //
+ + " Filter(?c = <uri:city3>) " //
+ + " ?e <uri:livesIn> ?c . "//
+ + " OPTIONAL{{ ?e a ?o . ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l }"//
+ + " UNION { ?e <uri:talksTo> ?o . ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l }}"//
+ + "}";//
+
+ AccumuloIndexSet ais1 = new AccumuloIndexSet(indexSparqlString, conn, accCon, tablePrefix + "INDEX1");
+ AccumuloIndexSet ais2 = new AccumuloIndexSet(indexSparqlString2, conn, accCon, tablePrefix + "INDEX2");
+
+ CountingResultHandler crh = new CountingResultHandler();
+ conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(crh);
+
+// Scanner scan = accCon.createScanner(tablePrefix + "spo", new Authorizations("U"));
+//
+// for(Entry<Key,Value> e: scan) {
+// System.out.println(e.getKey().getRow());
+// }
+
+ Assert.assertEquals(6, crh.getCount());
+
+
+
+ }
+
+
+
+
+ public static class CountingResultHandler implements TupleQueryResultHandler {
+ private int count = 0;
+
+ public int getCount() {
+ return count;
+ }
+
+ public void resetCount() {
+ this.count = 0;
+ }
+
+ @Override
+ public void startQueryResult(List<String> arg0) throws TupleQueryResultHandlerException {
+ }
+
+
+ @Override
+ public void handleSolution(BindingSet arg0) throws TupleQueryResultHandlerException {
+ System.out.println(arg0);
+ count++;
+ System.out.println("Count is " + count);
+ }
+
+ @Override
+ public void endQueryResult() throws TupleQueryResultHandlerException {
+ }
+
+ @Override
+ public void handleBoolean(boolean arg0) throws QueryResultHandlerException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void handleLinks(List<String> arg0) throws QueryResultHandlerException {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+
+
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/efcae829/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
----------------------------------------------------------------------
diff --git a/extras/indexingExample/src/main/java/MongoRyaDirectExample.java b/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
index 7946afc..d42d96a 100644
--- a/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
+++ b/extras/indexingExample/src/main/java/MongoRyaDirectExample.java
@@ -23,7 +23,8 @@ import mvm.rya.api.RdfCloudTripleStoreConfiguration;
import mvm.rya.indexing.accumulo.ConfigUtils;
import mvm.rya.indexing.accumulo.geo.GeoConstants;
import mvm.rya.mongodb.MongoDBRdfConfiguration;
-import mvm.rya.sail.config.RyaSailFactory;
+import mvm.rya.rdftriplestore.RdfCloudTripleStore;
+import mvm.rya.rdftriplestore.inference.InferenceEngineException;
import org.apache.commons.lang.Validate;
import org.apache.hadoop.conf.Configuration;
@@ -75,11 +76,12 @@ public class MongoRyaDirectExample {
long start = System.currentTimeMillis();
log.info("Running SPARQL Example: Add and Delete");
-// testAddAndDelete(conn);
-// testAddAndDeleteNoContext(conn);
-// testAddNamespaces(conn);
-// testAddPointAndWithinSearch(conn);
+ testAddAndDelete(conn);
+ testAddAndDeleteNoContext(conn);
+ testAddNamespaces(conn);
+ testAddPointAndWithinSearch(conn);
testAddAndFreeTextSearchWithPCJ(conn);
+ testInfer(conn, sail);
log.info("TIME: " + (System.currentTimeMillis() - start) / 1000.);
} finally {
@@ -304,6 +306,34 @@ public class MongoRyaDirectExample {
Validate.isTrue(resultHandler.getCount() == 0);
}
+
+ public static void testInfer(SailRepositoryConnection conn, Sail sail) throws MalformedQueryException, RepositoryException,
+ UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
+
+ // Add data
+ String query = "INSERT DATA\n"//
+ + "{ \n"//
+ + " <http://acme.com/people/Mike> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <urn:type1>. "
+ + " <urn:type1> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:superclass>. }";
+
+ log.info("Performing Query");
+
+ Update update = conn.prepareUpdate(QueryLanguage.SPARQL, query);
+ update.execute();
+
+ // refresh the graph for inferencing (otherwise there is a five minute wait)
+ ((RdfCloudTripleStore) sail).getInferenceEngine().refreshGraph();
+
+ query = "select ?s { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <urn:superclass> . }";
+ CountingResultHandler resultHandler = new CountingResultHandler();
+ TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
+ tupleQuery.evaluate(resultHandler);
+ log.info("Result count : " + resultHandler.getCount());
+
+ Validate.isTrue(resultHandler.getCount() == 1);
+
+ resultHandler.resetCount();
+ }
public static void testAddNamespaces(SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException,
UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException {
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/efcae829/sail/src/main/java/mvm/rya/rdftriplestore/inference/InferenceEngine.java
----------------------------------------------------------------------
diff --git a/sail/src/main/java/mvm/rya/rdftriplestore/inference/InferenceEngine.java b/sail/src/main/java/mvm/rya/rdftriplestore/inference/InferenceEngine.java
index f4ed420..0e2e930 100644
--- a/sail/src/main/java/mvm/rya/rdftriplestore/inference/InferenceEngine.java
+++ b/sail/src/main/java/mvm/rya/rdftriplestore/inference/InferenceEngine.java
@@ -79,6 +79,7 @@ public class InferenceEngine {
checkArgument(ryaDAO.isInitialized(), "RdfDao is not initialized");
if (schedule) {
+ refreshGraph();
timer = new Timer(InferenceEngine.class.getName());
timer.scheduleAtFixedRate(new TimerTask() {