我正在尝试从 linkedgeodata.org 查询某个国家/地区内各州的 RDF 数据。在 RDF 中,它表示为:
<http://linkedgeodata.org/triplify/node1055351027> <http://linkedgeodata.org/property/is_in%3Acountry> "LT" .
正如您可能注意到的,谓词包含转义冒号,因此“%3A”而不是“:” 我无法为此找到合适的 SPARQL 查询,这些是我的一些尝试
?node lgdp:is_in "LT".
?node lgdp:is_in:country "LT".
?node lgdp:is_in%3Acountry "LT".
?node lgdp:is_in\u003Acountry "LT".
?node lgdp:is_in"\u003A"country "LT".
我使用 virtuoso 的开源版本作为我的三重存储,这是我收到的除第一种形式之外的所有错误消息:
Virtuoso 37000 Error SP030: SPARQL compiler, line 0: Invalid character in SPARQL expression at '\'
SPARQL query:
define sql:big-data-const 0
#output-format:text/html
define input:default-graph-uri PREFIX lgdo:
PREFIX lgdp:
PREFIX lgd:
PREFIX pos:
PREFIX rdf:
SELECT ?node, ?label
Where {
?node a lgdo:State .
?node lgdp:is_in\u003Acountry "LT".
?node rdfs:label ?label .
}
最佳答案
使用命名空间时不允许使用 %
编码的字符,在这种情况下,您必须直接使用完整谓词(不带命名空间)。以下查询有效:
Prefix lgdo:<http://linkedgeodata.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?node, ?label
Where {
?node a lgdo:State .
?node <http://linkedgeodata.org/property/is_in%3Acountry> "LT".
?node rdfs:label ?label
}
查看结果 here .
关于rdf - 谓词中带有冒号的 SPARQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5820593/