我有一个SPARQL查询,我想消除所有消歧资源。我怎样才能做到这一点?这是我的问题:
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select distinct ?Nom ?resource ?url where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
FILTER (langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
}
答案 0 :(得分:2)
您可以为查询添加以下前缀和过滤器:
prefix dbo: <http://dbpedia.org/ontology/>
filter not exists {
?resource dbo:wikiPageRedirects*/dbo:wikiPageDisambiguates ?dis
}
这表示排除重定向到消除某些文章消歧的资源的资源和资源。这会给你一个这样的查询:
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbo: <http://dbpedia.org/ontology/>
select distinct ?Nom ?resource ?url where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
FILTER (langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
filter not exists {
?resource dbo:wikiPageRedirects*/dbo:wikiPageDisambiguates ?dis
}
}
现在,即使删除了所有消除歧义的页面,您仍可能在标题中包含“消除歧义”的结果。例如,其中一个结果是:
小苹果(消除歧义)“@ en
http://dbpedia.org/resource/The_Little_Apple_(disambiguation)
即使名称中有“消歧”,但不是消歧页面。它没有 dbo:wikiPageDisambiguates 的任何值。但它会重定向到另一个页面。您可能希望过滤掉重定向到其他内容的内容。您可以修改过滤器:
过滤器不存在{ ?资源dbo:wikiPageRedirects | dbo:wikiPageDisambiguates?dis }
这就是说要过滤掉重定向到某个东西的任何资源,或者消除歧义。实际上,这实际上是一个更简单的过滤器。这使您的查询:
prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix dbo: <http://dbpedia.org/ontology/>
select distinct ?Nom ?resource ?url where {
?resource rdfs:label ?Nom.
?resource foaf:isPrimaryTopicOf ?url.
FILTER (langMatches( lang(?Nom), "EN" )).
?Nom <bif:contains> "Apple".
filter not exists {
?resource dbo:wikiPageRedirects|dbo:wikiPageDisambiguates ?dis
}
}