org.apache.jena.sparql.syntax.ElementBind Java Examples
The following examples show how to use
org.apache.jena.sparql.syntax.ElementBind.
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: ElementTransformSPARQLStarTest.java From RDFstarTools with Apache License 2.0 | 6 votes |
protected void checkForEquivalence( ElementGroup expectedEG, ElementGroup testEG ) { assertEquals( expectedEG.size(), testEG.size() ); assertEquals( expectedEG.get(0).getClass(), testEG.get(0).getClass() ); if ( expectedEG.get(0) instanceof ElementPathBlock ) { final ElementPathBlock expectedEPB = (ElementPathBlock) expectedEG.get(0); final ElementPathBlock convertedEPB = (ElementPathBlock) testEG.get(0); checkForEquivalence( expectedEPB, convertedEPB ); } else if ( expectedEG.get(0) instanceof ElementBind ) { final ElementBind expectedEB = (ElementBind) expectedEG.get(0); final ElementBind convertedEB = (ElementBind) testEG.get(0); checkForEquivalence( expectedEB, convertedEB ); } else fail(); }
Example #2
Source File: ElementTransformSPARQLStar.java From RDFstarTools with Apache License 2.0 | 6 votes |
@Override public Element transform( ElementBind eb, Var v, Expr expr2 ) { if ( ( eb.getExpr() instanceof NodeValue ) && ( ((NodeValue) eb.getExpr()).getNode() instanceof Node_Triple ) ) { final NodeValue nv = (NodeValue) eb.getExpr(); final Node_Triple nt = (Node_Triple) nv.getNode(); final Triple tp = nt.get(); final ElementPathBlock epb = new ElementPathBlock(); unNestBindClause(tp, epb, v); return epb; } else return super.transform(eb, v, expr2); }
Example #3
Source File: ParserSPARQLStarTest.java From RDFstarTools with Apache License 2.0 | 6 votes |
protected Triple getBindTriplePattern( String queryString ) { final ElementGroup eg = getElementGroup(queryString); assertEquals( 1, eg.size() ); assertTrue( "unexpected type (" + eg.get(0).getClass() + ")", eg.get(0) instanceof ElementBind ); final ElementBind eb = (ElementBind) eg.get(0); assertTrue( "unexpected type (" + eb.getExpr().getClass() + ")", eb.getExpr() instanceof NodeValue ); final Node n = ( (NodeValue) eb.getExpr() ).getNode(); assertTrue( "unexpected type (" + n.getClass() + ")", n instanceof Node_Triple ); return ( (Node_Triple) n ).get(); }
Example #4
Source File: NodeExprNormalizer.java From sparql-generate with Apache License 2.0 | 6 votes |
/** * {@inheritDoc */ @Override public Object visit(Node_List node) { if (cache.containsKey(node)) { result = cache.get(node); return null; } if (node.getExpr().isVariable()) { result = node; return null; } Var var = Var.alloc(node.getLabel()); final Expr expr = nzer.normalize(node.getExpr()); bindings.add(new ElementBind(var, expr)); Node_List nzedList = new Node_List(new ExprVar(var)); cache.put(node, nzedList); this.result = nzedList; return null; }
Example #5
Source File: SelectExtractionVisitor.java From sparql-generate with Apache License 2.0 | 6 votes |
@Override public void visitBindingClauses(SPARQLExtQuery query) { if (query.isSelectType()) { return; } if (query.hasAggregators() || query.hasGroupBy()) { return; } for (Element el : query.getBindingClauses()) { isDummyQuery = false; if (el instanceof ElementIterator) { ElementIterator elementIterator = (ElementIterator) el; output.addProjectVars(elementIterator.getVars()); } else if (el instanceof ElementSource) { ElementSource elementSource = (ElementSource) el; output.addResultVar(elementSource.getVar()); } else if (el instanceof ElementBind) { ElementBind elementBind = (ElementBind) el; output.addResultVar(elementBind.getVar()); } else { throw new UnsupportedOperationException("should not reach" + " this point"); } } }
Example #6
Source File: QueryPatternNormalizer.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void visit(ElementBind el) { final ExprNormalizer enzer = new ExprNormalizer(); final Var var = el.getVar(); final Expr nzed = enzer.normalize(el.getExpr()); result = new ElementBind(var, nzed); }
Example #7
Source File: SPARQLExtFormatterElement.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void visit(ElementBind el) { out.print("BIND("); SPARQLExtFmtExprSPARQL v = new SPARQLExtFmtExprSPARQL(out, context); v.format(el.getExpr()); out.print(" AS "); out.print("?" + el.getVar().getVarName()); out.print(")"); }
Example #8
Source File: QueryXExprNormalizer.java From sparql-generate with Apache License 2.0 | 5 votes |
private void appendPostSelect(SPARQLExtQuery query, NodeExprNormalizer nenzer) { if (!nenzer.hasBindings()) { return; } for (Element element : nenzer.getBindings()) { if (element instanceof ElementBind) { ElementBind b = (ElementBind) element; query.addPostSelect(b.getVar(), b.getExpr()); } } }
Example #9
Source File: PlanFactory.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * Makes the plan for a SPARQL BIND clause. * * @param elementBind the SPARQL BIND * @return - */ private static BindOrSourcePlan makeBindPlan( final ElementBind elementBind) throws SPARQLExtException { Objects.requireNonNull(elementBind, "The Bind element must not be null"); Var var = elementBind.getVar(); Expr expr = elementBind.getExpr(); Objects.requireNonNull(var, "The source must not be null"); Objects.requireNonNull(expr, "The expression must not be null."); return new BindPlan(expr, var); }
Example #10
Source File: SelectQueryPartialCopyVisitor.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void visitFunctionExpression(SPARQLExtQuery query) { Var var = Var.alloc("out"); ElementBind bind = new ElementBind(var, query.getFunctionExpression()); output.setQueryPattern(bind); output.addResultVar(var); }
Example #11
Source File: SelectExtractionVisitor.java From sparql-generate with Apache License 2.0 | 5 votes |
@Override public void visitFunctionExpression(SPARQLExtQuery query) { Var var = Var.alloc("out"); ElementBind bind = new ElementBind(var, query.getFunctionExpression()); output.setQueryPattern(bind); output.addResultVar(var); isDummyQuery = false; }
Example #12
Source File: FindAllVariables.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(ElementBind e) { addVar(e.getVar()); ExprVars.varsMentioned(vars, e.getExpr()); }
Example #13
Source File: RuleSystemToUnionQuery.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(ElementBind eb) { org.apache.jena.sparql.expr.Expr expr = eb.getExpr().copySubstitute(this); Var v = eb.getVar(); result = new ElementBind(v, expr); }
Example #14
Source File: PlanFactory.java From sparql-generate with Apache License 2.0 | 4 votes |
/** * Makes a {@code RootPlan} for a query. * * @param query the Query. * @return the RootPlan. */ private static RootPlan make(final SPARQLExtQuery query) { Objects.requireNonNull(query, "The query must not be null"); if (query.hasEmbeddedExpressions()) { LOG.debug("Query has embedded expressions:\n" + query); String qs = query.toString(); SPARQLExtQuery query2; if (query.isSubQuery()) { query2 = (SPARQLExtQuery) ParserSPARQLExt.parseSubQuery(query, qs); query2.normalizeXExpr(); query2.normalizeAggregates(); } else { query2 = (SPARQLExtQuery) QueryFactory.create(qs, SPARQLExt.SYNTAX); query2.normalizeXExpr(); query2.normalizeBNode(); query2.normalizeAggregates(); } return make(query2); } LOG.trace("Making plan for query without embedded expressions\n" + query); DatasetDeclarationPlan datasetDeclarationPlan = new DatasetDeclarationPlan(query); List<BindingsClausePlan> iteratorAndSourcePlans = new ArrayList<>(); if (query.hasBindingClauses()) { for (Element el : query.getBindingClauses()) { BindingsClausePlan iteratorOrSourcePlan; if (el instanceof ElementIterator) { ElementIterator elementIterator = (ElementIterator) el; iteratorOrSourcePlan = makeIteratorPlan(elementIterator); } else if (el instanceof ElementSource) { ElementSource elementSource = (ElementSource) el; iteratorOrSourcePlan = makeSourcePlan(elementSource); } else if (el instanceof ElementBind) { ElementBind elementBind = (ElementBind) el; iteratorOrSourcePlan = makeBindPlan(elementBind); } else { throw new UnsupportedOperationException("should not reach" + " this point"); } iteratorAndSourcePlans.add(iteratorOrSourcePlan); } } /* * TEMPLATE queries are translated into a SELECT with project * variable ?out. */ final SelectPlan selectPlan = makeSelectPlan(query); if (query.isTemplateType()) { final TemplatePlan templatePlan = makeTemplatePlan(query); return new RootPlan( query, datasetDeclarationPlan, iteratorAndSourcePlans, selectPlan, templatePlan); } if (query.isGenerateType()) { final GeneratePlan generatePlan; if (query.hasGenerateClause()) { generatePlan = makeGenerateFormPlan(query); } else { generatePlan = makeGenerateNamedPlan(query); } return new RootPlan( query, datasetDeclarationPlan, iteratorAndSourcePlans, selectPlan, generatePlan); } return new RootPlan(query, datasetDeclarationPlan, iteratorAndSourcePlans, selectPlan); }
Example #15
Source File: SPARQLExtElementVisitorBase.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementBind el) { }
Example #16
Source File: OutputClauseNormalizer.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementBind el) { LOG.warn("Should not reach this point"); }
Example #17
Source File: OutputClauseNormalizer.java From sparql-generate with Apache License 2.0 | 4 votes |
@Override public void visit(ElementBind el) { LOG.warn("Should not reach this point"); }
Example #18
Source File: ElementTransformSPARQLStarTest.java From RDFstarTools with Apache License 2.0 | 4 votes |
protected void checkForEquivalence( ElementBind expectedEB, ElementBind testEB ) { assertTrue( expectedEB.equalTo(testEB,null) ); }
Example #19
Source File: QueryPatternSimplification.java From quetzal with Eclipse Public License 2.0 | 2 votes |
@Override public void visit(ElementBind e) { result = e; }