2015-11-30 52 views
1

的所有資源主題的選擇屬性我有這樣的SPARQL查詢來選擇beloning維基百科類National_parks_in_California所有資源:SPARQL:

PREFIX dcterms: <http://purl.org/dc/terms/> 

SELECT * WHERE { 
    ?park dcterms:subject dbc:National_parks_in_California . 
} 

returns

park 
http://dbpedia.org/resource/Death_Valley_National_Park 
http://dbpedia.org/resource/Yosemite_National_Park 
http://dbpedia.org/resource/Channel_Islands_National_Park 
http://dbpedia.org/resource/Kings_Canyon_National_Park 
http://dbpedia.org/resource/Lassen_Volcanic_National_Park 
http://dbpedia.org/resource/Redwood_National_and_State_Parks 
http://dbpedia.org/resource/Joshua_Tree_National_Park 
http://dbpedia.org/resource/Pinnacles_National_Park 
http://dbpedia.org/resource/Sequoia_National_Park 

是否有可能建立與dbpedia資源頁面一起返回的查詢也是每個資源的foaf:homepage

我寫

PREFIX dcterms: <http://purl.org/dc/terms/> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 

SELECT * WHERE { 
    ?park dcterms:subject dbc:National_parks_in_California . 
    ?webpage foaf:homepage ?park . 
} 

returns結果爲零。

回答

5

如果您打開結果,您會看到每個資源可能有一個foaf:homepage。因此,您的查詢的方向是錯誤的

PREFIX dcterms: <http://purl.org/dc/terms/> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
SELECT * WHERE { 
     ?park dcterms:subject dbc:National_parks_in_California . 
     optional{ 
      ?park foaf:homepage ?homepage. 
     } 
} 

我已經使用optional的原因是,一些資源沒有foaf:homepage