org.apache.jena.sparql.syntax.ElementOptional Java Examples
The following examples show how to use
org.apache.jena.sparql.syntax.ElementOptional.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TriplestoreResource.java From trellis with Apache License 2.0 | 5 votes |
/** * Fetch data for this resource. * * <p>This is equivalent to the following SPARQL query: * <pre><code> * SELECT ?predicate ?object ?binarySubject ?binaryPredicate ?binaryObject * WHERE { * GRAPH trellis:PreferServerManaged { * IDENTIFIER ?predicate ?object * OPTIONAL { * IDENTIFIER dc:hasPart ?binarySubject . * ?binarySubject ?binaryPredicate ?binaryObject * } * } * } * </code></pre> */ protected void fetchData() { LOGGER.debug("Fetching data from RDF datastore for: {}", identifier); final Var binarySubject = Var.alloc("binarySubject"); final Var binaryPredicate = Var.alloc("binaryPredicate"); final Var binaryObject = Var.alloc("binaryObject"); final Query q = new Query(); q.setQuerySelectType(); q.addResultVar(PREDICATE); q.addResultVar(OBJECT); q.addResultVar(binarySubject); q.addResultVar(binaryPredicate); q.addResultVar(binaryObject); final ElementPathBlock epb1 = new ElementPathBlock(); epb1.addTriple(create(toJena(identifier), PREDICATE, OBJECT)); final ElementPathBlock epb2 = new ElementPathBlock(); epb2.addTriple(create(toJena(identifier), toJena(DC.hasPart), binarySubject)); epb2.addTriple(create(toJena(identifier), type.asNode(), toJena(LDP.NonRDFSource))); epb2.addTriple(create(binarySubject, binaryPredicate, binaryObject)); final ElementGroup elg = new ElementGroup(); elg.addElement(epb1); elg.addElement(new ElementOptional(epb2)); q.setQueryPattern(new ElementNamedGraph(toJena(Trellis.PreferServerManaged), elg)); rdfConnection.querySelect(q, qs -> { final RDFNode s = qs.get("binarySubject"); final RDFNode p = qs.get("binaryPredicate"); final RDFNode o = qs.get("binaryObject"); nodesToTriple(s, p, o).ifPresent(t -> data.put(t.getPredicate(), t.getObject())); data.put(getPredicate(qs), getObject(qs)); }); }
Example #2
Source File: TriplePatternExtractor.java From NLIWOD with GNU Affero General Public License v3.0 | 5 votes |
@Override public void visit(final ElementOptional el) { optionalCount++; inOptionalClause = true; el.getOptionalElement().visit(this); inOptionalClause = false; }
Example #3
Source File: SPARQLExtFormatterElement.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void visit(ElementOptional el) { out.print("OPTIONAL"); out.incIndent(INDENT); out.newline(); visitAsGroup(el.getOptionalElement()); out.decIndent(INDENT); }
Example #4
Source File: RuleSystemToUnionQuery.java From quetzal with Eclipse Public License 2.0 | 5 votes |
@Override public void visit(ElementOptional opt) { Element elt = opt.getOptionalElement(); elt.visit(this); result = new ElementOptional(result); }
Example #5
Source File: OutputClauseNormalizer.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementOptional el) { LOG.warn("Should not reach this point"); }
Example #6
Source File: QueryPatternNormalizer.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementOptional el) { el.getOptionalElement().visit(this); result = new ElementOptional(result); }
Example #7
Source File: OutputClauseNormalizer.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementOptional el) { LOG.warn("Should not reach this point"); }
Example #8
Source File: SPARQLExtElementVisitorBase.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementOptional el) { }
Example #9
Source File: QueryPatternSimplification.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(ElementOptional opt) { opt.getOptionalElement().visit(this); result = new ElementOptional(result); }
Example #10
Source File: FindAllVariables.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(ElementOptional e) { e.getOptionalElement().visit(this); }
Example #11
Source File: StatisticsVisitor.java From IGUANA with GNU Affero General Public License v3.0 | votes |
public void startElement(ElementOptional el) {this.optional=true;}