public static boolean triplePathIso(TriplePath tp1, TriplePath tp2, NodeIsomorphismMap isoMap) { if ( tp1.isTriple() ^ tp2.isTriple() ) return false ; if ( tp1.isTriple() ) return Iso.tripleIso(tp1.asTriple(), tp2.asTriple(), isoMap) ; else return Iso.nodeIso(tp1.getSubject(), tp2.getSubject(), isoMap) && Iso.nodeIso(tp1.getObject(), tp2.getObject(), isoMap) && tp1.getPath().equalTo(tp2.getPath(), isoMap) ; }
@Override public QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt) { return new QueryIterPath(new TriplePath(subject, path, object), QueryIterSingleton.create(binding, execCxt), execCxt) ; }
protected void addVars(TriplePath t) { addVar(t.getSubject()); if (t.getPredicate()!=null) { addVar(t.getPredicate()); } addVar(t.getObject()); }
public PathBlock reduce(TriplePath triplePath) { PathBlock x = new PathBlock() ; reduce(x, varAlloc, triplePath.getSubject(), triplePath.getPath(), triplePath.getObject()) ; return x ; }
@Override public boolean equals(Object other) { if ( this == other) return true ; if ( ! ( other instanceof TriplePath) ) return false ; TriplePath tp = (TriplePath)other ; // True if one is true and one is false if ( tp.isTriple() ^ this.isTriple() ) return false ; if ( isTriple() ) return asTriple().equals(tp.asTriple()) ; else return subject.equals(tp.subject) && object.equals(tp.object) && path.equals(tp.path) ; }
@Override public void visit(OpPath opPath) { addVar(acc, opPath.getTriplePath().getSubject()) ; addVar(acc, opPath.getTriplePath().getObject()) ; }
public void setQueryPattern(Element graphPattern) { if (graphPattern instanceof ElementTriplesBlock) { query.setQueryPattern((ElementTriplesBlock)graphPattern); } else if (graphPattern instanceof ElementGroup) { ElementGroup group = (ElementGroup) graphPattern; for (Element e: flatten(group)) { if (e instanceof ElementPathBlock) { ElementPathBlock epb = (ElementPathBlock) e; for (TriplePath p:epb.getPattern().getList()) { if (!p.isTriple()) { throw new IllegalArgumentException("Conjunctive query only accepts a basic graph patterns. No triple path: "+ p+"\n"+graphPattern ); } } } else if (!(e instanceof ElementTriplesBlock) && !(e instanceof ElementFilter)) { throw new IllegalArgumentException("Conjunctive query only accepts a basic graph patterns: "+ e+"\n"+graphPattern ); } } query.setQueryPattern(graphPattern); } else { throw new IllegalArgumentException("Conjunctive query only accepts a basic graph patterns: "+ graphPattern); } } public void addTriple(Triple t) {
public RuleSystem toRules(TriplePath tp, boolean rightRecursion, String triplePredicateName, String negatedPropertySetPredName) { String predPrefix = "P"; Set<String> predNames = HashSetFactory.make(); predNames.add(triplePredicateName); predNames.add(negatedPropertySetPredName); int startSuffix = OCUtils.nextAvailableSuffixVariable(predNames, predPrefix)+1; NewVariableGenerator predgen = new NewVariableGenerator(predPrefix, startSuffix); PathToRules visitor = new PathToRules(predgen, triplePredicateName, negatedPropertySetPredName, rightRecursion);; tp.getPath().visit(visitor); return visitor.getResult(); }
@Override public int hashCode() { return triplePath.hashCode() ; }
@Override public boolean equals(Object other) { if ( this == other) return true ; if ( ! ( other instanceof TriplePath) ) return false ; TriplePath tp = (TriplePath)other ; // True if one is true and one is false if ( tp.isTriple() ^ this.isTriple() ) return false ; if ( isTriple() ) return asTriple().equals(tp.asTriple()) ; else return subject.equals(tp.subject) && object.equals(tp.object) && path.equals(tp.path) ; }
@Override public Op transform(OpPath opPath) { TriplePath tp = opPath.getTriplePath() ; Op op = transformPath(opPath, tp.getSubject(), tp.getPath(), tp.getObject() ) ; // And combine adjacent triple patterns. return op ; }
public static void addVarsFromTriplePath(Set<Var> acc, TriplePath tpath) { addVar(acc, tpath.getSubject()) ; addVar(acc, tpath.getObject()) ; }
if(e instanceof ElementPathBlock) {for(Iterator<TriplePath> iter = ((ElementPathBlock) e).patternElts(); iter.hasNext();){ Triple t = iter.next().asTriple(); triples.add(t); }}
@Override public int hashCode() { return triplePath.hashCode() ; }
public static boolean triplePathIso(TriplePath tp1, TriplePath tp2, NodeIsomorphismMap isoMap) { if ( tp1.isTriple() ^ tp2.isTriple() ) return false ; if ( tp1.isTriple() ) return Utils.tripleIso(tp1.asTriple(), tp2.asTriple(), isoMap) ; else return Utils.nodeIso(tp1.getSubject(), tp2.getSubject(), isoMap) && Utils.nodeIso(tp1.getObject(), tp2.getObject(), isoMap) && tp1.getPath().equalTo(tp2.getPath(), isoMap) ; }
@Override public void visit(ElementPathBlock el) { for (Iterator<TriplePath> iter = el.patternElts() ; iter.hasNext() ; ) { TriplePath tp = iter.next() ; // If it's triple-izable, then use the triple. if ( tp.isTriple() ) VarUtils.addVarsFromTriple(acc, tp.asTriple()) ; else VarUtils.addVarsFromTriplePath(acc, tp) ; } }
public PathBlock reduce(TriplePath triplePath) { PathBlock x = new PathBlock() ; reduce(x, varAlloc, triplePath.getSubject(), triplePath.getPath(), triplePath.getObject()) ; return x ; }
@Override public QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt) { return new QueryIterPath(new TriplePath(subject, path, object), QueryIterSingleton.create(binding, execCxt), execCxt) ; }