http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java index 63c5d13..5be8e7e 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/QueryJoinSelectOptimizerTest.java @@ -19,23 +19,12 @@ package org.apache.rya.rdftriplestore.evaluation; * under the License. */ - - import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.layout.TablePrefixLayoutStrategy; -import org.apache.rya.api.persist.RdfEvalStatsDAO; -import org.apache.rya.joinselect.AccumuloSelectivityEvalDAO; -import org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO; -import org.apache.rya.rdftriplestore.evaluation.QueryJoinSelectOptimizer; -import org.apache.rya.rdftriplestore.evaluation.RdfCloudTripleStoreSelectivityEvaluationStatistics; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; @@ -53,14 +42,20 @@ import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.Authorizations; import org.apache.hadoop.io.Text; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.layout.TablePrefixLayoutStrategy; +import org.apache.rya.api.persist.RdfEvalStatsDAO; +import org.apache.rya.joinselect.AccumuloSelectivityEvalDAO; +import org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO; +import org.eclipse.rdf4j.query.MalformedQueryException; +import org.eclipse.rdf4j.query.algebra.TupleExpr; +import org.eclipse.rdf4j.query.algebra.evaluation.impl.FilterOptimizer; +import org.eclipse.rdf4j.query.parser.ParsedQuery; +import org.eclipse.rdf4j.query.parser.sparql.SPARQLParser; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.algebra.evaluation.impl.FilterOptimizer; -import org.openrdf.query.parser.ParsedQuery; -import org.openrdf.query.parser.sparql.SPARQLParser; public class QueryJoinSelectOptimizerTest { @@ -950,7 +945,7 @@ public class QueryJoinSelectOptimizerTest { } TupleExpr te = getTupleExpr(q6); - TupleExpr te2 = (TupleExpr) te.clone(); + TupleExpr te2 = te.clone(); System.out.println("Bindings are " + te.getBindingNames()); RdfCloudTripleStoreSelectivityEvaluationStatistics ars = new RdfCloudTripleStoreSelectivityEvaluationStatistics(arc, res, accc); QueryJoinSelectOptimizer qjs = new QueryJoinSelectOptimizer(ars, accc);
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/RdfCloudTripleStoreSelectivityEvaluationStatisticsTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/RdfCloudTripleStoreSelectivityEvaluationStatisticsTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/RdfCloudTripleStoreSelectivityEvaluationStatisticsTest.java index bac1b11..77598e7 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/RdfCloudTripleStoreSelectivityEvaluationStatisticsTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/RdfCloudTripleStoreSelectivityEvaluationStatisticsTest.java @@ -19,45 +19,37 @@ package org.apache.rya.rdftriplestore.evaluation; * under the License. */ - - import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.concurrent.TimeUnit; -import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.layout.TablePrefixLayoutStrategy; -import org.apache.rya.api.persist.RdfEvalStatsDAO; -import org.apache.rya.joinselect.AccumuloSelectivityEvalDAO; -import org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.BatchWriter; import org.apache.accumulo.core.client.BatchWriterConfig; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.Scanner; 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.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Mutation; -import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.security.Authorizations; import org.apache.hadoop.io.Text; +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.layout.TablePrefixLayoutStrategy; +import org.apache.rya.api.persist.RdfEvalStatsDAO; +import org.apache.rya.joinselect.AccumuloSelectivityEvalDAO; +import org.apache.rya.prospector.service.ProspectorServiceEvalStatsDAO; +import org.eclipse.rdf4j.query.MalformedQueryException; +import org.eclipse.rdf4j.query.algebra.TupleExpr; +import org.eclipse.rdf4j.query.parser.ParsedQuery; +import org.eclipse.rdf4j.query.parser.sparql.SPARQLParser; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.parser.ParsedQuery; -import org.openrdf.query.parser.sparql.SPARQLParser; public class RdfCloudTripleStoreSelectivityEvaluationStatisticsTest { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java index c1e7d10..f40b4e9 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/evaluation/StatementPatternEvalTest.java @@ -37,23 +37,24 @@ import org.apache.rya.api.domain.RyaURI; import org.apache.rya.api.domain.StatementMetadata; import org.apache.rya.api.persist.RyaDAOException; import org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection.StoreTripleSource; +import org.eclipse.rdf4j.common.iteration.CloseableIteration; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.MalformedQueryException; +import org.eclipse.rdf4j.query.QueryEvaluationException; +import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.evaluation.QueryBindingSet; +import org.eclipse.rdf4j.query.algebra.helpers.StatementPatternCollector; +import org.eclipse.rdf4j.query.parser.ParsedQuery; +import org.eclipse.rdf4j.query.parser.sparql.SPARQLParser; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.openrdf.model.impl.URIImpl; -import org.openrdf.query.BindingSet; -import org.openrdf.query.MalformedQueryException; -import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.evaluation.QueryBindingSet; -import org.openrdf.query.algebra.helpers.StatementPatternCollector; -import org.openrdf.query.parser.ParsedQuery; -import org.openrdf.query.parser.sparql.SPARQLParser; - -import info.aduna.iteration.CloseableIteration; public class StatementPatternEvalTest { + private static final ValueFactory VF = SimpleValueFactory.getInstance(); private AccumuloRyaDAO dao; private AccumuloRdfConfiguration conf; @@ -109,16 +110,16 @@ public class StatementPatternEvalTest { Assert.assertEquals(3, bsList.size()); QueryBindingSet expected1 = new QueryBindingSet(); - expected1.addBinding("x", new URIImpl("uri:Joe")); - expected1.addBinding("c", new URIImpl("uri:context1")); + expected1.addBinding("x", VF.createIRI("uri:Joe")); + expected1.addBinding("c", VF.createIRI("uri:context1")); QueryBindingSet expected2 = new QueryBindingSet(); - expected2.addBinding("x", new URIImpl("uri:Doug")); - expected2.addBinding("c", new URIImpl("uri:context2")); + expected2.addBinding("x", VF.createIRI("uri:Doug")); + expected2.addBinding("c", VF.createIRI("uri:context2")); QueryBindingSet expected3 = new QueryBindingSet(); - expected3.addBinding("x", new URIImpl("uri:Eric")); - expected3.addBinding("c", new URIImpl("uri:context3")); + expected3.addBinding("x", VF.createIRI("uri:Eric")); + expected3.addBinding("c", VF.createIRI("uri:context3")); Set<BindingSet> expected = new HashSet<>(Arrays.asList(expected1, expected2, expected3)); Set<BindingSet> actual = new HashSet<>(bsList); @@ -149,10 +150,10 @@ public class StatementPatternEvalTest { dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); - bsConstraint1.addBinding("c", new URIImpl("uri:context2")); + bsConstraint1.addBinding("c", VF.createIRI("uri:context2")); QueryBindingSet bsConstraint2 = new QueryBindingSet(); - bsConstraint2.addBinding("c", new URIImpl("uri:context1")); + bsConstraint2.addBinding("c", VF.createIRI("uri:context1")); CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1, bsConstraint2)); @@ -165,12 +166,12 @@ public class StatementPatternEvalTest { Assert.assertEquals(2, bsList.size()); QueryBindingSet expected1 = new QueryBindingSet(); - expected1.addBinding("x", new URIImpl("uri:Joe")); - expected1.addBinding("c", new URIImpl("uri:context1")); + expected1.addBinding("x", VF.createIRI("uri:Joe")); + expected1.addBinding("c", VF.createIRI("uri:context1")); QueryBindingSet expected2 = new QueryBindingSet(); - expected2.addBinding("x", new URIImpl("uri:Doug")); - expected2.addBinding("c", new URIImpl("uri:context2")); + expected2.addBinding("x", VF.createIRI("uri:Doug")); + expected2.addBinding("c", VF.createIRI("uri:context2")); Set<BindingSet> expected = new HashSet<>(Arrays.asList(expected1, expected2)); Set<BindingSet> actual = new HashSet<>(bsList); @@ -203,10 +204,10 @@ public class StatementPatternEvalTest { dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); - bsConstraint1.addBinding("c", new URIImpl("uri:context1")); + bsConstraint1.addBinding("c", VF.createIRI("uri:context1")); QueryBindingSet bsConstraint2 = new QueryBindingSet(); - bsConstraint2.addBinding("c", new URIImpl("uri:context1")); + bsConstraint2.addBinding("c", VF.createIRI("uri:context1")); CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1, bsConstraint2)); @@ -219,8 +220,8 @@ public class StatementPatternEvalTest { Assert.assertEquals(1, bsList.size()); QueryBindingSet expected = new QueryBindingSet(); - expected.addBinding("x", new URIImpl("uri:Joe")); - expected.addBinding("c", new URIImpl("uri:context1")); + expected.addBinding("x", VF.createIRI("uri:Joe")); + expected.addBinding("c", VF.createIRI("uri:context1")); Assert.assertEquals(expected, bsList.get(0)); @@ -260,7 +261,7 @@ public class StatementPatternEvalTest { Assert.assertEquals(1, bsList.size()); QueryBindingSet expected = new QueryBindingSet(); - expected.addBinding("x", new URIImpl("uri:Joe")); + expected.addBinding("x", VF.createIRI("uri:Joe")); Assert.assertEquals(expected, bsList.get(0)); @@ -289,7 +290,7 @@ public class StatementPatternEvalTest { dao.add(statement3); QueryBindingSet bsConstraint1 = new QueryBindingSet(); - bsConstraint1.addBinding("x", new URIImpl("uri:Doug")); + bsConstraint1.addBinding("x", VF.createIRI("uri:Doug")); CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1)); @@ -301,7 +302,7 @@ public class StatementPatternEvalTest { Assert.assertEquals(1, bsList.size()); QueryBindingSet expected = new QueryBindingSet(); - expected.addBinding("x", new URIImpl("uri:Doug")); + expected.addBinding("x", VF.createIRI("uri:Doug")); Assert.assertEquals(expected, bsList.get(0)); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java index d239577..9c08468 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/AllValuesFromVisitorTest.java @@ -29,44 +29,44 @@ import java.util.Set; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.OWL; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.query.algebra.Join; +import org.eclipse.rdf4j.query.algebra.Projection; +import org.eclipse.rdf4j.query.algebra.ProjectionElem; +import org.eclipse.rdf4j.query.algebra.ProjectionElemList; +import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.TupleExpr; +import org.eclipse.rdf4j.query.algebra.Union; +import org.eclipse.rdf4j.query.algebra.Var; import org.junit.Assert; import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.OWL; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.query.algebra.Join; -import org.openrdf.query.algebra.Projection; -import org.openrdf.query.algebra.ProjectionElem; -import org.openrdf.query.algebra.ProjectionElemList; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.algebra.Union; -import org.openrdf.query.algebra.Var; public class AllValuesFromVisitorTest { private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); - private final ValueFactory vf = new ValueFactoryImpl(); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); // Value types - private final URI person = vf.createURI("urn:Person"); - private final URI dog = vf.createURI("urn:Dog"); + private final IRI person = VF.createIRI("urn:Person"); + private final IRI dog = VF.createIRI("urn:Dog"); // Predicates - private final URI parent = vf.createURI("urn:parent"); - private final URI relative = vf.createURI("urn:relative"); + private final IRI parent = VF.createIRI("urn:parent"); + private final IRI relative = VF.createIRI("urn:relative"); // Restriction types - private final URI parentsAreTallPeople = vf.createURI("urn:parentsAreTallPeople"); - private final URI parentsArePeople = vf.createURI("urn:parentsArePeople"); - private final URI relativesArePeople = vf.createURI("urn:relativesArePeople"); - private final URI parentsAreDogs = vf.createURI("urn:parentsAreDogs"); + private final IRI parentsAreTallPeople = VF.createIRI("urn:parentsAreTallPeople"); + private final IRI parentsArePeople = VF.createIRI("urn:parentsArePeople"); + private final IRI relativesArePeople = VF.createIRI("urn:relativesArePeople"); + private final IRI parentsAreDogs = VF.createIRI("urn:parentsAreDogs"); @Test public void testRewriteTypePattern() throws Exception { // Configure a mock instance engine with an ontology: final InferenceEngine inferenceEngine = mock(InferenceEngine.class); - Map<Resource, Set<URI>> personAVF = new HashMap<>(); + Map<Resource, Set<IRI>> personAVF = new HashMap<>(); personAVF.put(parentsAreTallPeople, new HashSet<>()); personAVF.put(parentsArePeople, new HashSet<>()); personAVF.put(relativesArePeople, new HashSet<>()); @@ -74,7 +74,7 @@ public class AllValuesFromVisitorTest { personAVF.get(parentsArePeople).add(parent); personAVF.get(relativesArePeople).add(relative); personAVF.get(relativesArePeople).add(parent); - Map<Resource, Set<URI>> dogAVF = new HashMap<>(); + Map<Resource, Set<IRI>> dogAVF = new HashMap<>(); dogAVF.put(parentsAreDogs, new HashSet<>()); dogAVF.get(parentsAreDogs).add(parent); when(inferenceEngine.getAllValuesFromByValueType(person)).thenReturn(personAVF); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java index 40f9098..0c5542e 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/DomainRangeVisitorTest.java @@ -27,36 +27,36 @@ import java.util.Stack; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.model.vocabulary.RDFS; +import org.eclipse.rdf4j.query.algebra.Join; +import org.eclipse.rdf4j.query.algebra.Projection; +import org.eclipse.rdf4j.query.algebra.ProjectionElem; +import org.eclipse.rdf4j.query.algebra.ProjectionElemList; +import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.TupleExpr; +import org.eclipse.rdf4j.query.algebra.Union; +import org.eclipse.rdf4j.query.algebra.Var; import org.junit.Assert; import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.model.vocabulary.RDFS; -import org.openrdf.query.algebra.Join; -import org.openrdf.query.algebra.Projection; -import org.openrdf.query.algebra.ProjectionElem; -import org.openrdf.query.algebra.ProjectionElemList; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.algebra.Union; -import org.openrdf.query.algebra.Var; public class DomainRangeVisitorTest { private static final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); - private static final ValueFactory vf = new ValueFactoryImpl(); - private static final URI person = vf.createURI("lubm:Person"); - private static final URI advisor = vf.createURI("lubm:advisor"); - private static final URI takesCourse = vf.createURI("lubm:takesCourse"); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); + private static final IRI person = VF.createIRI("lubm:Person"); + private static final IRI advisor = VF.createIRI("lubm:advisor"); + private static final IRI takesCourse = VF.createIRI("lubm:takesCourse"); @Test public void testRewriteTypePattern() throws Exception { final InferenceEngine inferenceEngine = mock(InferenceEngine.class); - final Set<URI> domainPredicates = new HashSet<>(); - final Set<URI> rangePredicates = new HashSet<>(); + final Set<IRI> domainPredicates = new HashSet<>(); + final Set<IRI> rangePredicates = new HashSet<>(); domainPredicates.add(advisor); domainPredicates.add(takesCourse); rangePredicates.add(advisor); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasSelfVisitorTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasSelfVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasSelfVisitorTest.java index ba6b7da..3ce93c0 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasSelfVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasSelfVisitorTest.java @@ -25,34 +25,34 @@ import java.util.HashSet; import java.util.Set; import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.query.algebra.Extension; +import org.eclipse.rdf4j.query.algebra.ExtensionElem; +import org.eclipse.rdf4j.query.algebra.Projection; +import org.eclipse.rdf4j.query.algebra.ProjectionElem; +import org.eclipse.rdf4j.query.algebra.ProjectionElemList; +import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.Union; +import org.eclipse.rdf4j.query.algebra.Var; import org.junit.Assert; import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.query.algebra.Extension; -import org.openrdf.query.algebra.ExtensionElem; -import org.openrdf.query.algebra.Projection; -import org.openrdf.query.algebra.ProjectionElem; -import org.openrdf.query.algebra.ProjectionElemList; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.Union; -import org.openrdf.query.algebra.Var; public class HasSelfVisitorTest { private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); - private static final ValueFactory VF = new ValueFactoryImpl(); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); - private static final URI narcissist = VF.createURI("urn:Narcissist"); - private static final URI love = VF.createURI("urn:love"); - private static final URI self = VF.createURI("urn:self"); + private static final IRI narcissist = VF.createIRI("urn:Narcissist"); + private static final IRI love = VF.createIRI("urn:love"); + private static final IRI self = VF.createIRI("urn:self"); @Test public void testTypePattern() throws Exception { final InferenceEngine inferenceEngine = mock(InferenceEngine.class); - final Set<URI> narcissistProps = new HashSet<>(); + final Set<IRI> narcissistProps = new HashSet<>(); narcissistProps.add(love); when(inferenceEngine.getHasSelfImplyingType(narcissist)).thenReturn(narcissistProps); final Var subj = new Var("s"); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java index c5f2a90..483d593 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/HasValueVisitorTest.java @@ -23,50 +23,51 @@ import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; import org.apache.rya.accumulo.AccumuloRdfConfiguration; -import org.apache.rya.rdftriplestore.inference.HasValueVisitor; -import org.apache.rya.rdftriplestore.inference.InferenceEngine; +import org.apache.rya.api.utils.NullableStatementImpl; import org.apache.rya.rdftriplestore.utils.FixedStatementPattern; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.query.algebra.Join; +import org.eclipse.rdf4j.query.algebra.Projection; +import org.eclipse.rdf4j.query.algebra.ProjectionElem; +import org.eclipse.rdf4j.query.algebra.ProjectionElemList; +import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.TupleExpr; +import org.eclipse.rdf4j.query.algebra.Union; +import org.eclipse.rdf4j.query.algebra.Var; import org.junit.Assert; import org.junit.Test; -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.model.vocabulary.RDF; -import org.openrdf.query.algebra.Join; -import org.openrdf.query.algebra.Projection; -import org.openrdf.query.algebra.ProjectionElem; -import org.openrdf.query.algebra.ProjectionElemList; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.TupleExpr; -import org.openrdf.query.algebra.Union; -import org.openrdf.query.algebra.Var; public class HasValueVisitorTest { private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); - private final ValueFactory vf = new ValueFactoryImpl(); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); - private final URI chordate = vf.createURI("urn:Chordate"); - private final URI vertebrate = vf.createURI("urn:Vertebrate"); - private final URI mammal = vf.createURI("urn:Mammal"); - private final URI tunicate = vf.createURI("urn:Tunicate"); - private final URI hasCharacteristic = vf.createURI("urn:anatomicalCharacteristic"); - private final URI notochord = vf.createURI("urn:notochord"); - private final URI skull = vf.createURI("urn:skull"); - private final URI belongsTo = vf.createURI("urn:belongsToTaxon"); - private final URI chordata = vf.createURI("urn:Chordata"); + private final IRI chordate = VF.createIRI("urn:Chordate"); + private final IRI vertebrate = VF.createIRI("urn:Vertebrate"); + private final IRI mammal = VF.createIRI("urn:Mammal"); + private final IRI tunicate = VF.createIRI("urn:Tunicate"); + private final IRI hasCharacteristic = VF.createIRI("urn:anatomicalCharacteristic"); + private final IRI notochord = VF.createIRI("urn:notochord"); + private final IRI skull = VF.createIRI("urn:skull"); + private final IRI belongsTo = VF.createIRI("urn:belongsToTaxon"); + private final IRI chordata = VF.createIRI("urn:Chordata"); @Test public void testRewriteTypePattern() throws Exception { // Configure a mock instance engine with an ontology: final InferenceEngine inferenceEngine = mock(InferenceEngine.class); - Map<URI, Set<Value>> vertebrateValues = new HashMap<>(); + Map<IRI, Set<Value>> vertebrateValues = new HashMap<>(); vertebrateValues.put(hasCharacteristic, new HashSet<>()); vertebrateValues.put(belongsTo, new HashSet<>()); vertebrateValues.get(hasCharacteristic).add(notochord); @@ -133,10 +134,10 @@ public class HasValueVisitorTest { Assert.assertNotNull(belongsToFSP); // Verify the expected FSPs for the appropriate properties: Assert.assertEquals(2, hasCharacteristicFSP.statements.size()); - Assert.assertTrue(hasCharacteristicFSP.statements.contains(vf.createStatement(vertebrate, hasCharacteristic, skull))); - Assert.assertTrue(hasCharacteristicFSP.statements.contains(vf.createStatement(vertebrate, hasCharacteristic, notochord))); + Assert.assertTrue(hasCharacteristicFSP.statements.contains(VF.createStatement(vertebrate, hasCharacteristic, skull))); + Assert.assertTrue(hasCharacteristicFSP.statements.contains(VF.createStatement(vertebrate, hasCharacteristic, notochord))); Assert.assertEquals(1, belongsToFSP.statements.size()); - Assert.assertTrue(belongsToFSP.statements.contains(vf.createStatement(vertebrate, belongsTo, chordata))); + Assert.assertTrue(belongsToFSP.statements.contains(VF.createStatement(vertebrate, belongsTo, chordata))); } @Test @@ -183,15 +184,24 @@ public class HasValueVisitorTest { Assert.assertEquals(fsp.getSubjectVar(), sp.getObjectVar()); Assert.assertEquals(originalSP.getObjectVar(), fsp.getObjectVar()); // Verify FSP: should provide (type, value) pairs - final Set<Statement> expectedStatements = new HashSet<>(); - final URI fspPred = (URI) fsp.getPredicateVar().getValue(); - expectedStatements.add(vf.createStatement(chordate, fspPred, notochord)); - expectedStatements.add(vf.createStatement(tunicate, fspPred, notochord)); - expectedStatements.add(vf.createStatement(vertebrate, fspPred, notochord)); - expectedStatements.add(vf.createStatement(mammal, fspPred, notochord)); - expectedStatements.add(vf.createStatement(vertebrate, fspPred, skull)); - expectedStatements.add(vf.createStatement(mammal, fspPred, skull)); - final Set<Statement> actualStatements = new HashSet<>(fsp.statements); - Assert.assertEquals(expectedStatements, actualStatements); + final List<Statement> expectedStatements = new LinkedList<>(); + final IRI fspPred = (IRI) fsp.getPredicateVar().getValue(); + expectedStatements.add(new NullableStatementImpl(chordate, fspPred, notochord)); + expectedStatements.add(new NullableStatementImpl(tunicate, fspPred, notochord)); + expectedStatements.add(new NullableStatementImpl(vertebrate, fspPred, notochord)); + expectedStatements.add(new NullableStatementImpl(mammal, fspPred, notochord)); + expectedStatements.add(new NullableStatementImpl(vertebrate, fspPred, skull)); + expectedStatements.add(new NullableStatementImpl(mammal, fspPred, skull)); + final List<Statement> actualStatements = new LinkedList<>(fsp.statements); + Assert.assertTrue(containsAll(expectedStatements, actualStatements)); + + } + private boolean containsAll(List<Statement> expected, List<Statement> actual){ + for( Statement a : actual){ + if (!expected.contains(a)){ + return false; + } + } + return true; } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java index b3eb900..3ef9e96 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceEngineTest.java @@ -32,17 +32,17 @@ import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.rdftriplestore.RdfCloudTripleStore; import org.apache.tinkerpop.gremlin.structure.Graph; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.query.QueryLanguage; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; import org.junit.After; import org.junit.Assert; import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.query.QueryLanguage; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.repository.sail.SailRepositoryConnection; import com.google.common.collect.Sets; @@ -51,7 +51,7 @@ import junit.framework.TestCase; public class InferenceEngineTest extends TestCase { private Connector connector; private AccumuloRyaDAO dao; - private final ValueFactory vf = new ValueFactoryImpl(); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); private AccumuloRdfConfiguration conf; private RdfCloudTripleStore store; private InferenceEngine inferenceEngine; @@ -102,19 +102,19 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, insert).execute(); inferenceEngine.refreshGraph(); - final URI a = vf.createURI("urn:A"); - final URI b = vf.createURI("urn:B"); - final URI c = vf.createURI("urn:C"); - final URI d = vf.createURI("urn:D"); - final URI e = vf.createURI("urn:E"); - final URI f = vf.createURI("urn:F"); - final URI g = vf.createURI("urn:G"); - final URI z = vf.createURI("urn:Z"); - final URI missing = vf.createURI("urn:Missing"); - final Set<URI> empty = new HashSet<>(); - final Set<URI> belowLevel2 = new HashSet<>(Arrays.asList(new URI[] { a, b })); - final Set<URI> belowLevel3 = new HashSet<>(Arrays.asList(new URI[] { a, b, c, d, e })); - final Set<URI> belowLevel4 = new HashSet<>(Arrays.asList(new URI[] { a, b, c, d, e, f, g })); + final IRI a = VF.createIRI("urn:A"); + final IRI b = VF.createIRI("urn:B"); + final IRI c = VF.createIRI("urn:C"); + final IRI d = VF.createIRI("urn:D"); + final IRI e = VF.createIRI("urn:E"); + final IRI f = VF.createIRI("urn:F"); + final IRI g = VF.createIRI("urn:G"); + final IRI z = VF.createIRI("urn:Z"); + final IRI missing = VF.createIRI("urn:Missing"); + final Set<IRI> empty = new HashSet<>(); + final Set<IRI> belowLevel2 = new HashSet<>(Arrays.asList(a, b)); + final Set<IRI> belowLevel3 = new HashSet<>(Arrays.asList(a, b, c, d, e)); + final Set<IRI> belowLevel4 = new HashSet<>(Arrays.asList(a, b, c, d, e, f, g)); Assert.assertEquals(empty, inferenceEngine.getSubClasses(a)); Assert.assertEquals(empty, inferenceEngine.getSubClasses(b)); Assert.assertEquals(empty, inferenceEngine.getSubClasses(z)); @@ -141,20 +141,20 @@ public class InferenceEngineTest extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, insert).execute(); inferenceEngine.refreshGraph(); final Graph graph = inferenceEngine.getSubPropertyOfGraph(); - final URI p = vf.createURI("urn:p"); - final URI q = vf.createURI("urn:q"); - final URI r = vf.createURI("urn:r"); - final URI s = vf.createURI("urn:s"); - final URI t = vf.createURI("urn:t"); - final URI u = vf.createURI("urn:u"); - final URI v = vf.createURI("urn:v"); - final URI w = vf.createURI("urn:w"); - final URI missing = vf.createURI("urn:Missing"); - final Set<URI> empty = new HashSet<>(); - final Set<URI> belowQ = new HashSet<>(Arrays.asList(new URI[] { p })); - final Set<URI> belowR = new HashSet<>(Arrays.asList(new URI[] { p, r, s })); - final Set<URI> belowT = new HashSet<>(Arrays.asList(new URI[] { p, q })); - final Set<URI> belowU = new HashSet<>(Arrays.asList(new URI[] { p, q, r, s, t, u, v })); + final IRI p = VF.createIRI("urn:p"); + final IRI q = VF.createIRI("urn:q"); + final IRI r = VF.createIRI("urn:r"); + final IRI s = VF.createIRI("urn:s"); + final IRI t = VF.createIRI("urn:t"); + final IRI u = VF.createIRI("urn:u"); + final IRI v = VF.createIRI("urn:v"); + final IRI w = VF.createIRI("urn:w"); + final IRI missing = VF.createIRI("urn:Missing"); + final Set<IRI> empty = new HashSet<>(); + final Set<IRI> belowQ = new HashSet<>(Arrays.asList(p)); + final Set<IRI> belowR = new HashSet<>(Arrays.asList(p, r, s)); + final Set<IRI> belowT = new HashSet<>(Arrays.asList(p, q)); + final Set<IRI> belowU = new HashSet<>(Arrays.asList(p, q, r, s, t, u, v)); Assert.assertEquals(empty, InferenceEngine.findParents(graph, p)); Assert.assertEquals(empty, InferenceEngine.findParents(graph, w)); Assert.assertEquals(empty, InferenceEngine.findParents(graph, missing)); @@ -189,29 +189,29 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, insert).execute(); inferenceEngine.refreshGraph(); - final Set<URI> hasDomainD1 = inferenceEngine.getPropertiesWithDomain(vf.createURI("urn:D1")); - final Set<URI> hasDomainD2 = inferenceEngine.getPropertiesWithDomain(vf.createURI("urn:D2")); - final Set<URI> hasDomainD3 = inferenceEngine.getPropertiesWithDomain(vf.createURI("urn:D3")); - final Set<URI> hasRangeD1 = inferenceEngine.getPropertiesWithRange(vf.createURI("urn:D1")); - final Set<URI> hasRangeD2 = inferenceEngine.getPropertiesWithRange(vf.createURI("urn:D2")); - final Set<URI> hasRangeD3 = inferenceEngine.getPropertiesWithRange(vf.createURI("urn:D3")); - final Set<URI> hasDomainR1 = inferenceEngine.getPropertiesWithDomain(vf.createURI("urn:R1")); - final Set<URI> hasDomainR2 = inferenceEngine.getPropertiesWithDomain(vf.createURI("urn:R2")); - final Set<URI> hasDomainR3 = inferenceEngine.getPropertiesWithDomain(vf.createURI("urn:R3")); - final Set<URI> hasRangeR1 = inferenceEngine.getPropertiesWithRange(vf.createURI("urn:R1")); - final Set<URI> hasRangeR2 = inferenceEngine.getPropertiesWithRange(vf.createURI("urn:R2")); - final Set<URI> hasRangeR3 = inferenceEngine.getPropertiesWithRange(vf.createURI("urn:R3")); - final Set<URI> empty = new HashSet<>(); - final Set<URI> expectedForward = new HashSet<>(); - expectedForward.add(vf.createURI("urn:p2")); - expectedForward.add(vf.createURI("urn:p1")); - expectedForward.add(vf.createURI("urn:q2")); - expectedForward.add(vf.createURI("urn:q1")); - final Set<URI> expectedInverse = new HashSet<>(); - expectedInverse.add(vf.createURI("urn:i1")); - expectedInverse.add(vf.createURI("urn:i2")); - expectedInverse.add(vf.createURI("urn:j1")); - expectedInverse.add(vf.createURI("urn:j2")); + final Set<IRI> hasDomainD1 = inferenceEngine.getPropertiesWithDomain(VF.createIRI("urn:D1")); + final Set<IRI> hasDomainD2 = inferenceEngine.getPropertiesWithDomain(VF.createIRI("urn:D2")); + final Set<IRI> hasDomainD3 = inferenceEngine.getPropertiesWithDomain(VF.createIRI("urn:D3")); + final Set<IRI> hasRangeD1 = inferenceEngine.getPropertiesWithRange(VF.createIRI("urn:D1")); + final Set<IRI> hasRangeD2 = inferenceEngine.getPropertiesWithRange(VF.createIRI("urn:D2")); + final Set<IRI> hasRangeD3 = inferenceEngine.getPropertiesWithRange(VF.createIRI("urn:D3")); + final Set<IRI> hasDomainR1 = inferenceEngine.getPropertiesWithDomain(VF.createIRI("urn:R1")); + final Set<IRI> hasDomainR2 = inferenceEngine.getPropertiesWithDomain(VF.createIRI("urn:R2")); + final Set<IRI> hasDomainR3 = inferenceEngine.getPropertiesWithDomain(VF.createIRI("urn:R3")); + final Set<IRI> hasRangeR1 = inferenceEngine.getPropertiesWithRange(VF.createIRI("urn:R1")); + final Set<IRI> hasRangeR2 = inferenceEngine.getPropertiesWithRange(VF.createIRI("urn:R2")); + final Set<IRI> hasRangeR3 = inferenceEngine.getPropertiesWithRange(VF.createIRI("urn:R3")); + final Set<IRI> empty = new HashSet<>(); + final Set<IRI> expectedForward = new HashSet<>(); + expectedForward.add(VF.createIRI("urn:p2")); + expectedForward.add(VF.createIRI("urn:p1")); + expectedForward.add(VF.createIRI("urn:q2")); + expectedForward.add(VF.createIRI("urn:q1")); + final Set<IRI> expectedInverse = new HashSet<>(); + expectedInverse.add(VF.createIRI("urn:i1")); + expectedInverse.add(VF.createIRI("urn:i2")); + expectedInverse.add(VF.createIRI("urn:j1")); + expectedInverse.add(VF.createIRI("urn:j2")); Assert.assertEquals(empty, hasDomainD1); Assert.assertEquals(empty, hasRangeD1); Assert.assertEquals(empty, hasDomainR1); @@ -248,24 +248,24 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, insert).execute(); inferenceEngine.refreshGraph(); - final Set<URI> properties = new HashSet<>(); - properties.add(vf.createURI("urn:headOf")); - properties.add(vf.createURI("urn:temporaryHeadOf")); - final Map<Resource, Set<URI>> chairDerivations = new HashMap<>(); - chairDerivations.put(vf.createURI("urn:Department"), properties); - chairDerivations.put(vf.createURI("urn:ScienceDepartment"), properties); - chairDerivations.put(vf.createURI("urn:HumanitiesDepartment"), properties); - final Map<Resource, Set<URI>> deanDerivations = new HashMap<>(); - deanDerivations.put(vf.createURI("urn:College"), properties); - final Map<Resource, Set<URI>> combinedDerivations = new HashMap<>(chairDerivations); - combinedDerivations.put(vf.createURI("urn:College"), properties); + final Set<IRI> properties = new HashSet<>(); + properties.add(VF.createIRI("urn:headOf")); + properties.add(VF.createIRI("urn:temporaryHeadOf")); + final Map<Resource, Set<IRI>> chairDerivations = new HashMap<>(); + chairDerivations.put(VF.createIRI("urn:Department"), properties); + chairDerivations.put(VF.createIRI("urn:ScienceDepartment"), properties); + chairDerivations.put(VF.createIRI("urn:HumanitiesDepartment"), properties); + final Map<Resource, Set<IRI>> deanDerivations = new HashMap<>(); + deanDerivations.put(VF.createIRI("urn:College"), properties); + final Map<Resource, Set<IRI>> combinedDerivations = new HashMap<>(chairDerivations); + combinedDerivations.put(VF.createIRI("urn:College"), properties); // Get someValuesFrom restrictions given the direct types - Assert.assertEquals(deanDerivations, inferenceEngine.getSomeValuesFromByRestrictionType(vf.createURI("urn:Dean"))); - Assert.assertEquals(chairDerivations, inferenceEngine.getSomeValuesFromByRestrictionType(vf.createURI("urn:Chair"))); + Assert.assertEquals(deanDerivations, inferenceEngine.getSomeValuesFromByRestrictionType(VF.createIRI("urn:Dean"))); + Assert.assertEquals(chairDerivations, inferenceEngine.getSomeValuesFromByRestrictionType(VF.createIRI("urn:Chair"))); // Finds the subtype's restrictions given the supertype - Assert.assertEquals(combinedDerivations, inferenceEngine.getSomeValuesFromByRestrictionType(vf.createURI("urn:Person"))); + Assert.assertEquals(combinedDerivations, inferenceEngine.getSomeValuesFromByRestrictionType(VF.createIRI("urn:Person"))); // Finds nothing if given a subtype which is not a restriction - Assert.assertEquals(new HashMap<>(), inferenceEngine.getSomeValuesFromByRestrictionType(vf.createURI("urn:ScienceDepartmentChair"))); + Assert.assertEquals(new HashMap<>(), inferenceEngine.getSomeValuesFromByRestrictionType(VF.createIRI("urn:ScienceDepartmentChair"))); } @Test @@ -283,20 +283,20 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, insert).execute(); inferenceEngine.refreshGraph(); - final Map<Resource, Set<URI>> restrictionsImplyingTerrier = new HashMap<>(); - final Set<URI> properties = new HashSet<>(); - properties.add(vf.createURI("urn:parent")); - properties.add(vf.createURI("urn:relative")); - restrictionsImplyingTerrier.put(vf.createURI("urn:Terrier"), properties); - restrictionsImplyingTerrier.put(vf.createURI("urn:Cairn_Terrier"), properties); - Assert.assertEquals(restrictionsImplyingTerrier, inferenceEngine.getAllValuesFromByValueType(vf.createURI("urn:Terrier"))); - final Map<Resource, Set<URI>> restrictionsImplyingDog = new HashMap<>(restrictionsImplyingTerrier); - restrictionsImplyingDog.put(vf.createURI("urn:Dog"), properties); - restrictionsImplyingDog.put(vf.createURI("urn:Retriever"), properties); - Assert.assertEquals(restrictionsImplyingDog, inferenceEngine.getAllValuesFromByValueType(vf.createURI("urn:Dog"))); - final Map<Resource, Set<URI>> restrictionsImplyingMammal = new HashMap<>(restrictionsImplyingDog); - restrictionsImplyingMammal.put(vf.createURI("urn:Person"), properties); - Assert.assertEquals(restrictionsImplyingMammal, inferenceEngine.getAllValuesFromByValueType(vf.createURI("urn:Mammal"))); + final Map<Resource, Set<IRI>> restrictionsImplyingTerrier = new HashMap<>(); + final Set<IRI> properties = new HashSet<>(); + properties.add(VF.createIRI("urn:parent")); + properties.add(VF.createIRI("urn:relative")); + restrictionsImplyingTerrier.put(VF.createIRI("urn:Terrier"), properties); + restrictionsImplyingTerrier.put(VF.createIRI("urn:Cairn_Terrier"), properties); + Assert.assertEquals(restrictionsImplyingTerrier, inferenceEngine.getAllValuesFromByValueType(VF.createIRI("urn:Terrier"))); + final Map<Resource, Set<IRI>> restrictionsImplyingDog = new HashMap<>(restrictionsImplyingTerrier); + restrictionsImplyingDog.put(VF.createIRI("urn:Dog"), properties); + restrictionsImplyingDog.put(VF.createIRI("urn:Retriever"), properties); + Assert.assertEquals(restrictionsImplyingDog, inferenceEngine.getAllValuesFromByValueType(VF.createIRI("urn:Dog"))); + final Map<Resource, Set<IRI>> restrictionsImplyingMammal = new HashMap<>(restrictionsImplyingDog); + restrictionsImplyingMammal.put(VF.createIRI("urn:Person"), properties); + Assert.assertEquals(restrictionsImplyingMammal, inferenceEngine.getAllValuesFromByValueType(VF.createIRI("urn:Mammal"))); } @Test @@ -320,14 +320,14 @@ public class InferenceEngineTest extends TestCase { final Map<Resource, Set<Value>> typeToValueImplications = new HashMap<>(); final Set<Value> vertebrateTaxa = new HashSet<>(); final Set<Value> tunicateTaxa = new HashSet<>(); - vertebrateTaxa.add(vf.createURI("urn:Vertebrata")); - tunicateTaxa.add(vf.createURI("urn:Tunicata")); + vertebrateTaxa.add(VF.createIRI("urn:Vertebrata")); + tunicateTaxa.add(VF.createIRI("urn:Tunicata")); final Set<Value> mammalTaxa = new HashSet<>(vertebrateTaxa); - mammalTaxa.add(vf.createURI("urn:Mammalia")); - typeToValueImplications.put(vf.createURI("urn:Vertebrate"), vertebrateTaxa); - typeToValueImplications.put(vf.createURI("urn:Tunicate"), tunicateTaxa); - typeToValueImplications.put(vf.createURI("urn:Mammal"), mammalTaxa); - Assert.assertEquals(typeToValueImplications, inferenceEngine.getHasValueByProperty(vf.createURI("urn:taxon"))); + mammalTaxa.add(VF.createIRI("urn:Mammalia")); + typeToValueImplications.put(VF.createIRI("urn:Vertebrate"), vertebrateTaxa); + typeToValueImplications.put(VF.createIRI("urn:Tunicate"), tunicateTaxa); + typeToValueImplications.put(VF.createIRI("urn:Mammal"), mammalTaxa); + Assert.assertEquals(typeToValueImplications, inferenceEngine.getHasValueByProperty(VF.createIRI("urn:taxon"))); } @Test @@ -350,35 +350,35 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, insert).execute(); inferenceEngine.refreshGraph(); - final URI legs = vf.createURI("urn:walksUsingLegs"); - final URI taxon = vf.createURI("urn:taxon"); + final IRI legs = VF.createIRI("urn:walksUsingLegs"); + final IRI taxon = VF.createIRI("urn:taxon"); // Verify direct restrictions: - final Map<URI, Set<Value>> valuesImplyingBiped = new HashMap<>(); + final Map<IRI, Set<Value>> valuesImplyingBiped = new HashMap<>(); valuesImplyingBiped.put(legs, new HashSet<>()); - valuesImplyingBiped.get(legs).add(vf.createLiteral("2")); - Assert.assertEquals(valuesImplyingBiped, inferenceEngine.getHasValueByType(vf.createURI("urn:Biped"))); - final Map<URI, Set<Value>> valuesImplyingMammal = new HashMap<>(); + valuesImplyingBiped.get(legs).add(VF.createLiteral("2")); + Assert.assertEquals(valuesImplyingBiped, inferenceEngine.getHasValueByType(VF.createIRI("urn:Biped"))); + final Map<IRI, Set<Value>> valuesImplyingMammal = new HashMap<>(); valuesImplyingMammal.put(taxon, new HashSet<>()); - valuesImplyingMammal.get(taxon).add(vf.createURI("urn:Mammalia")); - Assert.assertEquals(valuesImplyingMammal, inferenceEngine.getHasValueByType(vf.createURI("urn:Mammal"))); - final Map<URI, Set<Value>> valuesImplyingTunicate = new HashMap<>(); + valuesImplyingMammal.get(taxon).add(VF.createIRI("urn:Mammalia")); + Assert.assertEquals(valuesImplyingMammal, inferenceEngine.getHasValueByType(VF.createIRI("urn:Mammal"))); + final Map<IRI, Set<Value>> valuesImplyingTunicate = new HashMap<>(); valuesImplyingTunicate.put(taxon, new HashSet<>()); - valuesImplyingTunicate.get(taxon).add(vf.createURI("urn:Tunicata")); - Assert.assertEquals(valuesImplyingTunicate, inferenceEngine.getHasValueByType(vf.createURI("urn:Tunicate"))); - final Map<URI, Set<Value>> valuesImplyingPlant = new HashMap<>(); + valuesImplyingTunicate.get(taxon).add(VF.createIRI("urn:Tunicata")); + Assert.assertEquals(valuesImplyingTunicate, inferenceEngine.getHasValueByType(VF.createIRI("urn:Tunicate"))); + final Map<IRI, Set<Value>> valuesImplyingPlant = new HashMap<>(); valuesImplyingPlant.put(taxon, new HashSet<>()); - valuesImplyingPlant.get(taxon).add(vf.createURI("urn:Plantae")); - Assert.assertEquals(valuesImplyingPlant, inferenceEngine.getHasValueByType(vf.createURI("urn:Plant"))); + valuesImplyingPlant.get(taxon).add(VF.createIRI("urn:Plantae")); + Assert.assertEquals(valuesImplyingPlant, inferenceEngine.getHasValueByType(VF.createIRI("urn:Plant"))); // Verify indirect restrictions given a supertype, including multiple properties where relevant: - final Map<URI, Set<Value>> valuesImplyingVertebrate = new HashMap<>(); + final Map<IRI, Set<Value>> valuesImplyingVertebrate = new HashMap<>(); valuesImplyingVertebrate.put(taxon, new HashSet<>(valuesImplyingMammal.get(taxon))); - valuesImplyingVertebrate.get(taxon).add(vf.createURI("urn:Vertebrata")); - Assert.assertEquals(valuesImplyingVertebrate, inferenceEngine.getHasValueByType(vf.createURI("urn:Vertebrate"))); - final Map<URI, Set<Value>> valuesImplyingAnimal = new HashMap<>(); + valuesImplyingVertebrate.get(taxon).add(VF.createIRI("urn:Vertebrata")); + Assert.assertEquals(valuesImplyingVertebrate, inferenceEngine.getHasValueByType(VF.createIRI("urn:Vertebrate"))); + final Map<IRI, Set<Value>> valuesImplyingAnimal = new HashMap<>(); valuesImplyingAnimal.put(legs, valuesImplyingBiped.get(legs)); valuesImplyingAnimal.put(taxon, new HashSet<>(valuesImplyingVertebrate.get(taxon))); valuesImplyingAnimal.get(taxon).addAll(valuesImplyingTunicate.get(taxon)); - Assert.assertEquals(valuesImplyingAnimal, inferenceEngine.getHasValueByType(vf.createURI("urn:Animal"))); + Assert.assertEquals(valuesImplyingAnimal, inferenceEngine.getHasValueByType(VF.createIRI("urn:Animal"))); } @Test @@ -396,15 +396,15 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, ontology).execute(); inferenceEngine.refreshGraph(); - final Set<URI> subClassesA = inferenceEngine.getSubClasses(vf.createURI("urn:A")); - final Set<URI> subClassesB = inferenceEngine.getSubClasses(vf.createURI("urn:B")); - final Set<URI> expectedA = new HashSet<>(); - final Set<URI> expectedB = new HashSet<>(); - expectedB.add(vf.createURI("urn:Y")); - expectedB.add(vf.createURI("urn:SubY")); - expectedB.add(vf.createURI("urn:Z")); + final Set<IRI> subClassesA = inferenceEngine.getSubClasses(VF.createIRI("urn:A")); + final Set<IRI> subClassesB = inferenceEngine.getSubClasses(VF.createIRI("urn:B")); + final Set<IRI> expectedA = new HashSet<>(); + final Set<IRI> expectedB = new HashSet<>(); + expectedB.add(VF.createIRI("urn:Y")); + expectedB.add(VF.createIRI("urn:SubY")); + expectedB.add(VF.createIRI("urn:Z")); expectedA.addAll(expectedB); - expectedA.add(vf.createURI("urn:X")); + expectedA.add(VF.createIRI("urn:X")); Assert.assertEquals(expectedA, subClassesA); Assert.assertEquals(expectedB, subClassesB); } @@ -433,14 +433,14 @@ public class InferenceEngineTest extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, ontology).execute(); inferenceEngine.refreshGraph(); - final URI mother = vf.createURI("urn:Mother"); - final URI father = vf.createURI("urn:Father"); - final URI woman = vf.createURI("urn:Woman"); - final URI parent = vf.createURI("urn:Parent"); - final URI man = vf.createURI("urn:Man"); - final URI mom = vf.createURI("urn:Mom"); - final URI immediateFamilyMember = vf.createURI("urn:ImmediateFamilyMember"); - final URI relative = vf.createURI("urn:Relative"); + final IRI mother = VF.createIRI("urn:Mother"); + final IRI father = VF.createIRI("urn:Father"); + final IRI woman = VF.createIRI("urn:Woman"); + final IRI parent = VF.createIRI("urn:Parent"); + final IRI man = VF.createIRI("urn:Man"); + final IRI mom = VF.createIRI("urn:Mom"); + final IRI immediateFamilyMember = VF.createIRI("urn:ImmediateFamilyMember"); + final IRI relative = VF.createIRI("urn:Relative"); final List<Set<Resource>> intersectionsImplyingMother = Arrays.asList(Sets.newHashSet(woman, parent)); Assert.assertEquals(intersectionsImplyingMother, inferenceEngine.getIntersectionsImplying(mother)); @@ -450,7 +450,7 @@ public class InferenceEngineTest extends TestCase { // Check that Mother is a subclassOf Parent and Woman and // ImmediateFamilyMember and Relative. Also, Mother is a subclassOf // Mother and Mom through inferring equivalentClass. - final Set<URI> motherSuperClassUris = inferenceEngine.getSuperClasses(mother); + final Set<IRI> motherSuperClassUris = inferenceEngine.getSuperClasses(mother); Assert.assertNotNull(motherSuperClassUris); Assert.assertEquals(6, motherSuperClassUris.size()); Assert.assertTrue(motherSuperClassUris.contains(parent)); @@ -460,7 +460,7 @@ public class InferenceEngineTest extends TestCase { Assert.assertTrue(motherSuperClassUris.contains(mother)); Assert.assertTrue(motherSuperClassUris.contains(mom)); // Check that Father is a subclassOf Parent and Man - final Set<URI> fatherSuperClassUris = inferenceEngine.getSuperClasses(father); + final Set<IRI> fatherSuperClassUris = inferenceEngine.getSuperClasses(father); Assert.assertNotNull(fatherSuperClassUris); Assert.assertEquals(2, fatherSuperClassUris.size()); Assert.assertTrue(fatherSuperClassUris.contains(parent)); @@ -470,7 +470,7 @@ public class InferenceEngineTest extends TestCase { // ImmediateFamilyMember and Relative. The last 2 should be inferred // from having the same intersection as Mother. Also, Mom is a // subclassOf Mother and Mom through inferring equivalentClass. - final Set<URI> momSuperClassUris = inferenceEngine.getSuperClasses(mom); + final Set<IRI> momSuperClassUris = inferenceEngine.getSuperClasses(mom); Assert.assertNotNull(momSuperClassUris); Assert.assertEquals(6, momSuperClassUris.size()); Assert.assertTrue(momSuperClassUris.contains(parent)); @@ -525,29 +525,29 @@ public class InferenceEngineTest extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, ontology).execute(); inferenceEngine.refreshGraph(); - final URI suits = vf.createURI("urn:Suits"); - final URI ranks = vf.createURI("urn:Ranks"); - - final URI clubs = vf.createURI("urn:Clubs"); - final URI diamonds = vf.createURI("urn:Diamonds"); - final URI hearts = vf.createURI("urn:Hearts"); - final URI spades = vf.createURI("urn:Spades"); - - final URI ace = vf.createURI("urn:Ace"); - final URI two = vf.createURI("urn:2"); - final URI three = vf.createURI("urn:3"); - final URI four = vf.createURI("urn:4"); - final URI five = vf.createURI("urn:5"); - final URI six = vf.createURI("urn:6"); - final URI seven = vf.createURI("urn:7"); - final URI eight = vf.createURI("urn:8"); - final URI nine = vf.createURI("urn:9"); - final URI ten = vf.createURI("urn:10"); - final URI jack = vf.createURI("urn:Jack"); - final URI queen = vf.createURI("urn:Queen"); - final URI king = vf.createURI("urn:King"); - - final URI joker = vf.createURI("urn:Joker"); + final IRI suits = VF.createIRI("urn:Suits"); + final IRI ranks = VF.createIRI("urn:Ranks"); + + final IRI clubs = VF.createIRI("urn:Clubs"); + final IRI diamonds = VF.createIRI("urn:Diamonds"); + final IRI hearts = VF.createIRI("urn:Hearts"); + final IRI spades = VF.createIRI("urn:Spades"); + + final IRI ace = VF.createIRI("urn:Ace"); + final IRI two = VF.createIRI("urn:2"); + final IRI three = VF.createIRI("urn:3"); + final IRI four = VF.createIRI("urn:4"); + final IRI five = VF.createIRI("urn:5"); + final IRI six = VF.createIRI("urn:6"); + final IRI seven = VF.createIRI("urn:7"); + final IRI eight = VF.createIRI("urn:8"); + final IRI nine = VF.createIRI("urn:9"); + final IRI ten = VF.createIRI("urn:10"); + final IRI jack = VF.createIRI("urn:Jack"); + final IRI queen = VF.createIRI("urn:Queen"); + final IRI king = VF.createIRI("urn:King"); + + final IRI joker = VF.createIRI("urn:Joker"); final boolean isJokerEnumeratedType = inferenceEngine.isEnumeratedType(joker); Assert.assertFalse(isJokerEnumeratedType); @@ -572,12 +572,12 @@ public class InferenceEngineTest extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, ontology).execute(); inferenceEngine.refreshGraph(); final Set<Resource> expectedTypes = new HashSet<>(); - expectedTypes.add(vf.createURI("urn:Narcissist")); - Assert.assertEquals(expectedTypes, inferenceEngine.getHasSelfImplyingProperty(vf.createURI("urn:love"))); + expectedTypes.add(VF.createIRI("urn:Narcissist")); + Assert.assertEquals(expectedTypes, inferenceEngine.getHasSelfImplyingProperty(VF.createIRI("urn:love"))); - final Set<URI> expectedProperties = new HashSet<>(); - expectedProperties.add(vf.createURI("urn:love")); - Assert.assertEquals(expectedProperties, inferenceEngine.getHasSelfImplyingType(vf.createURI("urn:Narcissist"))); + final Set<IRI> expectedProperties = new HashSet<>(); + expectedProperties.add(VF.createIRI("urn:love")); + Assert.assertEquals(expectedProperties, inferenceEngine.getHasSelfImplyingType(VF.createIRI("urn:Narcissist"))); } @Test @@ -592,12 +592,12 @@ public class InferenceEngineTest extends TestCase { + "}}"; conn.prepareUpdate(QueryLanguage.SPARQL, ontology).execute(); inferenceEngine.refreshGraph(); - final URI comment = vf.createURI("urn:comment"); // none of the three supported types - final URI older = vf.createURI("urn:olderThan"); // transitive only - final URI notYounger = vf.createURI("urn:notYoungerThan"); // transitive and reflexive - final URI related = vf.createURI("urn:related"); // transitive and symmetric - final URI knows = vf.createURI("urn:knows"); // reflexive and symmetric - final URI sameAge = vf.createURI("urn:sameAgeAs"); // all three + final IRI comment = VF.createIRI("urn:comment"); // none of the three supported types + final IRI older = VF.createIRI("urn:olderThan"); // transitive only + final IRI notYounger = VF.createIRI("urn:notYoungerThan"); // transitive and reflexive + final IRI related = VF.createIRI("urn:related"); // transitive and symmetric + final IRI knows = VF.createIRI("urn:knows"); // reflexive and symmetric + final IRI sameAge = VF.createIRI("urn:sameAgeAs"); // all three // symmetry Assert.assertFalse(inferenceEngine.isSymmetricProperty(comment)); Assert.assertFalse(inferenceEngine.isSymmetricProperty(older)); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java index 375db4a..b53f5ee 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/InferenceIT.java @@ -32,23 +32,23 @@ import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.api.RdfCloudTripleStoreConstants; import org.apache.rya.rdftriplestore.RdfCloudTripleStore; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.FOAF; +import org.eclipse.rdf4j.model.vocabulary.OWL; +import org.eclipse.rdf4j.query.BindingSet; +import org.eclipse.rdf4j.query.QueryLanguage; +import org.eclipse.rdf4j.query.QueryResultHandlerException; +import org.eclipse.rdf4j.query.TupleQueryResultHandler; +import org.eclipse.rdf4j.query.TupleQueryResultHandlerException; +import org.eclipse.rdf4j.query.impl.ListBindingSet; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection; import org.junit.After; import org.junit.Assert; import org.junit.Test; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.FOAF; -import org.openrdf.model.vocabulary.OWL; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.QueryResultHandlerException; -import org.openrdf.query.TupleQueryResultHandler; -import org.openrdf.query.TupleQueryResultHandlerException; -import org.openrdf.query.impl.ListBindingSet; -import org.openrdf.repository.sail.SailRepository; -import org.openrdf.repository.sail.SailRepositoryConnection; import junit.framework.TestCase; @@ -57,7 +57,7 @@ public class InferenceIT extends TestCase { private Connector connector; private AccumuloRyaDAO dao; - private final ValueFactory vf = new ValueFactoryImpl(); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); private AccumuloRdfConfiguration conf; private RdfCloudTripleStore store; private InferenceEngine inferenceEngine; @@ -142,9 +142,9 @@ public class InferenceIT extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, instances).execute(); conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(resultHandler); final Set<Value> expected = new HashSet<>(); - expected.add(vf.createURI("urn:Alice")); - expected.add(vf.createURI("urn:Bob")); - expected.add(vf.createURI("urn:Eve")); + expected.add(VF.createIRI("urn:Alice")); + expected.add(VF.createIRI("urn:Bob")); + expected.add(VF.createIRI("urn:Eve")); final Set<Value> returned = new HashSet<>(); for (final BindingSet bs : solutions) { returned.add(bs.getBinding("x").getValue()); @@ -185,10 +185,10 @@ public class InferenceIT extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, instances).execute(); conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(resultHandler); final Set<Value> expected = new HashSet<>(); - expected.add(vf.createURI("urn:Professor1")); - expected.add(vf.createURI("urn:Professor2")); - expected.add(vf.createURI("urn:Professor3")); - expected.add(vf.createURI("urn:Professor4")); + expected.add(VF.createIRI("urn:Professor1")); + expected.add(VF.createIRI("urn:Professor2")); + expected.add(VF.createIRI("urn:Professor3")); + expected.add(VF.createIRI("urn:Professor4")); final Set<Value> returned = new HashSet<>(); for (final BindingSet bs : solutions) { returned.add(bs.getBinding("x").getValue()); @@ -244,9 +244,9 @@ public class InferenceIT extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, instances).execute(); conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(resultHandler); Map<Value, Integer> expected = new HashMap<>(); - expected.put(vf.createURI("urn:Alice"), 2); // from both courses - expected.put(vf.createURI("urn:Bob"), 1); // from course - expected.put(vf.createURI("urn:Carol"), 2); // from course and explicit type + expected.put(VF.createIRI("urn:Alice"), 2); // from both courses + expected.put(VF.createIRI("urn:Bob"), 1); // from course + expected.put(VF.createIRI("urn:Carol"), 2); // from course and explicit type Map<Value, Integer> returned = new HashMap<>(); for (BindingSet bs : solutions) { Value v = bs.getBinding("individual").getValue(); @@ -281,15 +281,15 @@ public class InferenceIT extends TestCase { for (final BindingSet solution : solutions) { answers.add(solution.getBinding("x").getValue()); } - Assert.assertTrue(answers.contains(vf.createURI("urn:Terry"))); - Assert.assertTrue(answers.contains(vf.createURI("urn:Rommy"))); + Assert.assertTrue(answers.contains(VF.createIRI("urn:Terry"))); + Assert.assertTrue(answers.contains(VF.createIRI("urn:Rommy"))); // If allValuesFrom inference were applied recursively, this triple wouldn't be needed: conn.prepareUpdate(QueryLanguage.SPARQL, "INSERT DATA { GRAPH <http://updated/test> {\n" + " <urn:Terry> a <urn:Cairn_Terrier> .\n" + "}}").execute(); conn.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT ?x { ?x a <urn:FictionalDog> }").evaluate(resultHandler); Assert.assertEquals(1, solutions.size()); - Assert.assertEquals(vf.createURI("urn:Toto"), solutions.get(0).getBinding("x").getValue()); + Assert.assertEquals(VF.createIRI("urn:Toto"), solutions.get(0).getBinding("x").getValue()); } @Test @@ -318,11 +318,11 @@ public class InferenceIT extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, instances).execute(); conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(resultHandler); final Set<Value> expected = new HashSet<>(); - expected.add(vf.createURI("urn:Alice")); - expected.add(vf.createURI("urn:Bob")); - expected.add(vf.createURI("urn:Carol")); - expected.add(vf.createURI("urn:Dan")); - expected.add(vf.createURI("urn:Lucy")); + expected.add(VF.createIRI("urn:Alice")); + expected.add(VF.createIRI("urn:Bob")); + expected.add(VF.createIRI("urn:Carol")); + expected.add(VF.createIRI("urn:Dan")); + expected.add(VF.createIRI("urn:Lucy")); final Set<Value> returned = new HashSet<>(); for (final BindingSet bs : solutions) { returned.add(bs.getBinding("x").getValue()); @@ -358,12 +358,12 @@ public class InferenceIT extends TestCase { final List<String> varNames = new LinkedList<>(); varNames.add("individual"); varNames.add("taxon"); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Alice"), vf.createURI("urn:Hominidae"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Alice"), vf.createURI("urn:Mammalia"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Bigfoot"), vf.createURI("urn:Mammalia"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Carol"), vf.createURI("urn:Hominidae"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Hank"), vf.createURI("urn:Carnivora"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Hank"), vf.createURI("urn:Mammalia"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Alice"), VF.createIRI("urn:Hominidae"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Alice"), VF.createIRI("urn:Mammalia"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Bigfoot"), VF.createIRI("urn:Mammalia"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Carol"), VF.createIRI("urn:Hominidae"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Hank"), VF.createIRI("urn:Carnivora"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Hank"), VF.createIRI("urn:Mammalia"))); Assert.assertEquals(expected, new HashSet<>(solutions)); } @@ -393,9 +393,9 @@ public class InferenceIT extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, instances).execute(); conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate(resultHandler); final Set<Value> expected = new HashSet<>(); - expected.add(vf.createURI("urn:Bob")); - expected.add(vf.createURI("urn:Carol")); - expected.add(vf.createURI("urn:Eve")); + expected.add(VF.createIRI("urn:Bob")); + expected.add(VF.createIRI("urn:Carol")); + expected.add(VF.createIRI("urn:Eve")); final Set<Value> returned = new HashSet<>(); for (final BindingSet bs : solutions) { returned.add(bs.getBinding("x").getValue()); @@ -433,36 +433,36 @@ public class InferenceIT extends TestCase { final String motherQuery = "SELECT ?individual { GRAPH <http://updated/test> { ?individual rdf:type <urn:Mother> } } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, motherQuery).evaluate(resultHandler); final Set<BindingSet> expectedMothers = new HashSet<>(); - expectedMothers.add(new ListBindingSet(varNames, vf.createURI("urn:Susan"))); + expectedMothers.add(new ListBindingSet(varNames, VF.createIRI("urn:Susan"))); Assert.assertEquals(expectedMothers, new HashSet<>(solutions)); // Find all <urn:Father> types (expect 1 result) final String fatherQuery = "SELECT ?individual { GRAPH <http://updated/test> { ?individual rdf:type <urn:Father> } } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, fatherQuery).evaluate(resultHandler); final Set<BindingSet> expectedFathers = new HashSet<>(); - expectedFathers.add(new ListBindingSet(varNames, vf.createURI("urn:Bob"))); + expectedFathers.add(new ListBindingSet(varNames, VF.createIRI("urn:Bob"))); Assert.assertEquals(expectedFathers, new HashSet<>(solutions)); // Find all <urn:Parent> types (expect 2 results) final String parentQuery = "SELECT ?individual { GRAPH <http://updated/test> { ?individual rdf:type <urn:Parent> } } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, parentQuery).evaluate(resultHandler); final Set<BindingSet> expectedParents = new HashSet<>(); - expectedParents.add(new ListBindingSet(varNames, vf.createURI("urn:Bob"))); - expectedParents.add(new ListBindingSet(varNames, vf.createURI("urn:Susan"))); + expectedParents.add(new ListBindingSet(varNames, VF.createIRI("urn:Bob"))); + expectedParents.add(new ListBindingSet(varNames, VF.createIRI("urn:Susan"))); Assert.assertEquals(expectedParents, new HashSet<>(solutions)); // Find all <urn:Woman> types (expect 1 result) final String womanQuery = "SELECT ?individual { GRAPH <http://updated/test> { ?individual rdf:type <urn:Woman> } } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, womanQuery).evaluate(resultHandler); final Set<BindingSet> expectedWomen = new HashSet<>(); - expectedWomen.add(new ListBindingSet(varNames, vf.createURI("urn:Susan"))); + expectedWomen.add(new ListBindingSet(varNames, VF.createIRI("urn:Susan"))); Assert.assertEquals(expectedWomen, new HashSet<>(solutions)); // Find all <urn:Man> types (expect 1 result) final String manQuery = "SELECT ?individual { GRAPH <http://updated/test> { ?individual rdf:type <urn:Man> } } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, manQuery).evaluate(resultHandler); final Set<BindingSet> expectedMen = new HashSet<>(); - expectedMen.add(new ListBindingSet(varNames, vf.createURI("urn:Bob"))); + expectedMen.add(new ListBindingSet(varNames, VF.createIRI("urn:Bob"))); Assert.assertEquals(expectedMen, new HashSet<>(solutions)); } @@ -540,11 +540,11 @@ public class InferenceIT extends TestCase { final String cardSuitQuery = "SELECT ?card { GRAPH <http://updated/test> { ?card a <urn:Card> . ?suit a <urn:Suits> . ?card <urn:HasSuit> ?suit} } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, cardSuitQuery).evaluate(resultHandler); final Set<BindingSet> expectedCardSuits = new HashSet<>(); - expectedCardSuits.add(new ListBindingSet(varNames, vf.createURI("urn:FlopCard1"))); - expectedCardSuits.add(new ListBindingSet(varNames, vf.createURI("urn:FlopCard2"))); - expectedCardSuits.add(new ListBindingSet(varNames, vf.createURI("urn:FlopCard3"))); - expectedCardSuits.add(new ListBindingSet(varNames, vf.createURI("urn:TurnCard"))); - expectedCardSuits.add(new ListBindingSet(varNames, vf.createURI("urn:RiverCard"))); + expectedCardSuits.add(new ListBindingSet(varNames, VF.createIRI("urn:FlopCard1"))); + expectedCardSuits.add(new ListBindingSet(varNames, VF.createIRI("urn:FlopCard2"))); + expectedCardSuits.add(new ListBindingSet(varNames, VF.createIRI("urn:FlopCard3"))); + expectedCardSuits.add(new ListBindingSet(varNames, VF.createIRI("urn:TurnCard"))); + expectedCardSuits.add(new ListBindingSet(varNames, VF.createIRI("urn:RiverCard"))); Assert.assertEquals(expectedCardSuits.size(), solutions.size()); Assert.assertEquals(expectedCardSuits, new HashSet<>(solutions)); @@ -552,11 +552,11 @@ public class InferenceIT extends TestCase { final String cardRankQuery = "SELECT ?card { GRAPH <http://updated/test> { ?card a <urn:Card> . ?rank a <urn:Ranks> . ?card <urn:HasRank> ?rank} } \n"; conn.prepareTupleQuery(QueryLanguage.SPARQL, cardRankQuery).evaluate(resultHandler); final Set<BindingSet> expectedCardRanks = new HashSet<>(); - expectedCardRanks.add(new ListBindingSet(varNames, vf.createURI("urn:FlopCard1"))); - expectedCardRanks.add(new ListBindingSet(varNames, vf.createURI("urn:FlopCard2"))); - expectedCardRanks.add(new ListBindingSet(varNames, vf.createURI("urn:FlopCard3"))); - expectedCardRanks.add(new ListBindingSet(varNames, vf.createURI("urn:TurnCard"))); - expectedCardRanks.add(new ListBindingSet(varNames, vf.createURI("urn:RiverCard"))); + expectedCardRanks.add(new ListBindingSet(varNames, VF.createIRI("urn:FlopCard1"))); + expectedCardRanks.add(new ListBindingSet(varNames, VF.createIRI("urn:FlopCard2"))); + expectedCardRanks.add(new ListBindingSet(varNames, VF.createIRI("urn:FlopCard3"))); + expectedCardRanks.add(new ListBindingSet(varNames, VF.createIRI("urn:TurnCard"))); + expectedCardRanks.add(new ListBindingSet(varNames, VF.createIRI("urn:RiverCard"))); Assert.assertEquals(expectedCardRanks.size(), solutions.size()); Assert.assertEquals(expectedCardRanks, new HashSet<>(solutions)); } @@ -580,8 +580,8 @@ public class InferenceIT extends TestCase { final List<String> varNames = new LinkedList<>(); varNames.add("who"); varNames.add("self"); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Alice"), vf.createURI("urn:Alice"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Narcissus"), vf.createURI("urn:Narcissus"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Alice"), VF.createIRI("urn:Alice"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Narcissus"), VF.createIRI("urn:Narcissus"))); Assert.assertEquals(expected, new HashSet<>(solutions)); query = "SELECT ?self { GRAPH <http://updated/test> { <urn:Alice> <urn:love> ?self } } \n"; @@ -589,7 +589,7 @@ public class InferenceIT extends TestCase { expected.clear(); varNames.clear(); varNames.add("self"); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Alice"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Alice"))); Assert.assertEquals(expected, new HashSet<>(solutions)); query = "SELECT ?who { GRAPH <http://updated/test> { ?who <urn:love> <urn:Alice> } } \n"; @@ -597,7 +597,7 @@ public class InferenceIT extends TestCase { expected.clear(); varNames.clear(); varNames.add("who"); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Alice"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Alice"))); Assert.assertEquals(expected, new HashSet<>(solutions)); query = "SELECT ?who { GRAPH <http://updated/test> { ?who a <urn:Narcissist> } } \n"; @@ -605,8 +605,8 @@ public class InferenceIT extends TestCase { expected.clear(); varNames.clear(); varNames.add("who"); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Narcissus"))); - expected.add(new ListBindingSet(varNames, vf.createURI("urn:Alice"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Narcissus"))); + expected.add(new ListBindingSet(varNames, VF.createIRI("urn:Alice"))); Assert.assertEquals(expected, new HashSet<>(solutions)); } @@ -622,10 +622,10 @@ public class InferenceIT extends TestCase { conn.prepareUpdate(QueryLanguage.SPARQL, ontology).execute(); conn.prepareUpdate(QueryLanguage.SPARQL, instances).execute(); inferenceEngine.refreshGraph(); - final URI alice = vf.createURI("urn:Alice"); - final URI bob = vf.createURI("urn:Bob"); - final URI carol = vf.createURI("urn:Carol"); - final URI eve = vf.createURI("urn:Eve"); + final IRI alice = VF.createIRI("urn:Alice"); + final IRI bob = VF.createIRI("urn:Bob"); + final IRI carol = VF.createIRI("urn:Carol"); + final IRI eve = VF.createIRI("urn:Eve"); final List<String> varNames = new LinkedList<>(); varNames.add("x"); final Set<BindingSet> aliceAndBob = new HashSet<>(); @@ -665,8 +665,8 @@ public class InferenceIT extends TestCase { // Query where subject and object are unrestricted variables: match // every known node (dangerous, but correct) - final URI hasFamily = vf.createURI("urn:hasFamilyMember"); - final URI rp = vf.createURI(OWL.NAMESPACE, "ReflexiveProperty"); + final IRI hasFamily = VF.createIRI("urn:hasFamilyMember"); + final IRI rp = VF.createIRI(OWL.NAMESPACE, "ReflexiveProperty"); final Set<BindingSet> everything = new HashSet<>(); everything.add(new ListBindingSet(varNames, alice, alice)); everything.add(new ListBindingSet(varNames, bob, bob)); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/81b99327/sail/src/test/java/org/apache/rya/rdftriplestore/inference/IntersectionOfVisitorTest.java ---------------------------------------------------------------------- diff --git a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/IntersectionOfVisitorTest.java b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/IntersectionOfVisitorTest.java index 58551a5..93585e5 100644 --- a/sail/src/test/java/org/apache/rya/rdftriplestore/inference/IntersectionOfVisitorTest.java +++ b/sail/src/test/java/org/apache/rya/rdftriplestore/inference/IntersectionOfVisitorTest.java @@ -31,19 +31,19 @@ import java.util.Map; import java.util.Set; import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.eclipse.rdf4j.model.IRI; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.query.algebra.Join; +import org.eclipse.rdf4j.query.algebra.Projection; +import org.eclipse.rdf4j.query.algebra.ProjectionElem; +import org.eclipse.rdf4j.query.algebra.ProjectionElemList; +import org.eclipse.rdf4j.query.algebra.StatementPattern; +import org.eclipse.rdf4j.query.algebra.Union; +import org.eclipse.rdf4j.query.algebra.Var; import org.junit.Test; -import org.openrdf.model.Resource; -import org.openrdf.model.URI; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.model.vocabulary.RDF; -import org.openrdf.query.algebra.Join; -import org.openrdf.query.algebra.Projection; -import org.openrdf.query.algebra.ProjectionElem; -import org.openrdf.query.algebra.ProjectionElemList; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.Union; -import org.openrdf.query.algebra.Var; import com.google.common.collect.Sets; @@ -52,22 +52,22 @@ import com.google.common.collect.Sets; */ public class IntersectionOfVisitorTest { private final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); - private static final ValueFactory VF = new ValueFactoryImpl(); + private static final ValueFactory VF = SimpleValueFactory.getInstance(); - private static final URI MOTHER = VF.createURI("urn:Mother"); - private static final URI FATHER = VF.createURI("urn:Father"); + private static final IRI MOTHER = VF.createIRI("urn:Mother"); + private static final IRI FATHER = VF.createIRI("urn:Father"); // Definition #1: :Mother owl:intersectionOf(:Animal, :Female, :Parent) - private static final URI ANIMAL = VF.createURI("urn:Animal"); - private static final URI FEMALE = VF.createURI("urn:Female"); - private static final URI PARENT = VF.createURI("urn:Parent"); + private static final IRI ANIMAL = VF.createIRI("urn:Animal"); + private static final IRI FEMALE = VF.createIRI("urn:Female"); + private static final IRI PARENT = VF.createIRI("urn:Parent"); // Definition #2: :Mother owl:intersectionOf(:Female, :Leader, :Nun) - private static final URI NUN = VF.createURI("urn:Nun"); - private static final URI LEADER = VF.createURI("urn:Leader"); + private static final IRI NUN = VF.createIRI("urn:Nun"); + private static final IRI LEADER = VF.createIRI("urn:Leader"); // Definition #3: :Father owl:intersectionOf(:Man, :Parent) - private static final URI MAN = VF.createURI("urn:Man"); + private static final IRI MAN = VF.createIRI("urn:Man"); @Test public void testIntersectionOf() throws Exception { @@ -226,7 +226,7 @@ public class IntersectionOfVisitorTest { assertEquals(expectedFatherSp, actualFatherSp); } - private static void assertStatementPattern(final StatementPattern statementPattern, final URI uri) { + private static void assertStatementPattern(final StatementPattern statementPattern, final IRI uri) { assertNotNull(statementPattern.getPredicateVar()); assertEquals(RDF.TYPE, statementPattern.getPredicateVar().getValue()); assertNotNull(statementPattern.getObjectVar());