比较Jena中的两个SPARQL查询
我想知道两个SPARQL查询在逻辑上是否等价,例如,假设我有两个查询,如下所示,如何知道它们是否等价比较Jena中的两个SPARQL查询,sparql,jena,Sparql,Jena,我想知道两个SPARQL查询在逻辑上是否等价,例如,假设我有两个查询,如下所示,如何知道它们是否等价 String query1= "SELECT ?name where { <http://www.example.com/P500> a <http://www.example.com/Parking>; " + "<http://www.example.com/name> ?name .}"; String
String query1= "SELECT ?name where { <http://www.example.com/P500> a <http://www.example.com/Parking>; " +
"<http://www.example.com/name> ?name .}";
String query2= "SELECT ?name where { <http://www.example.com/P500> <http://www.example.com/name> ?name;" +
" a <http://www.example.com/Parking> .}";
如果你比较两个优化的代数表达式,它可能会起作用?但是我想,至少变量名必须是相同的,否则你必须解决同构问题。我刚刚更新了代码,我试过了,但没有成功。三重模式的顺序不同。相等,或查询(Query.equals)或代数不是“逻辑等价的”,而是基于语法等价。@AndyS,是的,我特意将三元组按不同的顺序排列,以查看是否可以验证逻辑等价性
System.out.println("Compare query pattern");
System.out.println(q1.getQueryPattern().equalTo(q2.getQueryPattern(),null));
Op qop1 = Algebra.compile(q1) ;
Op qop2 = Algebra.compile(q2) ;
System.out.println("Compare query operator");
System.out.println(qop1.equalTo(qop2,null));