@Override public void visit(ElementPathBlock el) { // TODO Paths not handled yet List<TriplePath> triplePaths = el.getPattern().getList(); for(TriplePath triplePath : triplePaths) { Triple triple = triplePath.asTriple(); Quad quad = new Quad(defaultGraphName, triple); quads.add(quad); } //throw new RuntimeException("Not implemented"); }
public static ElementPathBlock createElementPath(Iterable<TriplePath> it) { ElementPathBlock result = new ElementPathBlock(); for(TriplePath tp : it) { result.addTriple(tp); } return result; }
@Override public void visit(ElementPathBlock el) { ElementPathBlock newBlock = new ElementPathBlock(); Iterator<TriplePath> tIter = el.patternElts(); while (tIter.hasNext()) { newBlock.addTriplePath(rewrite(tIter.next())); } push(newBlock); }
public static ElementPathBlock createElement(TriplePath triplePath) { ElementPathBlock result = new ElementPathBlock(); result.addTriplePath(triplePath); return result; }
@Override public Element transform(ElementPathBlock el) { ElementPathBlock epb = new ElementPathBlock() ; boolean changed = false ; for (TriplePath p : el.getPattern()) { TriplePath p2 = transform(p) ; changed = changed || p != p2 ; epb.addTriplePath(p2) ; } if ( changed ) return epb ; return el ; }
public static Element applyTransform(ElementPathBlock el, Map<Node, BinaryRelation> virtualPredicates, Generator<Var> rootVarGen) { PathBlock bgp = el.getPattern(); ElementPathBlock newPattern = new ElementPathBlock(); List<Element> elements = new ArrayList<Element>(bgp.size()); for(TriplePath tp : bgp) { if(tp.isTriple()) { Triple triple = tp.asTriple(); Generator<Var> varGen = rootVarGen.clone(); Element e = applyTransform(triple, virtualPredicates, varGen); if(e == null) { newPattern.addTriple(new TriplePath(triple)); } else { elements.add(e); } } else { logger.warn("Triple path expressions not supported"); newPattern.addTriple(tp); } } Iterable<Element> items = newPattern.isEmpty() ? elements : Iterables.concat(Collections.singleton(newPattern), elements) ; Element result = ElementUtils.createElementGroup(items); return result; }
public Element transform(ElementPathBlock el) { PathBlock before = el.getPattern(); PathBlock after = TransformDeduplicatePatterns.deduplicate(before); Element result; if(after.equals(before)) { result = el; } else { ElementPathBlock tmp = new ElementPathBlock(); tmp.getPattern().addAll(after); result = tmp; } return result; } }
@Override public void visit(ElementPathBlock el) { for (Iterator<TriplePath> iterator = el.patternElts(); iterator.hasNext();) { TriplePath tp = iterator.next(); if(inOptionalClause){ } else { if(tp.asTriple().equals(triple)){ ElementGroup parent = parentGroup.peek(); ElementPathBlock elementTriplesBlock = new ElementPathBlock(); elementTriplesBlock.addTriple(tp); ElementGroup eg = new ElementGroup(); eg.addElement(elementTriplesBlock); parent.addElement(new ElementFilter(new E_NotExists(eg))); iterator.remove(); } } } }
protected ElementGroup createQueryPattern(Template t){ ElementGroup elg = new ElementGroup(); Map<Node, BasicPattern> graphs = t.getGraphPattern(); for(Node n: graphs.keySet()){ Element el = new ElementPathBlock(graphs.get(n)); if(! Quad.defaultGraphNodeGenerated.equals(n) ){ ElementGroup e = new ElementGroup(); e.addElement(el); el = new ElementNamedGraph(n, e); } elg.addElement(el); } return elg; } }
Query q = QueryFactory.create(query); // SPARQL 1.1 // Remember distinct subjects in this final Set<Node> subjects = new HashSet<Node>(); // This will walk through all parts of the query ElementWalker.walk(q.getQueryPattern(), // For each element... new ElementVisitorBase() { // ...when it's a block of triples... public void visit(ElementPathBlock el) { // ...go through all the triples... Iterator<TriplePath> triples = el.patternElts(); while (triples.hasNext()) { // ...and grab the subject subjects.add(triples.next().getSubject()); } } } );
final public void Object(Node s, Node p, Path path, TripleCollector acc) throws ParseException { Node o ; ElementPathBlock tempAcc = new ElementPathBlock() ; int mark = tempAcc.mark() ; o = GraphNode(tempAcc); insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
.compare(o1.getObject().toString(), o2.getObject().toString()).result()); Iterator<TriplePath> iterator = el.patternElts(); while (iterator.hasNext()) { Triple tp = iterator.next().asTriple(); el.addTriple(tp);
@Override public void visit(ElementPathBlock el) { if ( el.isEmpty() ) { out.println("# Empty BGP"); return; PathBlock pBlk = el.getPattern(); BasicPattern bgp = new BasicPattern(); boolean first = true; // Has anything been output?
public ElementPathBlock(BasicPattern bgp) { for ( Triple t : bgp.getList() ) addTriple(t) ; }
@Override public void addTriple(Triple t) { addTriplePath(new TriplePath(t)) ; }
public Element transform(ElementPathBlock el) { PathBlock before = el.getPattern(); PathBlock after = TransformDeduplicatePatterns.deduplicate(before); Element result; if(after.equals(before)) { result = el; } else { ElementPathBlock tmp = new ElementPathBlock(); tmp.getPattern().addAll(after); result = tmp; } return result; } }
@Override public Element transform(ElementPathBlock el) { ElementPathBlock epb = new ElementPathBlock() ; boolean changed = false ; for (TriplePath p : el.getPattern()) { TriplePath p2 = transform(p) ; changed = changed || p != p2 ; epb.addTriplePath(p2) ; } if ( changed ) return epb ; return el ; }
@Override public void visit(ElementPathBlock el) { for (Iterator<TriplePath> iterator = el.patternElts(); iterator.hasNext();) { TriplePath tp = iterator.next(); if(inOptionalClause){ } else { if(tp.asTriple().equals(triple)){ ElementGroup parent = parentGroup.peek(); ElementPathBlock elementTriplesBlock = new ElementPathBlock(); elementTriplesBlock.addTriple(tp); ElementGroup eg = new ElementGroup(); eg.addElement(elementTriplesBlock); parent.addElement(new ElementFilter(new E_NotExists(eg))); iterator.remove(); } } } }
ElementPathBlock triplePattern = new ElementPathBlock(); Node typ = NodeFactory.createVariable("typ"); Node sometype = ...; // Assume OK // This represents rdfs:subClassOf+ Path pathSubClassOfPlus = PathFactory.pathOneOrMore1( PathFactory.pathLink(RDFS.subClassOf.asNode()) ); // This represents the SPARQL: ?typ rdfs:subClassOf+ sometype . TriplePath subClassOfPlus = new TriplePath(typ, subClassOfPlus, sometype) triplePattern.addTriplePath(subClassOfPlus); // ... One can also add regular Triple instances afterwards query.setQueryPattern(triplePattern);
final public Element TriplesBlock(ElementPathBlock acc) throws ParseException { if ( acc == null ) acc = new ElementPathBlock() ; TriplesSameSubjectPath(acc); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {