过滤 DBpedia 消歧页面

Filtering DBpedia disambiguation page

我有一个 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".
}  

您可以在查询中添加以下前缀和过滤器:

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
   }
}

SPARQL results

现在,即使删除了所有消歧页面,您仍然可能会得到标题中包含 "disambiguation" 的结果。例如,其中一个结果是:

小苹果(消歧义)"@zh
http://dbpedia.org/resource/The_Little_Apple_(disambiguation)

尽管名称中有 "disambiguation",但它不是消歧义页面。 dbo:wikiPageDisambiguates 没有任何值。不过,它会重定向 到另一个页面。您可能还想过滤掉重定向到其他内容的内容。您可以修改过滤器:

过滤器不存在{ ?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
   }
}

SPARQL results