本文整理了Java中org.apache.jena.sparql.algebra.Algebra
类的一些代码示例,展示了Algebra
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Algebra
类的具体详情如下:
包路径:org.apache.jena.sparql.algebra.Algebra
类名称:Algebra
[英]Utilities to produce SPARQL algebra
[中]生成SPARQL代数的实用程序
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
public static Op toOp(String queryStr) {
Query query = QueryFactory.create(queryStr, Syntax.syntaxSPARQL_11);
Op result = Algebra.compile(query);
return result;
}
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
public static SparqlView create(String name, QuadPattern quadPattern, Element element) {
Op tmp = Algebra.compile(element);
Op op = Algebra.toQuadForm(tmp);
SparqlView result = create(name, quadPattern, op);
return result;
}
代码示例来源:origin: apache/jena
static public QueryIterator exec(Op op, Dataset ds)
{
return exec(op, ds.asDatasetGraph()) ;
}
代码示例来源:origin: apache/jena
private static void outputAlgebraOptQuads(ServletOutputStream outStream, final Query query, boolean lineNumbers) throws IOException
{
outStream.println("<p>Alebgra, with general quads optimizations:</p>") ;
final Op op = Algebra.optimize(Algebra.toQuadForm(Algebra.compile(query))) ;
outputQueryOp(outStream, query, op, lineNumbers) ;
}
代码示例来源:origin: apache/jena
private static void outputAlgebraOpt(ServletOutputStream outStream, final Query query, boolean lineNumbers) throws IOException
{
outStream.println("<p>Alebgra, with general triple optimizations:</p>") ;
final Op op = Algebra.optimize(Algebra.compile(query)) ;
outputQueryOp(outStream, query, op, lineNumbers) ;
}
代码示例来源:origin: apache/jena
/** query->algebra/quads->OpAsQuery->query */
private static Query[] roundTripQueryQuad(String query) {
Query orig = QueryFactory.create(query, Syntax.syntaxSPARQL_11);
Op toReconstruct = Algebra.compile(orig);
toReconstruct = Algebra.toQuadForm(toReconstruct);
Query got = OpAsQuery.asQuery(toReconstruct);
Query[] r = { orig, got };
return r;
}
代码示例来源:origin: apache/jena
private void checkRename(String queryString, String opExpectedString)
{
Op opExpected = SSE.parseOp(opExpectedString) ;
queryString = "PREFIX : <http://example/>\n"+queryString ;
Query query = QueryFactory.create(queryString) ;
Op op = Algebra.compile(query) ;
Op opRenamed = TransformScopeRename.transform(op) ;
assertEquals(opExpected, opRenamed) ;
}
代码示例来源:origin: apache/jena
private static void test(String patternString, boolean optimize, String... strExpected)
{
Query q = QueryFactory.create("SELECT * WHERE "+patternString) ;
Op op = Algebra.compile(q) ;
if ( optimize )
op = Algebra.optimize(op) ;
op = Algebra.toQuadForm(op) ;
Op op2 = SSE.parseOp(StrUtils.strjoinNL(strExpected)) ;
assertEquals(op2, op) ;
}
}
代码示例来源:origin: apache/jena
protected Op createOp(Query query)
{
Op op = Algebra.compile(query) ;
return op ;
}
代码示例来源:origin: apache/jena
@Override
protected Op modifyOp(Op op)
{
op = super.modifyOp(op) ;
op = Algebra.toQuadForm(op) ;
return op ;
}
代码示例来源:origin: apache/jena
public static void checkOp(Query query, boolean optimizeAlgebra)
{
IndentedLineBuffer buff = new IndentedLineBuffer() ;
Op op = Algebra.compile(query) ;
if ( optimizeAlgebra )
op = Algebra.optimize(op) ;
WriterSSE.out(buff, op, query) ;
String str = buff.toString() ;
try {
Op op2 = SSE.parseOp(str) ;
if ( op.hashCode() != op2.hashCode() )
{
op.hashCode() ;
op2.hashCode() ;
dump(op, op2) ;
throw new QueryCheckException("reparsed algebra expression hashCode does not equal algebra from query") ;
}
if ( ! op.equals(op2) )
{
dump(op, op2) ;
throw new QueryCheckException("reparsed algebra expression does not equal query algebra") ;
}
} catch (SSEParseException | BuildException ex)
{
System.err.println(str);
throw ex ;
} // Breakpoint
}
代码示例来源:origin: apache/jena
protected Op op(String pattern, Mode mode) {
Op op = SSE.parseOp(pattern) ;
if ( mode == Mode.QUADS )
op = Algebra.toQuadForm(op) ;
else if ( mode == Mode.QUADBLOCKS )
op = Algebra.toQuadBlockForm(op) ;
return op ;
}
}
代码示例来源:origin: apache/jena
private static ResultSet exec(String pattern, Graph graph)
{
Op op = SSE.parseOp(pattern, pmap) ;
List<Var> vars = new ArrayList<>() ;
vars.addAll(OpVars.visibleVars(op)) ;
QueryIterator qIter = Algebra.exec(op, graph) ;
return ResultSetFactory.create(qIter, Var.varNames(vars)) ;
}
代码示例来源:origin: apache/jena
private static void check(Op opToOptimize, String opExpectedString) {
Op opOptimize = Algebra.optimize(opToOptimize) ;
Op opExpected = SSE.parseOp(opExpectedString) ;
if ( false ) {
// Hook for more detail during development.
boolean b = Objects.equals(opExpected, opOptimize) ;
if ( ! b ) {
System.err.println("** Input:");
System.err.print(opToOptimize) ;
System.err.println("** Expected:");
System.err.print(opExpected) ;
System.err.println("** Actual:");
System.err.print(opOptimize) ;
System.err.println("-------------------") ;
}
}
assertEquals(opExpected, opOptimize) ;
}
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
@Override
protected Binding computeNext() {
while(bindings.hasNext()) {
List<Binding> cand = bindings.next();
Binding r = null;
for(Binding b : cand) {
if(r == null) {
r = b;
} else {
boolean isCompatible = Algebra.compatible(r, b);
if(isCompatible) {
r = Algebra.merge(r, b);
} else {
continue;
}
}
}
return r;
}
return endOfData();
}
}
代码示例来源:origin: apache/jena
/** Apply static transformations to a query to optimize it */
public static Op optimize(Op op) { return optimize(op, null) ; }
代码示例来源:origin: apache/jena
@Override
public boolean containsCompatibleWithSharedDomain(Binding bindingLeft)
{
if ( commonVars.size() == 0 )
return false ;
for ( Binding bindingRight: table )
{
if ( hasCommonVars(bindingLeft, bindingRight)
&& Algebra.compatible(bindingLeft, bindingRight) )
return true ;
}
return false ;
}
代码示例来源:origin: apache/jena
if ( Algebra.disjoint(bindingLeft, bindingRight) )
if ( ! Algebra.compatible(bindingLeft, bindingRight) )
代码示例来源:origin: SmartDataAnalytics/jena-sparql-api
public static void main(String[] args) {
//String sA = "Select * { ?s ?p ?o . Filter((?s || ?p) && ?o) . }";
//String sA = "Select * { ?s ?p ?o . Filter((?s || ?p) && !(?o || ?g)) . }";
String sA = "Select * { ?s ?p ?o . Filter(?o != <http://Person>). Optional { { ?x ?y ?z . Filter(?x != <http://x> && ?x = ?y) . } Union { ?x a ?y . Filter(?x = <http://x>) . } } . }";
//String sA = "Select * { ?s ?p ?o . Filter(!(?s = ?p || ?p = ?o && ?s = ?o || ?o = ?s)) . }";
//String sA = "Select * { ?s ?p ?o . Filter(!(?s = ?p || ?j = <http://x>)) . }";
Query qA = QueryFactory.create(sA);
Op opA = Algebra.compile(qA);
opA = Algebra.toQuadForm(opA);
System.out.println(opA);
// How to deal with union? variables appearing in them
//System.out.println(opA.getClass());
ExprList exprs = FilterUtils.collectExprs(opA, new ExprList());
ExprList proc = eval(exprs);
System.out.println(proc);
List<ExprList> clauses = dnfToClauses(proc);
System.out.println("Mentioned vars:" + proc.getVarsMentioned());
System.out.println("Clauses: " + clauses);
}
代码示例来源:origin: apache/jena
@Test
public void testTable2() {
// JENA-1468 : op to string and back.
String qs = "SELECT * WHERE { ?x ?p ?z . VALUES ?y { } }" ;
Query query = QueryFactory.create(qs);
Op op = Algebra.compile(query);
String x = op.toString();
Op op1 = SSE.parseOp(x);
Query query2 = OpAsQuery.asQuery(op1);
assertEquals(query, query2);
}
内容来源于网络,如有侵权,请联系作者删除!