@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) ; } }
@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) ; } }
@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(ElementPathBlock arg0) { Iterator<TriplePath> it = arg0.patternElts(); while (it.hasNext()) { TriplePath t = it.next(); if (t.isTriple()) { this.atomset.add(SparqlUtils.triple2Atom(t.asTriple())); } else { throw new ParseError("TriplePath not allowed"); } } }
@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 int hashCode() { if ( hash == -1 ) { if ( isTriple() ) hash = asTriple().hashCode() ; else hash = (subject.hashCode()<<2) ^ path.hashCode() ^ (object.hashCode()<<1) ; } return hash ; }
@Override public int hashCode() { if ( hash == -1 ) { if ( isTriple() ) hash = asTriple().hashCode() ; else hash = (subject.hashCode()<<2) ^ path.hashCode() ^ (object.hashCode()<<1) ; } return hash ; }
public static ElementTriplesBlock toTriples(ElementPathBlock pb) { ElementTriplesBlock ret = new ElementTriplesBlock(); for (TriplePath tp :pb.getPattern().getList()) { if (tp.isTriple()) { ret.addTriple(tp.asTriple()); } else { throw new RuntimeException("Path query not supported"); } } return ret; } public static Set<String> getVars(Set<Var> vars) {
protected void insert(TripleCollector target, ElementPathBlock source) { for (TriplePath path : source.getPattern()) { if (path.isTriple()) { target.addTriple(path.asTriple()); } else { target.addTriplePath(path); } } }
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) ; }
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) ; }
throw new UnsupportedQueryException("Path expressions are not supported yet."); triples.add(path.asTriple());
public List<Triple> getTriples() { if (query.getQueryPattern() instanceof ElementTriplesBlock) { ElementTriplesBlock sp = (ElementTriplesBlock) query.getQueryPattern(); return sp.getPattern().getList(); } else { assert query.getQueryPattern() instanceof ElementGroup : query.getQueryPattern() ; List<Element> es = flatten(query.getQueryPattern()); List<Triple> ret = new ArrayList<Triple>(); for (Element e: es) { if (e instanceof ElementTriplesBlock) { ret.addAll(((ElementTriplesBlock) e).getPattern().getList()); } else if (e instanceof ElementPathBlock ) { ElementPathBlock epb = (ElementPathBlock) e; for (TriplePath tp: epb.getPattern().getList()) { assert tp.isTriple() : tp; ret.add(tp.asTriple()); } } } return ret; } }
public static TriplePath substitute(TriplePath triplePath, Binding binding) { if ( triplePath.isTriple() ) return new TriplePath(Substitute.substitute(triplePath.asTriple(), binding)) ; Node s = triplePath.getSubject() ; Node o = triplePath.getObject() ; Node s1 = substitute(s, binding) ; Node o1 = substitute(o, binding) ; TriplePath tp = triplePath ; if ( s1 != s || o1 != o ) tp = new TriplePath(s1, triplePath.getPath(), o1) ; return tp ; }
public static TriplePath substitute(TriplePath triplePath, Binding binding) { if ( triplePath.isTriple() ) return new TriplePath(Substitute.substitute(triplePath.asTriple(), binding)) ; Node s = triplePath.getSubject() ; Node o = triplePath.getObject() ; Node s1 = substitute(s, binding) ; Node o1 = substitute(o, binding) ; TriplePath tp = triplePath ; if ( s1 != s || o1 != o ) tp = new TriplePath(s1, triplePath.getPath(), o1) ; return tp ; }
/** Convert any paths of exactly one predicate to a triple pattern */ public static Op pathToTriples(PathBlock pattern) { BasicPattern bp = null ; Op op = null ; for ( TriplePath tp : pattern ) { if ( tp.isTriple() ) { if ( bp == null ) bp = new BasicPattern() ; bp.add(tp.asTriple()) ; continue ; } // Path form. op = flush(bp, op) ; bp = null ; OpPath opPath2 = new OpPath(tp) ; op = OpSequence.create(op, opPath2) ; continue ; } // End. Finish off any outstanding BGP. op = flush(bp, op) ; return op ; }
/** Convert any paths of exactly one predicate to a triple pattern */ public static Op pathToTriples(PathBlock pattern) { BasicPattern bp = null ; Op op = null ; for ( TriplePath tp : pattern ) { if ( tp.isTriple() ) { if ( bp == null ) bp = new BasicPattern() ; bp.add(tp.asTriple()) ; continue ; } // Path form. op = flush(bp, op) ; bp = null ; OpPath opPath2 = new OpPath(tp) ; op = OpSequence.create(op, opPath2) ; continue ; } // End. Finish off any outstanding BGP. op = flush(bp, op) ; return op ; }
public Element transform(TriplePath tp,boolean bestEffort, NewVariableGenerator vargen, boolean[] resultHasPropertyPaths) { Triple t = tp.asTriple(); if (t!=null) { // this is a simple triple ElementTriplesBlock ret =new ElementTriplesBlock(); ret.addTriple(t); return ret; } assert !tp.isTriple(); assert tp.getPredicate()==null: tp; JenaPathRewrite pr = new JenaPathRewrite(tp.getSubject(), tp.getObject(), bestEffort, vargen); tp.getPath().visit(pr); if (resultHasPropertyPaths!=null) { resultHasPropertyPaths[0] = pr.resultWithPropertyPaths(); } return pr.getResult(); }
for(TriplePath path:list) { if(path.isTriple()) { indent("{%s}: %s",path.getClass(),path.asTriple());