public ElementPathBlock(BasicPattern bgp) { for ( Triple t : bgp.getList() ) addTriple(t) ; }
public static ElementPathBlock createElementPath(Iterable<TriplePath> it) { ElementPathBlock result = new ElementPathBlock(); for(TriplePath tp : it) { result.addTriple(tp); } return result; }
if (lst.isEmpty()) { ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(t); eg.addElement(epb); } else { } else if (e instanceof ElementPathBlock) { ElementPathBlock epb = (ElementPathBlock) e; epb.addTriple(t); } else { ElementPathBlock etb = new ElementPathBlock(); etb.addTriple(t); eg.addElement(etb);
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; }
/** * 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)); }
/** * 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)); }
/** * 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); }
/** * 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()) ; }
private Element process(BasicPattern pattern) { // The different SPARQL versions 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()) ; }
@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(); } } } }
@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(); } } } }
public static Query constructBySubject(Node s) { Triple triple = new Triple(s, p, o); BasicPattern basicPattern = new BasicPattern(); basicPattern.add(triple); Template template = new Template(basicPattern); ElementGroup elementGroup = new ElementGroup(); ElementPathBlock pathBlock = new ElementPathBlock(); elementGroup.addElement(pathBlock); pathBlock.addTriple(triple); Query query = new Query(); query.setQueryConstructType(); query.setConstructTemplate(template); query.setQueryPattern(elementGroup); return query; }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * SELECT ?object * WHERE { * GRAPH trellis:PreferServerManaged { ?object dc:isPartOf IDENTIFIER } * } * </code></pre> */ private Stream<Quad> fetchContainmentQuads() { if (getInteractionModel().getIRIString().endsWith("Container")) { final Query q = new Query(); q.setQuerySelectType(); q.addResultVar(OBJECT); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(create(OBJECT, rdf.asJenaNode(DC.isPartOf), rdf.asJenaNode(identifier))); final ElementNamedGraph ng = new ElementNamedGraph(rdf.asJenaNode(Trellis.PreferServerManaged), epb); final ElementGroup elg = new ElementGroup(); elg.addElement(ng); q.setQueryPattern(elg); final Stream.Builder<Quad> builder = builder(); rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(LDP.PreferContainment, identifier, LDP.contains, getObject(qs)))); return builder.build(); } return Stream.empty(); }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * SELECT ?subject ?predicate ?object * WHERE { GRAPH fromGraphName { ?subject ?predicate ?object } } * </code></pre> */ private Stream<Quad> fetchAllFromGraph(final String fromGraphName, final IRI toGraphName) { final Query q = new Query(); q.setQuerySelectType(); q.addResultVar(SUBJECT); q.addResultVar(PREDICATE); q.addResultVar(OBJECT); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(create(SUBJECT, PREDICATE, OBJECT)); final ElementGroup elg = new ElementGroup(); elg.addElement(new ElementNamedGraph(createURI(fromGraphName), epb)); q.setQueryPattern(elg); final Stream.Builder<Quad> builder = builder(); rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(toGraphName, getSubject(qs), getPredicate(qs), getObject(qs)))); return builder.build(); }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * SELECT ?subject ?predicate ?object * WHERE { GRAPH fromGraphName { ?subject ?predicate ?object } } * </code></pre> */ private Stream<Quad> fetchAllFromGraph(final String fromGraphName, final IRI toGraphName) { final Query q = new Query(); q.setQuerySelectType(); q.addResultVar(SUBJECT); q.addResultVar(PREDICATE); q.addResultVar(OBJECT); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(create(SUBJECT, PREDICATE, OBJECT)); final ElementGroup elg = new ElementGroup(); elg.addElement(new ElementNamedGraph(createURI(fromGraphName), epb)); q.setQueryPattern(elg); final Stream.Builder<Quad> builder = builder(); rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(toGraphName, getSubject(qs), getPredicate(qs), getObject(qs)))); return builder.build(); }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * WITH trellis:PreferServerManaged * DELETE { IDENTIFIER dc:modified ?time } * INSERT { IDENTIFIER dc:modified TIME } * WHERE { IDENTIFIER dc:modified ?time } . * </code></pre></p> */ private UpdateRequest buildUpdateModificationRequest(final IRI identifier, final Literal time) { final UpdateRequest req = new UpdateRequest(); final Var modified = Var.alloc(MODIFIED); final UpdateDeleteInsert modify = new UpdateDeleteInsert(); modify.setWithIRI(rdf.asJenaNode(PreferServerManaged)); modify.getDeleteAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); modify.getInsertAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), rdf.asJenaNode(time))); final ElementGroup eg = new ElementGroup(); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); eg.addElement(epb); modify.setElement(eg); req.add(modify); return req; }
/** * This code is equivalent to the SPARQL query below. * * <p><pre><code> * WITH trellis:PreferServerManaged * DELETE { IDENTIFIER dc:modified ?time } * INSERT { IDENTIFIER dc:modified TIME } * WHERE { IDENTIFIER dc:modified ?time } . * </code></pre></p> */ private UpdateRequest buildUpdateModificationRequest(final IRI identifier, final Literal time) { final UpdateRequest req = new UpdateRequest(); final Var modified = Var.alloc(MODIFIED); final UpdateDeleteInsert modify = new UpdateDeleteInsert(); modify.setWithIRI(rdf.asJenaNode(PreferServerManaged)); modify.getDeleteAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); modify.getInsertAcc().addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), rdf.asJenaNode(time))); final ElementGroup eg = new ElementGroup(); final ElementPathBlock epb = new ElementPathBlock(); epb.addTriple(triple(rdf.asJenaNode(identifier), rdf.asJenaNode(DC.modified), modified)); eg.addElement(epb); modify.setElement(eg); req.add(modify); return req; }