Added example for StatementMetadata
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/aa65d6a9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/aa65d6a9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/aa65d6a9 Branch: refs/heads/master Commit: aa65d6a92c45ffdd8758525f1643e0e25e6909c6 Parents: 11349b1 Author: Caleb Meier <[email protected]> Authored: Thu Feb 23 12:26:52 2017 -0800 Committer: pujav65 <[email protected]> Committed: Mon Mar 13 10:00:28 2017 -0400 ---------------------------------------------------------------------- .../accumulo/query/AccumuloRyaQueryEngine.java | 8 +- .../apache/rya/mongodb/MongoDBQueryEngine.java | 2 +- .../statement/metadata/matching/OWLReify.java | 49 +++ .../StatementMetadataExternalSetProvider.java | 4 +- .../matching/StatementMetadataNode.java | 410 +++++++++++-------- .../AccumuloStatementMetadataNodeTest.java | 266 +++++++++++- .../AccumuloStatementMetadataOptimizerIT.java | 37 +- .../metadata/MongoStatementMetadataIT.java | 22 +- .../MongoStatementMetadataNodeTest.java | 8 +- ...tatementMetadataExternalSetProviderTest.java | 16 +- .../StatementMetadataOptimizerTest.java | 42 +- .../metadata/StatementMetadataTestUtils.java | 5 +- .../src/main/java/StatementMetadataExample.java | 271 ++++++++++++ 13 files changed, 884 insertions(+), 256 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java index 7626f29..b9e53cf 100644 --- a/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java +++ b/dao/accumulo.rya/src/main/java/org/apache/rya/accumulo/query/AccumuloRyaQueryEngine.java @@ -133,9 +133,15 @@ public class AccumuloRyaQueryEngine implements RyaQueryEngine<AccumuloRdfConfigu TABLE_LAYOUT layout = null; RyaURI context = null; TriplePatternStrategy strategy = null; + boolean contextSet = false; for (Map.Entry<RyaStatement, BindingSet> stmtbs : stmts) { RyaStatement stmt = stmtbs.getKey(); - context = stmt.getContext(); //TODO: This will be overwritten + if(!contextSet) { + context = stmt.getContext(); + contextSet = true; + } else if(context != null && !context.equals(stmt.getContext())) { + context = null; + } BindingSet bs = stmtbs.getValue(); strategy = ryaContext.retrieveStrategy(stmt); if (strategy == null) { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBQueryEngine.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBQueryEngine.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBQueryEngine.java index a57825a..ce2ac6b 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBQueryEngine.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/MongoDBQueryEngine.java @@ -197,6 +197,6 @@ public class MongoDBQueryEngine implements RyaQueryEngine<MongoDBRdfConfiguratio @Override public void close() throws IOException { - if (mongoClient != null){ mongoClient.close(); } +// if (mongoClient != null){ mongoClient.close(); } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/OWLReify.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/OWLReify.java b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/OWLReify.java new file mode 100644 index 0000000..640f358 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/OWLReify.java @@ -0,0 +1,49 @@ +package org.apache.rya.indexing.statement.metadata.matching; +/* + * 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 org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; +import org.openrdf.model.vocabulary.OWL; + +public class OWLReify { + + /** http://www.w3.org/2002/07/owl#Annotation*/ + public final static URI ANNOTATION; + + /** http://www.w3.org/2002/07/owl#annotatedSource*/ + public static final URI SOURCE; + + /** http://www.w3.org/2002/07/owl#annotatedProperty*/ + public static final URI PROPERTY; + + /** http://www.w3.org/2002/07/owl#annotatedTarget*/ + public static final URI TARGET; + + static { + ValueFactory factory = ValueFactoryImpl.getInstance(); + ANNOTATION = factory.createURI(OWL.NAMESPACE, "Annotation"); + PROPERTY = factory.createURI(OWL.NAMESPACE, "annotatedProperty"); + SOURCE = factory.createURI(OWL.NAMESPACE, "annotatedSource"); + TARGET = factory.createURI(OWL.NAMESPACE, "annotatedTarget"); + } +} + + + http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataExternalSetProvider.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataExternalSetProvider.java b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataExternalSetProvider.java index f430b1b..bfa0dfa 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataExternalSetProvider.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataExternalSetProvider.java @@ -45,8 +45,8 @@ import com.google.common.collect.Multimap; */ public class StatementMetadataExternalSetProvider implements ExternalSetProvider<StatementMetadataNode<?>> { - private List<RyaURI> expectedURI = Arrays.asList(RdfToRyaConversions.convertURI(RDF.SUBJECT), - RdfToRyaConversions.convertURI(RDF.PREDICATE), RdfToRyaConversions.convertURI(RDF.OBJECT), + private List<RyaURI> expectedURI = Arrays.asList(RdfToRyaConversions.convertURI(OWLReify.SOURCE), + RdfToRyaConversions.convertURI(OWLReify.PROPERTY), RdfToRyaConversions.convertURI(OWLReify.TARGET), RdfToRyaConversions.convertURI(RDF.TYPE)); private Multimap<Var, StatementPattern> reifiedQueries; private Set<RyaURI> metadataProperties; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java index 85b048e..363dba2 100644 --- a/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java +++ b/extras/indexing/src/main/java/org/apache/rya/indexing/statement/metadata/matching/StatementMetadataNode.java @@ -1,4 +1,5 @@ package org.apache.rya.indexing.statement.metadata.matching; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -60,38 +61,54 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import info.aduna.iteration.CloseableIteration; +import info.aduna.iteration.EmptyIteration; /** - * This class provides users with the ability to issue reified queries to Rya. As opposed to a single triple - * representing a statement, a reified query consists of a number of triples that all describe the same - * statement. For example, instead of having the single statement (http://Bob, http://worksAt,http://CoffeeShop), - * the reified statement representing this triple would be the collection of triples: {(_blankNode, RDF.TYPE, RDF.STATEMENT), - * (_blankNode, RDF.SUBJECT, http://Bob), (_blankNode, RDF.PREDICATE, http://worksAt), (_blankNode, RDF.OBJECT, http://CoffeeShop)}. - * The advantage of expanding the statement into a collection of triples in this way is that additional assertions can be made about the - * statement. For example, we could use the triple (_blankNode, <http://createdOn>, <http://date#1/2/17>) to indicate that the statement - * was created on 1/2/17. The drawback of reification is that is it inefficient. It takes four triples to specify what was originally - * specified with one triple. So reificiation is expensive from a storage perspective. It is also expensive from a query perspective in - * that three joins are required to evaluate a query that is reduced to a single scan in non-reified form. + * This class provides users with the ability to issue reified queries to Rya. + * As opposed to a single triple representing a statement, a reified query + * consists of a number of triples that all describe the same statement. For + * example, instead of having the single statement (http://Bob, + * http://worksAt,http://CoffeeShop), the reified statement representing this + * triple would be the collection of triples: {(_blankNode, RDF.TYPE, + * OWLReify.ANNOTATION), (_blankNode, OWLReify.SOURCE, http://Bob), (_blankNode, + * OWLReify.PROPERTY, http://worksAt), (_blankNode, OWLReify.TARGET, http://CoffeeShop)}. + * The advantage of expanding the statement into a collection of triples in this + * way is that additional assertions can be made about the statement. For + * example, we could use the triple (_blankNode, <http://createdOn>, + * <http://date#1/2/17>) to indicate that the statement was created on 1/2/17. + * The drawback of reification is that is it inefficient. It takes four triples + * to specify what was originally specified with one triple. So reificiation is + * expensive from a storage perspective. It is also expensive from a query + * perspective in that three joins are required to evaluate a query that is + * reduced to a single scan in non-reified form. * - * This class provides Rya with the ability to issue reified queries even though statements are not reified. Each {@link RyaStatement} - * contains a {@link StatementMetadata} field that allows users to store additional metadata about a given statement. When a user - * issues a reified query (possibly containing StatementPatterns about metadata for that statement), the {@link StatementPattern}s for - * that parsed query are used to create this class. Upon construction, the StatementMetadataNode validates that the - * collection of StatementPatterns represents a reified query, and then evaluates the reified query using a single scan over a range - * determined by the subject, predicate, and object portions of the reified query. If additional metadata properties are specified in - * the reified query, the results of the initial scan are filtered client side by comparing the user specified properties with the - * StatementMetadata extracted from each of the results. This class allows users to issue queries about RyaStatements and any contextual - * properties without the inefficiencies associated with reification. + * This class provides Rya with the ability to issue reified queries even though + * statements are not reified. Each {@link RyaStatement} contains a + * {@link StatementMetadata} field that allows users to store additional + * metadata about a given statement. When a user issues a reified query + * (possibly containing StatementPatterns about metadata for that statement), + * the {@link StatementPattern}s for that parsed query are used to create this + * class. Upon construction, the StatementMetadataNode validates that the + * collection of StatementPatterns represents a reified query, and then + * evaluates the reified query using a single scan over a range determined by + * the subject, predicate, and object portions of the reified query. If + * additional metadata properties are specified in the reified query, the + * results of the initial scan are filtered client side by comparing the user + * specified properties with the StatementMetadata extracted from each of the + * results. This class allows users to issue queries about RyaStatements and any + * contextual properties without the inefficiencies associated with reification. * - * @param <C> - Configuration object + * @param <C> + * - Configuration object */ -public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> extends ExternalSet implements ExternalBatchingIterator { +public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> extends ExternalSet + implements ExternalBatchingIterator { private static final RyaURI TYPE_ID_URI = new RyaURI(RDF.TYPE.toString()); - private static final RyaURI SUBJ_ID_URI = new RyaURI(RDF.SUBJECT.toString()); - private static final RyaURI PRED_ID_URI = new RyaURI(RDF.PREDICATE.toString()); - private static final RyaURI OBJ_ID_URI = new RyaURI(RDF.OBJECT.toString()); - private static final RyaURI STATEMENT_ID_URI = new RyaURI(RDF.STATEMENT.toString()); + private static final RyaURI SUBJ_ID_URI = new RyaURI(OWLReify.SOURCE.toString()); + private static final RyaURI PRED_ID_URI = new RyaURI(OWLReify.PROPERTY.toString()); + private static final RyaURI OBJ_ID_URI = new RyaURI(OWLReify.TARGET.toString()); + private static final RyaURI STATEMENT_ID_URI = new RyaURI(OWLReify.ANNOTATION.toString()); private StatementPattern statement; private Map<RyaURI, Var> properties; @@ -107,12 +124,12 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e verifySameSubjects(patterns); verifyAllPredicatesAreConstants(patterns); boolean correctForm = verifyHasCorrectTypePattern(patterns); - if(!correctForm) { + if (!correctForm) { throw new IllegalArgumentException("Invalid reified StatementPatterns."); } setStatementPatternAndProperties(patterns); } - + /** * Get {@link StatementPattern}s representing the underlying reified query. * @@ -185,46 +202,57 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e boolean predFound = false; boolean statementFound = false; boolean valid = true; - + boolean contextSet = false; + Var context = null; + for (final StatementPattern pattern : patterns) { final RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString()); + if (!contextSet) { + context = pattern.getContextVar(); + contextSet = true; + } else { + if(context != null && !context.equals(pattern.getContextVar())) { + return false; + } + } + if (predicate.equals(TYPE_ID_URI)) { final RyaURI statementID = new RyaURI(pattern.getObjectVar().getValue().stringValue()); if (statementID.equals(STATEMENT_ID_URI)) { statementFound = true; } else { - //contains more than one Statement containing TYPE_ID_URI as Predicate - //and STATEMENT_ID_URI as Object - valid = false; + // contains more than one Statement containing TYPE_ID_URI + // as Predicate + // and STATEMENT_ID_URI as Object + valid = false; } } if (predicate.equals(SUBJ_ID_URI)) { - if(!subjFound) { + if (!subjFound) { subjFound = true; } else { - //contains more than Subject SP + // contains more than Subject SP valid = false; } - - + } if (predicate.equals(PRED_ID_URI)) { - if(!predFound) { + if (!predFound) { predFound = true; } else { - //contains more than one Predicate SP + // contains more than one Predicate SP valid = false; } } if (predicate.equals(OBJ_ID_URI)) { - if(!objFound) { + if (!objFound) { objFound = true; } else { - //contains more than one Object SP + // contains more than one Object SP valid = false; } } @@ -232,33 +260,40 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e return valid && statementFound && subjFound && predFound && objFound; } - + /** - * Constructs a {@link StatementPattern} from the StatementPatterns representing a reified query. - * This StatementPattern has as a subject, the object of the StatementPattern containing the predicate - * {@link RDF#SUBJECT}. This StatementPattern has as predicate, the object of the StatementPattern containing the predicate - * {@link RDF#PREDICATE}. This StatementPattern has as an object, the object of the StatementPattern containing the predicate - * {@link RDF#OBJECT}. This method also builds a map between all predicates that are not of the above type and the object {@link Var}s - * they are associated with. This map contains the user specified metadata properties and is used for comparison with the - * metadata properties extracted from RyaStatements passed back by the {@link RyaQueryEngine}. + * Constructs a {@link StatementPattern} from the StatementPatterns + * representing a reified query. This StatementPattern has as a subject, the + * object of the StatementPattern containing the predicate + * {@link RDF#SUBJECT}. This StatementPattern has as predicate, the object + * of the StatementPattern containing the predicate {@link RDF#PREDICATE}. + * This StatementPattern has as an object, the object of the + * StatementPattern containing the predicate {@link RDF#OBJECT}. This method + * also builds a map between all predicates that are not of the above type + * and the object {@link Var}s they are associated with. This map contains + * the user specified metadata properties and is used for comparison with + * the metadata properties extracted from RyaStatements passed back by the + * {@link RyaQueryEngine}. * - * @param patterns - collection of patterns representing a reified query + * @param patterns + * - collection of patterns representing a reified query */ - private void setStatementPatternAndProperties(Collection<StatementPattern> patterns){ - + private void setStatementPatternAndProperties(Collection<StatementPattern> patterns) { + StatementPattern sp = new StatementPattern(); Map<RyaURI, Var> properties = new HashMap<>(); - + for (final StatementPattern pattern : patterns) { final RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString()); - if(!uriList.contains(predicate)) { + if (!uriList.contains(predicate)) { Var objVar = pattern.getObjectVar(); properties.put(predicate, objVar); continue; - } - + } + if (predicate.equals(SUBJ_ID_URI)) { + sp.setContextVar(pattern.getContextVar()); sp.setSubjectVar(pattern.getObjectVar()); } @@ -267,7 +302,7 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e } if (predicate.equals(OBJ_ID_URI)) { - sp.setObjectVar(pattern.getObjectVar()); + sp.setObjectVar(pattern.getObjectVar()); } } this.statement = sp; @@ -275,80 +310,93 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e } /** - * This method pairs each {@link BindingSet} in the specified collection with the StatementPattern constraints - * and issues a query to Rya using the {@link RyaQueryEngine}. + * This method pairs each {@link BindingSet} in the specified collection + * with the StatementPattern constraints and issues a query to Rya using the + * {@link RyaQueryEngine}. */ @Override public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Collection<BindingSet> bindingset) throws QueryEvaluationException { + if (bindingset.size() == 0) { + return new EmptyIteration<>(); + } + queryEngine = RyaQueryEngineFactory.getQueryEngine(conf); Set<Map.Entry<RyaStatement, BindingSet>> statements = new HashSet<>(); Iterator<BindingSet> iter = bindingset.iterator(); - while(iter.hasNext()) { + while (iter.hasNext()) { BindingSet bs = iter.next(); - statements.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>(getRyaStatementFromBindings(bs), bs)); + statements.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>( + getRyaStatementFromBindings(bs), bs)); } - + final CloseableIteration<? extends Entry<RyaStatement, BindingSet>, RyaDAOException> iteration; try { iteration = queryEngine.queryWithBindingSet(statements, conf); } catch (RyaDAOException e) { throw new RuntimeException(e); } - - return new PropertyFilterAndBindingSetJoinIteration(iteration, properties, statement); + + return new PropertyFilterAndBindingSetJoinIteration(iteration, properties, statement); } - + /** - * Uses StatementPattern constraints to form a RyaStatement, and fills in any null values with - * {@link BindingSet} values corresponding to the variable for that position. + * Uses StatementPattern constraints to form a RyaStatement, and fills in + * any null values with {@link BindingSet} values corresponding to the + * variable for that position. * * @param bs - * @return RyaStatement whose values are determined by StatementPattern and BindingSet constraints + * @return RyaStatement whose values are determined by StatementPattern and + * BindingSet constraints */ private RyaStatement getRyaStatementFromBindings(BindingSet bs) { - - Value subjValue = getVarValue(statement.getSubjectVar(),bs); - Value predValue = getVarValue(statement.getPredicateVar(),bs); - Value objValue = getVarValue(statement.getObjectVar(),bs); + + Value subjValue = getVarValue(statement.getSubjectVar(), bs); + Value predValue = getVarValue(statement.getPredicateVar(), bs); + Value objValue = getVarValue(statement.getObjectVar(), bs); + Value contextValue = getVarValue(statement.getContextVar(), bs); RyaURI subj = null; RyaURI pred = null; RyaType obj = null; - - - if(subjValue != null) { + RyaURI context = null; + + if (subjValue != null) { Preconditions.checkArgument(subjValue instanceof URI); subj = RdfToRyaConversions.convertURI((URI) subjValue); } - - if(predValue != null) { + + if (predValue != null) { Preconditions.checkArgument(predValue instanceof URI); pred = RdfToRyaConversions.convertURI((URI) predValue); } - - if(objValue != null) { + + if (objValue != null) { obj = RdfToRyaConversions.convertValue(objValue); } - return new RyaStatement(subj, pred, obj); + + if(contextValue != null) { + context = RdfToRyaConversions.convertURI((URI) contextValue); + } + return new RyaStatement(subj, pred, obj, context); } - + /** - * Assigns BindingSet values for any {@link Var} whose {@link Value} is null. - * Returns the {@link Value} associated with Var (if it has one), otherwise returns the BindingSet Value - * corresponding to {@link Var#getName()}. If no such Binding exits, this method returns null. + * Assigns BindingSet values for any {@link Var} whose {@link Value} is + * null. Returns the {@link Value} associated with Var (if it has one), + * otherwise returns the BindingSet Value corresponding to + * {@link Var#getName()}. If no such Binding exits, this method returns + * null. * * @param var * @param bindings - * @return Value + * @return Value */ private Value getVarValue(Var var, BindingSet bindings) { if (var == null) { return null; - } - else if (var.hasValue()) { + } else if (var.hasValue()) { return var.getValue(); - } - else { + } else { return bindings.getValue(var.getName()); } } @@ -358,25 +406,24 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e throws QueryEvaluationException { return evaluate(Collections.singleton(bindings)); } - - + @Override public boolean equals(Object other) { - - if(this == other ) { + + if (this == other) { return true; } - - if(other instanceof StatementMetadataNode) { + + if (other instanceof StatementMetadataNode) { StatementMetadataNode<?> meta = (StatementMetadataNode<?>) other; - if(meta.patterns.size() != this.patterns.size()) { + if (meta.patterns.size() != this.patterns.size()) { return false; } - - if(this.patterns.size() != meta.patterns.size()) { + + if (this.patterns.size() != meta.patterns.size()) { return false; } - + Set<StatementPattern> thisSet = new HashSet<>(patterns); Set<StatementPattern> thatSet = new HashSet<>(meta.patterns); return thisSet.equals(thatSet); @@ -384,62 +431,66 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e return false; } } - + @Override public int hashCode() { int hashcode = 0; - for(StatementPattern sp: patterns) { + for (StatementPattern sp : patterns) { hashcode += sp.hashCode(); } return hashcode; } - + @Override public Set<String> getBindingNames() { - if(bindingNames == null) { + if (bindingNames == null) { bindingNames = getVariableNames(); - } + } return bindingNames; } - + @Override public Set<String> getAssuredBindingNames() { return getBindingNames(); } - + @Override public String getSignature() { return "StatementMetadataNode(" + Joiner.on(",").join(getBindingNames()) + ")"; } - + @Override public String toString() { return getSignature(); } - + private Set<String> getVariableNames() { Set<String> vars = new HashSet<>(); - for(StatementPattern pattern : patterns) { - for(Var var: pattern.getVarList()) { - if(var.getValue() == null) { + for (StatementPattern pattern : patterns) { + for (Var var : pattern.getVarList()) { + if (var.getValue() == null) { vars.add(var.getName()); } } } return vars; } - - + /** - * This is an {@link CloseableIteration} class that serves a number of purposes. It's primary purpose is to - * filter a CloseableIteration over {@link Map.Entry<RyaStatement,BindingSet>} using a specified property Map - * from {@link RyaURI} to {@link org.openrdf.query.algebra.Var}. This Iteration iterates over the Entries in the user specified Iteration, - * comparing properties in the {@link StatementMetadata} Map contained in the RyaStatements with the property Map for this class. - * If the properties match, a {@BindingSet} is formed from the RyaStatement/Properties and joined (if possible) with the - * BindingSet taken from the Map.Entry. If the RyaStatement/Property BindingSet cannot be formed or joined the the Entry BindingSet, - * the Entry in the user specified Iteration is filtered out. So this class converts Iterations, filters according to the - * specified property Map, and joins the BindingSet formed from the RyaStatements/Properties with the Entry BindingSet. -}. + * This is an {@link CloseableIteration} class that serves a number of + * purposes. It's primary purpose is to filter a CloseableIteration over + * {@link Map.Entry<RyaStatement,BindingSet>} using a specified property Map + * from {@link RyaURI} to {@link org.openrdf.query.algebra.Var}. This + * Iteration iterates over the Entries in the user specified Iteration, + * comparing properties in the {@link StatementMetadata} Map contained in + * the RyaStatements with the property Map for this class. If the properties + * match, a {@BindingSet} is formed from the RyaStatement/Properties and + * joined (if possible) with the BindingSet taken from the Map.Entry. If the + * RyaStatement/Property BindingSet cannot be formed or joined the the Entry + * BindingSet, the Entry in the user specified Iteration is filtered out. So + * this class converts Iterations, filters according to the specified + * property Map, and joins the BindingSet formed from the + * RyaStatements/Properties with the Entry BindingSet. }. * */ class PropertyFilterAndBindingSetJoinIteration implements CloseableIteration<BindingSet, QueryEvaluationException> { @@ -450,14 +501,15 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e private BindingSet next; private boolean hasNextCalled = false; private boolean hasNext = false; - - public PropertyFilterAndBindingSetJoinIteration(CloseableIteration<? extends Entry<RyaStatement, BindingSet>, - RyaDAOException> statements, Map<RyaURI, Var> properties, StatementPattern sp) { + + public PropertyFilterAndBindingSetJoinIteration( + CloseableIteration<? extends Entry<RyaStatement, BindingSet>, RyaDAOException> statements, + Map<RyaURI, Var> properties, StatementPattern sp) { this.statements = statements; this.properties = properties; this.sp = sp; } - + @Override public boolean hasNext() throws QueryEvaluationException { if (!hasNextCalled) { @@ -470,7 +522,7 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e next = bs.get(); hasNext = true; } - if(!hasNext) { + if (!hasNext) { queryEngine.close(); } return hasNext; @@ -484,16 +536,16 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e @Override public BindingSet next() throws QueryEvaluationException { - - if(hasNextCalled) { - if(!hasNext) { + + if (hasNextCalled) { + if (!hasNext) { throw new NoSuchElementException(); } hasNextCalled = false; return next; } else { hasNext(); - if(!hasNext) { + if (!hasNext) { throw new NoSuchElementException(); } hasNextCalled = false; @@ -510,63 +562,69 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e public void close() throws QueryEvaluationException { try { statements.close(); - } catch ( RyaDAOException e) { + } catch (RyaDAOException e) { throw new QueryEvaluationException(e); } } - + /** - * Fast-forwards Iteration to next valid Entry and builds the BindingSet. + * Fast-forwards Iteration to next valid Entry and builds the + * BindingSet. * - * @return BindingSet + * @return BindingSet * @throws RyaDAOException */ private Optional<BindingSet> getNext() throws RyaDAOException { Optional<BindingSet> optionalBs = Optional.empty(); - while(statements.hasNext() && !optionalBs.isPresent()) { + while (statements.hasNext() && !optionalBs.isPresent()) { Map.Entry<RyaStatement, BindingSet> next = statements.next(); optionalBs = buildBindingSet(next.getKey(), next.getValue()); } return optionalBs; } - + /** - * Builds BindingSet from Entry if possible. Otherwise returns an empty Optional if no - * valid BindingSet can be built. Valid BindingSet can be built if this class's - * property Map is consistent with {@link StatementMetadata} properties for the specified - * RyaStatement and if the BindingSet built form the StatementMetadata properties can be - * joined with specified BindingSet. + * Builds BindingSet from Entry if possible. Otherwise returns an empty + * Optional if no valid BindingSet can be built. Valid BindingSet can be + * built if this class's property Map is consistent with + * {@link StatementMetadata} properties for the specified RyaStatement + * and if the BindingSet built form the StatementMetadata properties can + * be joined with specified BindingSet. * - * @param statement - RyaStatement - * @param bindingSet - BindingSet - * @return - Optional containing BindingSet is a valid BindingSet could be built + * @param statement + * - RyaStatement + * @param bindingSet + * - BindingSet + * @return - Optional containing BindingSet is a valid BindingSet could + * be built */ private Optional<BindingSet> buildBindingSet(RyaStatement statement, BindingSet bindingSet) { - + QueryBindingSet bs = new QueryBindingSet(); Optional<BindingSet> optPropBs = buildPropertyBindingSet(statement); - if(!optPropBs.isPresent()) { + if (!optPropBs.isPresent()) { return Optional.empty(); } BindingSet propBs = optPropBs.get(); BindingSet spBs = buildBindingSetFromStatementPattern(statement); - if(!canJoinBindingSets(spBs, propBs)) { + if (!canJoinBindingSets(spBs, propBs)) { return Optional.empty(); } bs.addAll(spBs); bs.addAll(propBs); - if(!canJoinBindingSets(bs, bindingSet)) { + if (!canJoinBindingSets(bs, bindingSet)) { return Optional.empty(); } bs.addAll(bindingSet); return Optional.of(bs); - + } - + /** - * Verifies whether this class's property Map is consistent with StatementMetadata properties - * for specified RyaStatement. If consistent, this method builds the associated BindingSet otherwise - * an empty Optional is returned. + * Verifies whether this class's property Map is consistent with + * StatementMetadata properties for specified RyaStatement. If + * consistent, this method builds the associated BindingSet otherwise an + * empty Optional is returned. * * @param statement * @return @@ -574,29 +632,35 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e private Optional<BindingSet> buildPropertyBindingSet(RyaStatement statement) { StatementMetadata metadata = statement.getMetadata(); Map<RyaURI, RyaType> statementProps = metadata.getMetadata(); + if (statementProps.size() < properties.size()) { + return Optional.empty(); + } QueryBindingSet bs = new QueryBindingSet(); - for(Map.Entry<RyaURI, Var> entry : properties.entrySet()) { + for (Map.Entry<RyaURI, Var> entry : properties.entrySet()) { RyaURI key = entry.getKey(); Var var = entry.getValue(); - if(!statementProps.containsKey(key)) { + if (!statementProps.containsKey(key)) { return Optional.empty(); } else { Value val = RyaToRdfConversions.convertValue(statementProps.get(key)); - if(var.getValue() == null) { + if (var.getValue() == null) { bs.addBinding(var.getName(), val); - } else if (!var.getValue().equals(val)){ + } else if (!var.getValue().equals(val)) { return Optional.empty(); } } } return Optional.of(bs); } - + /** - * Builds the BindingSet from the specified RyaStatement by using the StatementPattern - * for this class. This method checks whether StatementPattern has a {@link Value} for each - * position {@link org.openrdf.query.algebra.Var} (Subject, Predicate, Object). If it doesn't have a Value, a Binding is created - * from the RyaStatement using the {@link RyaType} for the corresponding position (Subject, Predicate, Object). + * Builds the BindingSet from the specified RyaStatement by using the + * StatementPattern for this class. This method checks whether + * StatementPattern has a {@link Value} for each position + * {@link org.openrdf.query.algebra.Var} (Subject, Predicate, Object). + * If it doesn't have a Value, a Binding is created from the + * RyaStatement using the {@link RyaType} for the corresponding position + * (Subject, Predicate, Object). * * @param statement * @return BindingSet @@ -605,34 +669,38 @@ public class StatementMetadataNode<C extends RdfCloudTripleStoreConfiguration> e Var subjVar = sp.getSubjectVar(); Var predVar = sp.getPredicateVar(); Var objVar = sp.getObjectVar(); + Var contextVar = sp.getContextVar(); QueryBindingSet bs = new QueryBindingSet(); - - if(subjVar.getValue() == null) { + + if (subjVar.getValue() == null) { bs.addBinding(subjVar.getName(), RyaToRdfConversions.convertValue(statement.getSubject())); } - - if(predVar.getValue() == null ) { + + if (predVar.getValue() == null) { bs.addBinding(predVar.getName(), RyaToRdfConversions.convertValue(statement.getPredicate())); } - - if(objVar.getValue() == null) { + + if (objVar.getValue() == null) { bs.addBinding(objVar.getName(), RyaToRdfConversions.convertValue(statement.getObject())); } + if (contextVar != null && contextVar.getValue() == null) { + bs.addBinding(contextVar.getName(), RyaToRdfConversions.convertValue(statement.getContext())); + } + return bs; } - + private boolean canJoinBindingSets(BindingSet bs1, BindingSet bs2) { - for(Binding b: bs1) { + for (Binding b : bs1) { String name = b.getName(); Value val = b.getValue(); - if(bs2.hasBinding(name) && (!bs2.getValue(name).equals(val))) { + if (bs2.hasBinding(name) && (!bs2.getValue(name).equals(val))) { return false; } } return true; } } - } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataNodeTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataNodeTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataNodeTest.java index fc6bdb2..a2cc08d 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataNodeTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataNodeTest.java @@ -19,12 +19,17 @@ package org.apache.rya.indexing.statement.metadata; * under the License. */ import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Map; import org.apache.accumulo.core.client.Connector; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; +import org.apache.rya.accumulo.query.AccumuloRyaQueryEngine; import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.RdfCloudTripleStoreUtils; import org.apache.rya.api.domain.RyaStatement; import org.apache.rya.api.domain.RyaType; import org.apache.rya.api.domain.RyaURI; @@ -54,10 +59,10 @@ public class AccumuloStatementMetadataNodeTest { private AccumuloRyaDAO dao; private AccumuloRdfConfiguration conf; - private final String query = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; - private final String query2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject ?x; " - + "rdf:predicate <http://worksAt>; rdf:object ?y; <http://createdBy> ?x; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query2 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; owl:annotatedSource ?x; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?y; <http://createdBy> ?x; <http://createdOn> \'2017-01-04\'^^xsd:date }"; @Before public void init() throws Exception { @@ -362,6 +367,259 @@ public class AccumuloStatementMetadataNodeTest { dao.delete(statement2, conf); } + /** + * Tests if StatementMetadataNode joins BindingSet values correctly for + * variables appearing as the object in one of the StatementPattern + * statements (in the case ?x appears as the Object in the statement + * _:blankNode rdf:object ?x). StatementPattern statements have either + * rdf:subject, rdf:predicate, or rdf:object as the predicate. Additionally, + * this test also determines whether node uses specified context as a query + * constraint. + * + * @throws MalformedQueryException + * @throws QueryEvaluationException + * @throws RyaDAOException + */ + @Test + public void simpleQueryWithConstantContext() + throws MalformedQueryException, QueryEvaluationException, RyaDAOException { + + // query used to create StatementPatternMetadataNode + String contextQuery = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where { graph <http://context_1> {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }}"; + + StatementMetadata metadata = new StatementMetadata(); + metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe")); + metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04")); + + RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), + new RyaType("CoffeeShop"), new RyaURI("http://context_1"), "", metadata); + RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), + new RyaType("HardwareStore"), new RyaURI("http://context_2"), "", metadata); + dao.add(statement1); + dao.add(statement2); + + SPARQLParser parser = new SPARQLParser(); + ParsedQuery pq = parser.parseQuery(contextQuery, null); + List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr()); + StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf); + + List<BindingSet> bsCollection = new ArrayList<>(); + QueryBindingSet bsConstraint1 = new QueryBindingSet(); + bsConstraint1.addBinding("x", new LiteralImpl("CoffeeShop")); + bsConstraint1.addBinding("z", new LiteralImpl("Virginia")); + + QueryBindingSet bsConstraint2 = new QueryBindingSet(); + bsConstraint2.addBinding("x", new LiteralImpl("HardwareStore")); + bsConstraint2.addBinding("z", new LiteralImpl("Maryland")); + + QueryBindingSet bsConstraint3 = new QueryBindingSet(); + bsConstraint3.addBinding("x", new LiteralImpl("BurgerShack")); + bsConstraint3.addBinding("z", new LiteralImpl("Delaware")); + bsCollection.add(bsConstraint1); + bsCollection.add(bsConstraint2); + bsCollection.add(bsConstraint3); + + CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection); + + QueryBindingSet expected1 = new QueryBindingSet(); + expected1.addBinding("x", new LiteralImpl("CoffeeShop")); + expected1.addBinding("y", new LiteralImpl("Joe")); + expected1.addBinding("z", new LiteralImpl("Virginia")); + + List<BindingSet> bsList = new ArrayList<>(); + while (iteration.hasNext()) { + bsList.add(iteration.next()); + } + + Assert.assertEquals(1, bsList.size()); + Assert.assertEquals(expected1, bsList.get(0)); + + dao.delete(statement1, conf); + dao.delete(statement2, conf); + } + + /** + * Tests if StatementMetadataNode joins BindingSet values correctly for + * variables appearing as the object in one of the StatementPattern + * statements (in the case ?x appears as the Object in the statement + * _:blankNode rdf:object ?x). StatementPattern statements have either + * rdf:subject, rdf:predicate, or rdf:object as the predicate. Additionally, + * this test also determines whether node passes back bindings corresponding + * to a specified context. + * + * @throws MalformedQueryException + * @throws QueryEvaluationException + * @throws RyaDAOException + */ + @Test + public void simpleQueryWithVariableContext() + throws MalformedQueryException, QueryEvaluationException, RyaDAOException { + + // query used to create StatementPatternMetadataNode + String contextQuery = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y ?c where { graph ?c {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }}"; + + StatementMetadata metadata = new StatementMetadata(); + metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe")); + metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04")); + + RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), + new RyaType("CoffeeShop"), new RyaURI("http://context_1"), "", metadata); + RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), + new RyaType("HardwareStore"), new RyaURI("http://context_2"), "", metadata); + dao.add(statement1); + dao.add(statement2); + + SPARQLParser parser = new SPARQLParser(); + ParsedQuery pq = parser.parseQuery(contextQuery, null); + List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr()); + StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf); + + List<BindingSet> bsCollection = new ArrayList<>(); + QueryBindingSet bsConstraint1 = new QueryBindingSet(); + bsConstraint1.addBinding("x", new LiteralImpl("CoffeeShop")); + bsConstraint1.addBinding("z", new LiteralImpl("Virginia")); + + QueryBindingSet bsConstraint2 = new QueryBindingSet(); + bsConstraint2.addBinding("x", new LiteralImpl("HardwareStore")); + bsConstraint2.addBinding("z", new LiteralImpl("Maryland")); + + QueryBindingSet bsConstraint3 = new QueryBindingSet(); + bsConstraint3.addBinding("x", new LiteralImpl("BurgerShack")); + bsConstraint3.addBinding("z", new LiteralImpl("Delaware")); + bsCollection.add(bsConstraint1); + bsCollection.add(bsConstraint2); + bsCollection.add(bsConstraint3); + + CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection); + + QueryBindingSet expected1 = new QueryBindingSet(); + expected1.addBinding("x", new LiteralImpl("CoffeeShop")); + expected1.addBinding("y", new LiteralImpl("Joe")); + expected1.addBinding("z", new LiteralImpl("Virginia")); + expected1.addBinding("c", new URIImpl("http://context_1")); + + QueryBindingSet expected2 = new QueryBindingSet(); + expected2.addBinding("x", new LiteralImpl("HardwareStore")); + expected2.addBinding("y", new LiteralImpl("Joe")); + expected2.addBinding("z", new LiteralImpl("Maryland")); + expected2.addBinding("c", new URIImpl("http://context_2")); + + List<BindingSet> bsList = new ArrayList<>(); + while (iteration.hasNext()) { + bsList.add(iteration.next()); + } + + Assert.assertEquals(2, bsList.size()); + Assert.assertEquals(expected1, bsList.get(1)); + Assert.assertEquals(expected2, bsList.get(0)); + + dao.delete(statement1, conf); + dao.delete(statement2, conf); + } + + /** + * Tests if StatementMetadataNode joins BindingSet values correctly for + * variables appearing as the object in one of the StatementPattern + * statements (in the case ?x appears as the Object in the statement + * _:blankNode rdf:object ?x). StatementPattern statements have either + * rdf:subject, rdf:predicate, or rdf:object as the predicate. Additionally, + * this test also determines whether node passes back bindings corresponding + * to a specified context and that a join across variable context is + * performed properly. + * + * @throws MalformedQueryException + * @throws QueryEvaluationException + * @throws RyaDAOException + */ + @Test + public void simpleQueryWithVariableContextAndJoinOnContext() + throws MalformedQueryException, QueryEvaluationException, RyaDAOException { + + // query used to create StatementPatternMetadataNode + String contextQuery = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y ?c where { graph ?c {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }}"; + + StatementMetadata metadata = new StatementMetadata(); + metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe")); + metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04")); + + RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), + new RyaType("CoffeeShop"), new RyaURI("http://context_1"), "", metadata); + RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), + new RyaType("HardwareStore"), new RyaURI("http://context_2"), "", metadata); + dao.add(statement1); + dao.add(statement2); + + + SPARQLParser parser = new SPARQLParser(); + ParsedQuery pq = parser.parseQuery(contextQuery, null); + List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr()); + StatementMetadataNode<AccumuloRdfConfiguration> node = new StatementMetadataNode<>(spList, conf); + + List<BindingSet> bsCollection = new ArrayList<>(); + QueryBindingSet bsConstraint1 = new QueryBindingSet(); + bsConstraint1.addBinding("x", new LiteralImpl("CoffeeShop")); + bsConstraint1.addBinding("z", new LiteralImpl("Virginia")); + bsConstraint1.addBinding("c", new URIImpl("http://context_1")); + + QueryBindingSet bsConstraint2 = new QueryBindingSet(); + bsConstraint2.addBinding("x", new LiteralImpl("CoffeeShop")); + bsConstraint2.addBinding("z", new LiteralImpl("Maryland")); + bsConstraint2.addBinding("c", new URIImpl("http://context_2")); + + QueryBindingSet bsConstraint4 = new QueryBindingSet(); + bsConstraint4.addBinding("x", new LiteralImpl("HardwareStore")); + bsConstraint4.addBinding("z", new LiteralImpl("WestVirginia")); + bsConstraint4.addBinding("c", new URIImpl("http://context_2")); + + QueryBindingSet bsConstraint3 = new QueryBindingSet(); + bsConstraint3.addBinding("x", new LiteralImpl("BurgerShack")); + bsConstraint3.addBinding("z", new LiteralImpl("Delaware")); + bsConstraint3.addBinding("c", new URIImpl("http://context_1")); + bsCollection.add(bsConstraint1); + bsCollection.add(bsConstraint2); + bsCollection.add(bsConstraint3); + bsCollection.add(bsConstraint4); + +// AccumuloRyaQueryEngine engine = dao.getQueryEngine(); +//// CloseableIteration<RyaStatement, RyaDAOException> iter = engine.query(new RyaStatement(new RyaURI("http://Joe"), +//// new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context_2")), conf); +// CloseableIteration<? extends Map.Entry<RyaStatement,BindingSet>, RyaDAOException> iter = engine.queryWithBindingSet(Arrays.asList(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>( +// new RyaStatement(new RyaURI("http://Joe"), +// new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context_2")), bsConstraint4)), conf); +// while (iter.hasNext()) { +// System.out.println(iter.next()); +// } +// + CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(bsCollection); + + QueryBindingSet expected1 = new QueryBindingSet(); + expected1.addBinding("x", new LiteralImpl("CoffeeShop")); + expected1.addBinding("y", new LiteralImpl("Joe")); + expected1.addBinding("z", new LiteralImpl("Virginia")); + expected1.addBinding("c", new URIImpl("http://context_1")); + + QueryBindingSet expected2 = new QueryBindingSet(); + expected2.addBinding("x", new LiteralImpl("HardwareStore")); + expected2.addBinding("y", new LiteralImpl("Joe")); + expected2.addBinding("z", new LiteralImpl("WestVirginia")); + expected2.addBinding("c", new URIImpl("http://context_2")); + + List<BindingSet> bsList = new ArrayList<>(); + while (iteration.hasNext()) { + bsList.add(iteration.next()); + } + + Assert.assertEquals(2, bsList.size()); + Assert.assertEquals(expected1, bsList.get(1)); + Assert.assertEquals(expected2, bsList.get(0)); + + dao.delete(statement1, conf); + dao.delete(statement2, conf); + } + private static AccumuloRdfConfiguration getConf() { final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataOptimizerIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataOptimizerIT.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataOptimizerIT.java index 2353f51..48a0f28 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataOptimizerIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/AccumuloStatementMetadataOptimizerIT.java @@ -58,12 +58,12 @@ public class AccumuloStatementMetadataOptimizerIT { private SailRepository repo; private SailRepositoryConnection conn; private AccumuloRyaDAO dao; - private final String query1 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; - private final String query2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?a ?b ?c where {_:blankNode1 rdf:type rdf:Statement; rdf:subject ?a; " - + "rdf:predicate <http://worksAt>; rdf:object <http://BurgerShack>; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date. " - + "_:blankNode2 rdf:type rdf:Statement; rdf:subject ?a; " - + "rdf:predicate <http://talksTo>; rdf:object ?b; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query1 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; owl:annotatedSource <http://Joe>; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query2 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?a ?b ?c where {_:blankNode1 rdf:type owl:Annotation; owl:annotatedSource ?a; " + + "owl:annotatedProperty <http://worksAt>; owl:annotatedTarget <http://BurgerShack>; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date. " + + "_:blankNode2 rdf:type owl:Annotation; owl:annotatedSource ?a; " + + "owl:annotatedProperty <http://talksTo>; owl:annotatedTarget ?b; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date }"; @Before public void init() throws Exception { @@ -143,31 +143,6 @@ public class AccumuloStatementMetadataOptimizerIT { dao.delete(statement, (AccumuloRdfConfiguration) conf); } -// @Test -// public void simpleDataTypeTest() throws Exception { -// StatementMetadata metadata = new StatementMetadata(); -// metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Doug")); -// metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-15")); -// -// RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), -// new RyaType("http://BurgerShack"), new RyaURI("http://context"), "", metadata); -// dao.add(statement); -// RyaStatement statement2 = new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://worksAt"), -// new RyaURI("http://BurgerShack"), new RyaURI("http://context"), "", metadata); -// dao.add(statement2); -// -// String temp = "select ?x where { ?x <http://worksAt> 'http://BurgerShack' . }"; -// TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, temp).evaluate(); -// -// List<BindingSet> bsList = new ArrayList<>(); -// while (result.hasNext()) { -// bsList.add(result.next()); -// } -// System.out.println("Bindings are: " + bsList); -// dao.delete(statement, (AccumuloRdfConfiguration) conf); -// dao.delete(statement2, (AccumuloRdfConfiguration) conf); -// } - @Test public void simpleQueryWithBindingSet() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataIT.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataIT.java index 8b8d1df..3ca37a6 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataIT.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataIT.java @@ -1,4 +1,5 @@ package org.apache.rya.indexing.statement.metadata; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -65,12 +66,12 @@ public class MongoStatementMetadataIT { private SailRepository repo; private SailRepositoryConnection conn; private MongoDBRyaDAO dao; - private final String query1 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; - private final String query2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?a ?b ?c where {_:blankNode1 rdf:type rdf:Statement; rdf:subject ?a; " - + "rdf:predicate <http://worksAt>; rdf:object <http://BurgerShack>; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date. " - + "_:blankNode2 rdf:type rdf:Statement; rdf:subject ?a; " - + "rdf:predicate <http://talksTo>; rdf:object ?b; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query1 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query2 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?a ?b ?c where {_:blankNode1 rdf:type owl:Annotation; ano:Source ?a; " + + "ano:Property <http://worksAt>; ano:Target <http://BurgerShack>; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date. " + + "_:blankNode2 rdf:type owl:Annotation; ano:Source ?a; " + + "ano:Property <http://talksTo>; ano:Target ?b; <http://createdBy> ?c; <http://createdOn> \'2017-01-04\'^^xsd:date }"; @Before public void init() throws Exception { @@ -92,7 +93,7 @@ public class MongoStatementMetadataIT { sail.shutDown(); sail.shutDown(); dao.destroy(); - + if (mongoClient != null) { mongoClient.close(); } @@ -101,7 +102,6 @@ public class MongoStatementMetadataIT { } MongoConnectorFactory.closeMongoClient(); } - @Test public void simpleQueryWithoutBindingSet() throws Exception { @@ -231,9 +231,9 @@ public class MongoStatementMetadataIT { dao.add(statement2); dao.add(statement3); dao.add(statement4); - + TupleQueryResult result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query2).evaluate(); - + Set<BindingSet> expected = new HashSet<>(); QueryBindingSet expected1 = new QueryBindingSet(); expected1.addBinding("b", new URIImpl("http://Betty")); @@ -255,7 +255,7 @@ public class MongoStatementMetadataIT { } private MongoDBRdfConfiguration getConf() throws IOException { - + String host = mongoClient.getServerAddressList().get(0).getHost(); int port = mongoClient.getServerAddressList().get(0).getPort(); Set<RyaURI> propertySet = new HashSet<RyaURI>( http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataNodeTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataNodeTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataNodeTest.java index 0a3ada0..36091ea 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataNodeTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/MongoStatementMetadataNodeTest.java @@ -62,10 +62,10 @@ public class MongoStatementMetadataNodeTest { protected MongoClient mongoClient; private MongoDBRdfConfiguration conf; private MongoDBRyaDAO dao; - private final String query = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; - private final String query2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject ?x; " - + "rdf:predicate <http://worksAt>; rdf:object ?y; <http://createdBy> ?x; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query2 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; ano:Source ?x; " + + "ano:Property <http://worksAt>; ano:Target ?y; <http://createdBy> ?x; <http://createdOn> \'2017-01-04\'^^xsd:date }"; @Before http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataExternalSetProviderTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataExternalSetProviderTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataExternalSetProviderTest.java index 2a41396..5e28a5b 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataExternalSetProviderTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataExternalSetProviderTest.java @@ -46,14 +46,14 @@ import org.openrdf.query.parser.sparql.SPARQLParser; public class StatementMetadataExternalSetProviderTest { - private final String query = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; - private final String query3 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type rdf:Statement. _:blankNode2 rdf:type rdf:Statement; rdf:subject <http://Bob>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; - private final String query2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " - + "_:blankNode2 rdf:type rdf:Statement; rdf:subject <http://Bob>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; + private final String query = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotation; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private final String query3 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type owl:Annotation. _:blankNode2 rdf:type owl:Annotation; ano:Source <http://Bob>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; + private final String query2 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type owl:Annotation; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " + + "_:blankNode2 rdf:type owl:Annotation; ano:Source <http://Bob>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; @Test public void createSingleAccumuloMetadataNode() throws MalformedQueryException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataOptimizerTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataOptimizerTest.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataOptimizerTest.java index 5a1cef8..d4c9436 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataOptimizerTest.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataOptimizerTest.java @@ -54,28 +54,28 @@ import org.openrdf.query.parser.sparql.SPARQLParser; @RunWith(value = Parameterized.class) public class StatementMetadataOptimizerTest { - private static final String query1 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; - private static final String query2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode2 rdf:type rdf:Statement; rdf:subject <http://Bob>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; - private static final String query3 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode2 rdf:type rdf:Statement; rdf:subject <http://Frank>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-03-04\'^^xsd:date }"; - private static final String query4 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " + private static final String query1 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode rdf:type owl:Annotated; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date }"; + private static final String query2 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode2 rdf:type owl:Annotated; ano:Source <http://Bob>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; + private static final String query3 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode2 rdf:type owl:Annotated; ano:Source <http://Frank>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-03-04\'^^xsd:date }"; + private static final String query4 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type owl:Annotated; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " + "_:blankNode2 rdf:type rdf:Statement; rdf:subject <http://Bob>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; - private static final String query5 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " - + "_:blankNode2 rdf:type rdf:Statement; rdf:subject <http://Bob>; " - + "rdf:predicate <http://worksAt>; rdf:object ?a; <http://createdBy> ?b; <http://createdOn> \'2017-02-04\'^^xsd:date. " - + "OPTIONAL{ _:blankNode3 rdf:type rdf:Statement; rdf:subject <http://Frank>; " - + "rdf:predicate <http://worksAt>; rdf:object ?c; <http://createdBy> <http://Doug>; <http://createdOn> \'2017-03-04\'^^xsd:date } }"; - private static final String query6 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {?m rdf:type rdf:Statement; rdf:subject <http://Joe>; " - + "rdf:predicate <http://worksAt>; rdf:object ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " - + "{ ?o rdf:type rdf:Statement; rdf:subject <http://Frank>; " - + "rdf:predicate <http://worksAt>; rdf:object ?c; <http://createdBy> ?p; <http://createdOn> \'2017-03-04\'^^xsd:date . } " - + "UNION {?n rdf:predicate <http://worksAt>; rdf:object ?a; <http://createdBy> ?c; <http://createdOn> \'2017-02-04\'^^xsd:date; " - + "rdf:type rdf:Statement; rdf:subject ?p. } }"; + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-02-04\'^^xsd:date }"; + private static final String query5 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {_:blankNode1 rdf:type owl:Annotated; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " + + "_:blankNode2 rdf:type owl:Annotated; rdf:subject <http://Bob>; " + + "ano:Property <http://worksAt>; ano:Target ?a; <http://createdBy> ?b; <http://createdOn> \'2017-02-04\'^^xsd:date. " + + "OPTIONAL{ _:blankNode3 rdf:type owl:Annotated; ano:Source <http://Frank>; " + + "ano:Property <http://worksAt>; ano:Target ?c; <http://createdBy> <http://Doug>; <http://createdOn> \'2017-03-04\'^^xsd:date } }"; + private static final String query6 = "prefix owl: <http://www.w3.org/2002/07/owl#> prefix ano: <http://www.w3.org/2002/07/owl#annotated> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?y where {?m rdf:type owl:Annotated; ano:Source <http://Joe>; " + + "ano:Property <http://worksAt>; ano:Target ?x; <http://createdBy> ?y; <http://createdOn> \'2017-01-04\'^^xsd:date. " + + "{ ?o rdf:type owl:Annotated; ano:Source <http://Frank>; " + + "ano:Property <http://worksAt>; ano:Target ?c; <http://createdBy> ?p; <http://createdOn> \'2017-03-04\'^^xsd:date . } " + + "UNION {?n ano:Property <http://worksAt>; ano:Target ?a; <http://createdBy> ?c; <http://createdOn> \'2017-02-04\'^^xsd:date; " + + "rdf:type owl:Annotated; ano:Source ?p. } }"; private String query; private Set<StatementMetadataNode<?>> expected; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/aa65d6a9/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataTestUtils.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataTestUtils.java b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataTestUtils.java index de499e7..35c5405 100644 --- a/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataTestUtils.java +++ b/extras/indexing/src/test/java/org/apache/rya/indexing/statement/metadata/StatementMetadataTestUtils.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import org.apache.rya.api.domain.RyaURI; +import org.apache.rya.indexing.statement.metadata.matching.OWLReify; import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.model.vocabulary.RDF; @@ -36,8 +37,8 @@ import org.openrdf.query.algebra.helpers.QueryModelVisitorBase; public class StatementMetadataTestUtils { private static final List<RyaURI> uriList = Arrays.asList(new RyaURI(RDF.TYPE.toString()), - new RyaURI(RDF.SUBJECT.toString()), new RyaURI(RDF.PREDICATE.toString()), - new RyaURI(RDF.OBJECT.toString())); + new RyaURI(OWLReify.SOURCE.toString()), new RyaURI(OWLReify.PROPERTY.toString()), + new RyaURI(OWLReify.TARGET.toString())); public static Set<QueryModelNode> getMetadataNodes(TupleExpr query) { MetadataNodeCollector collector = new MetadataNodeCollector();
