2016-01-07 43 views
0

我有一個SPARQL查詢,我想消除所有的解除消毒資源。我怎樣才能做到這一點?這是我的查詢:過濾DBpedia消歧頁面

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

回答

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

SPARQL results

現在,即使是刪除所有頁面消除歧義,你還可以有個結果,其中包括在標題爲「消歧」。例如,結果之一是:

       的小蘋果(消歧)「@恩
        http://dbpedia.org/resource/The_Little_Apple_(disambiguation)

即使有 」爲名消除歧義「,這是而不是這是一個消歧頁面,它沒有任何值dbo:wikiPageDisambiguates。它確實重定向到另一個頁面,但是您可能想要fi排除掉重定向到別的東西。你雖然可以修改過濾器:

過濾器不存在{ 資源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