2017-06-22 118 views
0

我想要DBpedia的國家名稱列表。使用SPARQL獲取DBpedia中的所有國家名稱

我使用http://dbpedia.org/snorql/來執行我的查詢,但直到現在我還沒有找到DBpedia中可用的所有國家名稱。

例如:DBR:United_Kingdom,DBR:India,DBR:United_States

+0

OK,向我們展示你迄今爲止寫的SPARQL,即使它沒有得到「所有國家」。 –

+0

我的SPARQL查詢是'SELECT DISTINCT?country WHERE { ?city rdf:type dbo:City; rdfs:label?label; dbo:country?country } order by?country' or you can open this [link](http://dbpedia.org/snorql/?query=SELECT+DISTINCT+%3Fcountry+WHERE+%7B%0D%0A+% 3Fcity + RDF%3Atype + DBO%3ACity +%3B +%0D 0A%RDFS +++++++%3Alabel +%3Flabel +%3B +%0D 0A%DBO +++++++%3Acountry +%3Fcountry +%0D 0A%% 7D%0D%0Aorder + by +%3Fcountry) –

+0

您並非要求所有國家/地區。你要求所有與一個國家有已知關係的城市。這可能聽起來很有道理,但也許在DBpedia中有一些國家沒有記錄城市。您是否嘗試過我在下面提供的查詢?使用我指出的一些類進行查詢可能會很有趣,然後「減去可用於城市問題的國家/地區」。 –

回答

1

是問題

  1. 你不知道如何寫一般SPARQL? (沒關係,很難開始。)
  2. 你不知道DBpedia中的類和謂詞嗎? (這也行,我必須每次檢查一次。)
  3. 還有其他的東西嗎?

這得到所有聯合國成員國。獲得「所有國家」可能只是在他們的本體論中找到合適的課程。

select distinct ?s 
where { ?s a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> } 

我碰巧知道,紐約市是美國最大的城市,而DBpedia的具有largestCity謂詞和New_York_City實例。所以我寫了一個查詢,只應該把美國作爲主題,然後詢問所有連接的謂詞和對象。您應該考慮一個符合您定義「所有國家」的例外的對象。如果您找不到一個,則可能需要將union幾個其他三重模式合併爲一個查詢。

我也過濾掉所有包含的兩個術語與您無關的對象:「國家」或「民族」

select distinct * 
where { ?s a <http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations> ; 
dbo:largestCity dbr:New_York_City ; 
?p ?o 
filter(isURI(?o)) 
filter((regex(lcase(str(?o)), "country")) || (regex(lcase(str(?o)), "nation"))) 

} 

給人的foloowing,這應有助於你寫的ISN一個後續問題並非特定於美國。

+--------------------------------------------+---------------------------------------------------+------------------------------------------------------------------------------+ 
|      s      |      p       |          o          | 
+--------------------------------------------+---------------------------------------------------+------------------------------------------------------------------------------+ 
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://www.ifs.du.edu/ifs/frm_CountryProfile.aspx?Country=US     | 
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://nationalatlas.gov/             | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://dbpedia.org/class/yago/Country108544813        | 
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject     | http://dbpedia.org/resource/Category:G7_nations        | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://schema.org/Country             | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/2000/01/rdf-schema#seeAlso  | http://dbpedia.org/resource/Anti-miscegenation_laws       | 
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject     | http://dbpedia.org/resource/Category:Member_states_of_the_United_Nations  | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/2002/07/owl#sameAs    | http://transparency.270a.info/classification/country/US      | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://dbpedia.org/ontology/Country           | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://dbpedia.org/class/yago/WikicatMemberStatesOfTheUnitedNations   | 
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject     | http://dbpedia.org/resource/Category:G8_nations        | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/2002/07/owl#sameAs    | http://linked-web-apis.fit.cvut.cz/resource/united_states_of_america_country | 
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://www.nationalcenter.org/HistoricalDocuments.html      | 
| http://dbpedia.org/resource/United_States | http://dbpedia.org/ontology/wikiPageExternalLink | http://news.bbc.co.uk/2/hi/americas/country_profiles/1217752.stm    | 
| http://dbpedia.org/resource/United_States | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://umbel.org/umbel/rc/Country           | 
| http://dbpedia.org/resource/United_States | http://purl.org/dc/terms/subject     | http://dbpedia.org/resource/Category:G20_nations        | 
+--------------------------------------------+---------------------------------------------------+------------------------------------------------------------------------------+ 
相關問題