使用WikiPageRedirects的sparql [英] sparql using wikiPageRedirects
问题描述
我正在使用sparql查找实体的位置。我有dbpedia-spootlight的网址,想为他们找到位置。所以我正在使用的查询是:
I am using sparql to find a location of entity. I have urls from dbpedia-spootlight and want to find location for them. So the query I am using is:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT *
WHERE { ?uri rdfs:label ?label .
OPTIONAL { ?uri geo:lat ?lat . ?uri geo:long ?long } .
OPTIONAL { ?uri dbpedia-owl:country ?dbpediaContry . ?dbpediaContry dbpprop:cctld ?ccTLD } .
FILTER (?uri = <URL> && lang(?label) = "en" ) }
,直到我获得以下网址,这都很好: http://dbpedia.org / resource / Valencia,_Spain 。
它具有指向 http://dbpedia.org/resource/Valencia 的WikiPageRedirects,并且没有其他数据。
我迷路了,我该如何构建查询来检查带有重定向的案例。
and it was fine until I have got this url: http://dbpedia.org/resource/Valencia,_Spain . It has wikiPageRedirects to http://dbpedia.org/resource/Valencia and no other data. I have got lost how could i build query to check cases with redirects.
有人可以帮助我吗?
推荐答案
尝试更改查询的第一部分以使用 UNION
例如
Try changing the first part of your query to use a UNION
e.g.
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT *
WHERE
{
{
?uri rdfs:label ?label .
}
UNION
{
[] dbo:wikiPageRedirects ?uri .
?uri rdfs:label ?label .
}
OPTIONAL
{
?uri geo:lat ?lat ;
geo:long ?long
}
OPTIONAL
{
?uri dbo:country ?dbpediaContry .
?dbpediaContry dbp:cctld ?ccTLD
}
FILTER (SAMETERM(?uri, <URL>) && lang(?label) = "en" )
}
UNION
可让您查找事物包含URI的对象和通过重定向包含URI的对象,然后再应用其余查询。注意,我还更改了您的 FILTER
以使用 SAMETERM()
,这将使查询更快。
The UNION
allow you to find things that have a URI and those that have a URI via a redirect before then applying the rest of your query. Note I also changed your FILTER
to use SAMETERM()
which should make the query faster.
通常,如果您在进行此类 FILTER
设置常量的查询时,强烈建议您替换将?uri
变量与< URL>
一起使用,应该会看到更好的性能
In general if you have this kind of query where you are doing that sort of a FILTER
to set a constant I would strongly suggest just replacing all uses of the ?uri
variable with <URL>
instead which should see much better performance
这篇关于使用WikiPageRedirects的sparql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!