生成增量SPARQL查询 [英] Generate an incremental SPARQL query

查看:117
本文介绍了生成增量SPARQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以动态生成SPARQL查询吗?
我想做的事情是这样的:
如果我有一个DBpedia资源r1和另一个DBpedia资源r2,则
此查询

is there any way to generate a SPARQL query in a dynamic way? what I'm trying to do is some thing like this: if I have a DBpedia resource r1 and another DBpedia resource r2, this query

SELECT * WHERE { <r1> ?pre <r2> }

将返回两个资源
与该查询之间的谓词

will return the predicate between the 2 resources and this query

SELECT * WHERE { <r1> ?pre1 ?obj1 . ?obj1 ?pre2 <r2> }

将返回这两个资源之间的所有谓词和对象(分两步)
等等,在
上,我试图以这种方式构建此查询,即它会自动增加两个资源之间的对象和谓词的数量(例如4个步骤)?

will return all the predicates and object between these two resources ( in two steps) and so on I'm trying to build this query in such a way that it will automatically increase the number of objects and predicates between the two resources (for example in 4 steps)?

推荐答案

我想出了解决这个问题的方法。
这是我的解决方案:

I figure out how to solve this problem.. here is my solution:

private String completeQuery(String coreQuery){
String completeQuery = "";
completeQuery += "SELECT * WHERE {"+ "\n";
completeQuery += coreQuery + "\n";
completeQuery =completeQuery + "}" + "\n" +"limit 5" ;
return completeQuery;}
public String link(String object1, String object2, int distance){
if(distance == 1){
    String Quer = "<http://dbpedia.org/resource/"+object1+">" + " ?pre1 " +"<http://dbpedia.org/resource/"+object2+">";
    return completeQuery(Quer);
} 
else {
    String query = "<http://dbpedia.org/resource/"+object1+">" + " ?pre1 ?obj1 " + ".\n";
    for(int i = 1; i < distance-1; i++){
        query += "?obj" + i + " ?pre" + (i+1) + " ?obj" + (i+1) + ".\n" ;

    }
    query  += "?obj" + (distance-1) + " ?pre" + distance + " " + "<http://dbpedia.org/resource/"+object2+">";
    return completeQuery(query);
}}

这篇关于生成增量SPARQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆