@Override public void meet(StatementPattern sp) { sp.replaceWith(new AggregationPipelineQueryNode(inputCollection, sp)); }
private void removeMatchedPattern(final TupleExpr tupleExpr, final StatementPattern pattern, final TupleExprReplacer replacer) { final List<TupleExpr> indexTuples = replacer.createReplacement(pattern); if (indexTuples.size() > 1) { final VarExchangeVisitor vev = new VarExchangeVisitor(pattern); tupleExpr.visit(vev); Join join = new Join(indexTuples.remove(0), indexTuples.remove(0)); for (final TupleExpr geo : indexTuples) { join = new Join(join, geo); } pattern.replaceWith(join); } else if (indexTuples.size() == 1) { pattern.replaceWith(indexTuples.get(0)); pattern.setParentNode(null); } else { throw new IllegalStateException("Must have at least one replacement for matched StatementPattern."); } }
@Override public void meet(final Join node) { final QueryModelNode lNode = node.getLeftArg(); if (lNode instanceof StatementPattern) { exchangeVar.replaceWith(lNode); node.setLeftArg(exchangeVar); } else { super.meet(node); } } }
/** * Transform a statement pattern to infer triples for a predicate variable. * * @param node the node to transform * @return list of nodes to visit next */ @Override public List<QueryModelNode> apply(StatementPattern node) { List<QueryModelNode> next = newNextList(); StatementPattern left = node.clone(); next.add(left); TupleExpr right = assignPredicates(predicates, node.clone(), next); node.replaceWith(new Union(left, right)); return next; }
/** * Transform a statement pattern according to OWL-2 property chain * axiom. * * @param node the node to transform * @return list of nodes to visit next */ @Override public List<QueryModelNode> apply(StatementPattern node) { List<QueryModelNode> next = newNextList(); Var s = node.getSubjectVar(); Var o = node.getObjectVar(); Var c = node.getContextVar(); TupleExpr left = node.clone(); TupleExpr right = getChain(s, o, c); node.replaceWith(new Union(left, right)); next.add(left); next.add(right); return next; }
node.replaceWith(union); log.trace("Replacing node with inferred intersection union: " + union);
@Override public void updateQueryModelNodes(boolean hasResult) { QueryModelNode replacementNode = hasResult ? new SingletonSet() : new EmptySet(); geoStatement.replaceWith(replacementNode); if(hasResult) { filter.replaceWith(filter.getArg()); } else { filter.replaceWith(new EmptySet()); } if(functionParent instanceof ExtensionElem) { Extension extension = (Extension) functionParent.getParentNode(); List<ExtensionElem> elements = extension.getElements(); if(elements.size() > 1) { elements.remove(functionParent); } else { extension.replaceWith(extension.getArg()); } } } }
@Override public void updateQueryModelNodes(boolean hasResult) { QueryModelNode replacementNode = hasResult ? new SingletonSet() : new EmptySet(); geoStatement.replaceWith(replacementNode); if(hasResult) { filter.replaceWith(filter.getArg()); } else { filter.replaceWith(new EmptySet()); } if(functionParent instanceof ExtensionElem) { Extension extension = (Extension) functionParent.getParentNode(); List<ExtensionElem> elements = extension.getElements(); if(elements.size() > 1) { elements.remove(functionParent); } else { extension.replaceWith(extension.getArg()); } } } }
/** * Transform a statement pattern according to OWL-2 subproperty axiom. * * @param node the node to transform * @return list of nodes to visit next */ @Override public List<QueryModelNode> apply(StatementPattern node) { List<QueryModelNode> next = newNextList(); StatementPattern left = node.clone(); // replace the predicate with the subproperty StatementPattern right = new StatementPattern( node.getSubjectVar(), new ConstVar(vf.createURI(op1)), node.getObjectVar(), node.getContextVar()); node.replaceWith( new Union(left, right)); next.add(left); next.add(right); return next; }
/** * Transform a statement pattern according to OWL-2 subclass axiom. * * @param node the node to transform * @return list of nodes to visit next */ @Override public List<QueryModelNode> apply(StatementPattern node) { List<QueryModelNode> next = newNextList(); StatementPattern left = node.clone(); // replace the object with the subclass StatementPattern right = new StatementPattern( node.getSubjectVar(), node.getPredicateVar(), new ConstVar(vf.createURI(ce1)), node.getContextVar()); node.replaceWith( new Union(left, right)); next.add(left); next.add(right); return next; }
@Override protected void meetSP(final StatementPattern node) throws Exception { final StatementPattern sp = node.clone(); final Var predVar = sp.getPredicateVar(); final URI pred = (URI) predVar.getValue(); final String predNamespace = pred.getNamespace(); final Var objVar = sp.getObjectVar(); final Var cntxtVar = sp.getContextVar(); if (objVar != null && !RDF.NAMESPACE.equals(predNamespace) && !SESAME.NAMESPACE.equals(predNamespace) && !RDFS.NAMESPACE.equals(predNamespace) && !EXPANDED.equals(cntxtVar)) { final URI transPropUri = (URI) predVar.getValue(); if (inferenceEngine.isTransitiveProperty(transPropUri)) { node.replaceWith(new TransitivePropertySP(sp.getSubjectVar(), sp.getPredicateVar(), sp.getObjectVar(), sp.getContextVar())); } } } }
union.setLeftArg(sp); union.setRightArg(new StatementPattern(objVar, predVar, subjVar, cntxtVar)); node.replaceWith(union);
@Override protected void meetSP(final StatementPattern node) throws Exception { final Var subVar = node.getSubjectVar(); final Var predVar = node.getPredicateVar(); final Var objVar = node.getObjectVar(); final Var conVar = node.getContextVar(); if (predVar != null && objVar != null && objVar.getValue() != null && objVar.getValue() instanceof Resource && RDF.TYPE.equals(predVar.getValue()) && !EXPANDED.equals(conVar)) { final Resource object = (Resource) objVar.getValue(); if (inferenceEngine.isEnumeratedType(object)) { final Set<BindingSet> solutions = new LinkedHashSet<>(); final Set<Resource> enumeration = inferenceEngine.getEnumeration(object); for (final Resource enumType : enumeration) { final QueryBindingSet qbs = new QueryBindingSet(); qbs.addBinding(subVar.getName(), enumType); solutions.add(qbs); } if (!solutions.isEmpty()) { final BindingSetAssignment enumNode = new BindingSetAssignment(); enumNode.setBindingSets(solutions); node.replaceWith(enumNode); log.trace("Replacing node with inferred one of enumeration: " + enumNode); } } } } }
node.replaceWith(new Union(left, right)); next.add(left); next.add(right);
@Override public void meet(StatementPattern node) throws RepositoryException { Resource subj = (Resource)node.getSubjectVar().getValue(); URI pred = (URI)node.getPredicateVar().getValue(); Value obj = node.getObjectVar().getValue(); Resource[] ctx = getContexts(node.getContextVar()); for (RepositoryConnection member : members) { if (member.hasStatement(subj, pred, obj, true, ctx)) { return; } } node.replaceWith(new EmptySet()); }
union.setLeftArg(sp); union.setRightArg(new StatementPattern(objVar, new Var(predVar.getName(), invPropUri), subjVar, cntxtVar)); node.replaceWith(union);
node.replaceWith(new InferUnion(node.clone(), svfInferenceQuery));
@Override public void meet(StatementPattern node) throws RepositoryException { Resource subj = (Resource)node.getSubjectVar().getValue(); IRI pred = (IRI)node.getPredicateVar().getValue(); Value obj = node.getObjectVar().getValue(); Resource[] ctx = getContexts(node.getContextVar()); for (RepositoryConnection member : members) { if (member.hasStatement(subj, pred, obj, true, ctx)) { return; } } node.replaceWith(new EmptySet()); }
/** * Check whether any solution for the {@link StatementPattern} could be derived from * reflexive property inference, and if so, replace the pattern with a union of itself and the * reflexive solution. */ @Override protected void meetSP(StatementPattern node) throws Exception { // Only applies when the predicate is defined and reflexive final Var predVar = node.getPredicateVar(); if (predVar.getValue() != null && inferenceEngine.isReflexiveProperty((URI) predVar.getValue())) { final StatementPattern originalSP = node.clone(); // The reflexive solution is a ZeroLengthPath between subject and // object: they can be matched to one another, whether constants or // variables. final Var subjVar = node.getSubjectVar(); final Var objVar = node.getObjectVar(); final ZeroLengthPath reflexiveSolution = new ZeroLengthPath(subjVar, objVar); node.replaceWith(new InferUnion(originalSP, reflexiveSolution)); } } }
clone.getSubjectVar())); node.replaceWith(union); node.replaceWith(union);