Java SPARQL ARQ查询执行

Java SPARQL ARQ查询执行,java,sparql,jena,lubm,Java,Sparql,Jena,Lubm,因此,我有一段Jena代码,它基本上是尝试使用TripleElementTriplesBlock构建查询,最后使用QueryFactory.make()。现在我已经设置了一个本地Virtuoso实例,因此我的SPARQL端点是localhost。i、 e.只是http://localhost:8890/sparql。我正在查询的RDF是从生成的。现在,我试图根据一些条件替换查询模式中的三元组。i、 例如,如果查询由两个BGP或三重模式组成,并且其中一个三重模式的结果为零,那么我想将该三重模式更改

因此,我有一段Jena代码,它基本上是尝试使用
Triple
ElementTriplesBlock
构建查询,最后使用
QueryFactory.make()
。现在我已经设置了一个本地Virtuoso实例,因此我的SPARQL端点是localhost。i、 e.只是
http://localhost:8890/sparql
。我正在查询的RDF是从生成的。现在,我试图根据一些条件替换查询模式中的三元组。i、 例如,如果查询由两个BGP或三重模式组成,并且其中一个三重模式的结果为零,那么我想将该三重模式更改为其他模式。我如何在耶拿实现这一目标。我的代码看起来像

//Create your triples
Triple pattern1 = Triple.create(Var.alloc("X"),Node.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),Node.createURI("http://swat.cse.lehigh.edu/onto/univ-bench.owl#AssociateProfessor"));
Triple pattern = Triple.create(Var.alloc("X"), Node.createURI("http://swat.cse.lehigh.edu/onto/univ-bench.owl#emailAddress"), Var.alloc("Y2"));

ElementTriplesBlock block = new ElementTriplesBlock();
block.addTriple(pattern1);
block.addTriple(pattern);

ElementGroup body = new ElementGroup();
body.addElement(block); 

//Build a Query here

Query q = QueryFactory.make();
q.setPrefix("ub", "http://swat.cse.lehigh.edu/onto/univ-bench.owl#");

q.setQueryPattern(body);

q.setQuerySelectType();
q.addResultVar("X");

//?X ub:emailAddress ?Y2 .  
//Query to String
System.out.println(q.toString());



QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", q);
Op op = Algebra.optimize(Algebra.compile(q));
System.out.println(op.toString());
(project (?X)
  (bgp
    (triple ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#AssociateProfessor>)
    (triple ?X <http://swat.cse.lehigh.edu/onto/univ-bench.owl#emailAddress> ?Y2)
  ))
因此,为了清楚起见,我可以通过使用
Op=Algebra.optimize(Algebra.compile(q))
行以关系代数的形式查看BGP。输出看起来像

//Create your triples
Triple pattern1 = Triple.create(Var.alloc("X"),Node.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),Node.createURI("http://swat.cse.lehigh.edu/onto/univ-bench.owl#AssociateProfessor"));
Triple pattern = Triple.create(Var.alloc("X"), Node.createURI("http://swat.cse.lehigh.edu/onto/univ-bench.owl#emailAddress"), Var.alloc("Y2"));

ElementTriplesBlock block = new ElementTriplesBlock();
block.addTriple(pattern1);
block.addTriple(pattern);

ElementGroup body = new ElementGroup();
body.addElement(block); 

//Build a Query here

Query q = QueryFactory.make();
q.setPrefix("ub", "http://swat.cse.lehigh.edu/onto/univ-bench.owl#");

q.setQueryPattern(body);

q.setQuerySelectType();
q.addResultVar("X");

//?X ub:emailAddress ?Y2 .  
//Query to String
System.out.println(q.toString());



QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", q);
Op op = Algebra.optimize(Algebra.compile(q));
System.out.println(op.toString());
(project (?X)
  (bgp
    (triple ?X <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://swat.cse.lehigh.edu/onto/univ-bench.owl#AssociateProfessor>)
    (triple ?X <http://swat.cse.lehigh.edu/onto/univ-bench.owl#emailAddress> ?Y2)
  ))
(项目(?X)
(bgp
(三倍X)
(三倍X?Y2)
))

现在我该如何评估每个三元组的执行情况?在本例中,如果我只想在查询模式执行的每个步骤中打印结果的数量,我将如何做?我确实读过一些例子。我想必须使用
操作执行器和
查询执行器,但我不确定它们是如何组合在一起的。在本例中,我只想遍历每个基本图形模式,然后输出基本图形模式及其从端点返回的结果数。任何帮助或指点都将不胜感激。

这本书中有一条很长的线索users@jena.pache.org,主题“如何在给定SPARQL查询的情况下一致地删除三重模式?”谢谢@AndyS,我现在来检查一下。现在我的直觉是我使用Algebra.compile和Algebra.optimize来获得三元组的求值顺序。也许用不透明的。虽然不确定,但我现在将查看论坛。