询问是否存在SPARQL资源 [英] Ask if SPARQL resource exists
问题描述
检查SPARQL资源是否存在的好方法是什么?
我正在搜索相当于触发HTTP GET请求到例如 http://dbpedia.org/resource/Game_of_Thrones
并检查HTTP状态代码,但我想通过SPARQL查询来完成。
What is a good way to check if a SPARQL resource exists?
I'm searching for the equivalent of firing a HTTP GET request to e.g. http://dbpedia.org/resource/Game_of_Thrones
and check the HTTP status code but I'd like to do it with a SPARQL query.
我想到了这样的事情:
ASK {<http://dbpedia.org/resource/Game_of_Thrones> a <http://dbpedia.org/resource/>}
我确定是执行此操作的好方法,但我找不到它。
I'm sure there is a good way to do this but I can't find it.
注意:我不想检查是否存在一个特定的三元组。我只想知道资源是否存在。
Note: I don't want to check for the existance of a specific triple. I just want to know if a resource exists.
推荐答案
SPARQL是RDF查询语言。 RDF三元组由主语,谓语和宾语组成。
SPARQL is an RDF query language. An RDF triple consists of subject, predicate and object.
您只需使用 UNION
作为析取,检查这些位置中是否存在URI。
You just need to check if an URI is present in any of these positions, using UNION
as disjunction.
ASK {
VALUES (?r) { (dbr:Game_of_Thrones) }
{ ?r ?p ?o }
UNION
{ ?s ?r ?o }
UNION
{ ?s ?p ?r }
}
尽管SPARQL规范不不允许在谓词位置 []
,DBpedia(即为DBpedia端点提供服务的Virtuoso服务器)理解这一点:
Although the SPARQL specification doesn't allow []
in predicate position, DBpedia (i.e., the Virtuoso server serving the DBpedia endpoint) understands this:
ASK {
VALUES (?r) { (dbr:Game_of_Thrones) }
{ ?r [] [] }
UNION
{ [] ?r [] }
UNION
{ [] [] ?r }
}
这篇关于询问是否存在SPARQL资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!