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);
public static ElementPathBlock createElement(TriplePath triplePath) { ElementPathBlock result = new ElementPathBlock(); result.addTriplePath(triplePath); return result; }
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); }
@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); }
@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 BinaryRelation from(org.apache.jena.sparql.path.Path path) { TriplePath tp = new TriplePath(Vars.s, path, Vars.o); ElementPathBlock e = new ElementPathBlock(); e.addTriplePath(tp); BinaryRelation result = new BinaryRelationImpl(e, Vars.s, Vars.o); 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 ; }
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) ; }
@Override public void visit(OpPath opPath) { ElementPathBlock epb = new ElementPathBlock() ; epb.addTriplePath(opPath.getTriplePath()) ; ElementGroup g = currentGroup() ; g.addElement(epb) ; }
final public void ObjectPath(Node s, Node p, Path path, TripleCollector acc) throws ParseException { Node o ; ElementPathBlock tempAcc = new ElementPathBlock() ; int mark = tempAcc.mark() ; o = GraphNodePath(tempAcc); insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
final public void ObjectPath(Node s, Node p, Path path, TripleCollector acc) throws ParseException { Node o ; ElementPathBlock tempAcc = new ElementPathBlock() ; int mark = tempAcc.mark() ; o = GraphNodePath(tempAcc); insert(tempAcc, mark, s, p, path, o) ; insert(acc, tempAcc) ; }
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) ; }
/** * Add a graph to the where clause. * * Short hand for graph { s, p, o } * * @param graph * The name of the graph. * @param subQuery * A triple path to add to the graph. */ public void addGraph(Node graph, TriplePath subQuery) { ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(subQuery); getClause().addElement(new ElementNamedGraph(graph, epb)); }
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; } }
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; } }
/** * Add an optional triple to the where clause * * @param t * The triple path to add. * @throws IllegalArgumentException * If the triple is not a valid triple for a where clause. */ public void addOptional(TriplePath t) throws IllegalArgumentException { testTriple(t); ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(t); ElementOptional opt = new ElementOptional(epb); getClause().addElement(opt); }
/** * Add an optional triple to the where clause * * @param t * The triple path to add. * @throws IllegalArgumentException * If the triple is not a valid triple for a where clause. */ public void addOptional(TriplePath t) throws IllegalArgumentException { testTriple(t); ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(t); ElementOptional opt = new ElementOptional(epb); getClause().addElement(opt); }
/** * Add an optional triple to the where clause * * @param t * The triple path to add. * @throws IllegalArgumentException * If the triple is not a valid triple for a where clause. */ public void addOptional(TriplePath t) throws IllegalArgumentException { testTriple(t); ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(t); ElementOptional opt = new ElementOptional(epb); getClause().addElement(opt); }
private Element process(BasicPattern pattern) { // The different SPARQL versions (1.0, 1.1) use different internal // structures for BGPs. if ( query.getSyntax() == Syntax.syntaxSPARQL_10 ) { ElementTriplesBlock e = new ElementTriplesBlock() ; for ( Triple t : pattern ) // Leave bNode variables as they are // Query serialization will deal with them. e.addTriple(t) ; return e ; } if ( query.getSyntax() == Syntax.syntaxSPARQL_11 || query.getSyntax() == Syntax.syntaxARQ ) { ElementPathBlock e = new ElementPathBlock() ; for ( Triple t : pattern ) // Leave bNode variables as they are // Query serialization will deal with them. e.addTriple(t) ; return e ; } throw new ARQInternalErrorException("Unrecognized syntax: " + query.getSyntax()) ; }