How can I query a country's property like language from DBpedia?

一世执手 提交于 2019-11-28 14:03:46

问题


How can I query a country profile with DBPedia like http://dbpedia.org/page/France and get a property like language?


回答1:


Let's start from the beginning, as you don't say what you have tried.

DBpedia is a database of information about so-called resources: facts derived from Wikipedia articles stored as RDF triples. Resources are identified by URIs; DBpedia uses the form http://dbpedia.org/resource/* where * is the same as * in http://en.wikipedia.org/wiki/*.

So DBpedia has facts about the resource http://dbpedia.org/resource/France. If you look up this resource in your browser, you will be redirected to http://dbpedia.org/page/France, because the country France cannot be displayed in your browser but the description of it can.

Among the facts DBpedia knows is

<http://dbpedia.org/resource/France> <http://dbpedia.org/ontology/language> <http://dbpedia.org/resource/French_language>

which basically says "France['s] language [is] the French language."

To get this fact via an API, you can use the standard RDF query language and protocol SPARQL. The DBpedia SPARQL endpoint, which is where you send SPARQL queries to DBpedia, has a web form to let you enter and submit queries. If you just want an HTML table showing what language is spoken in France, leave the form's settings at the defaults and use:

select ?language ?languageName
where {
  dbpedia:France dbpedia-owl:language ?language .
  ?language rdfs:label ?languageName .
}

which means: "Give me the resource(s) that France uses as a language, and the name(s)."
dbpedia:France is short for <http://dbpedia.org/resource/France>, and dbpedia-owl:language is short for <http://dbpedia.org/ontology/language>.

If you want countries and the languages that are spoken in those countries, use:

select distinct ?country ?language
where {
  ?country a dbpedia-owl:Country .
  ?country dbpedia-owl:language ?language .
} 
LIMIT 100

which means: "Give me 100 combinations of resources that are countries and the resources that these countries use as language."

There are nuances that I left out, but this should get you started.




回答2:


As @Bergi points out in the comments, see http://wiki.dbpedia.org/OnlineAccess for list of possible on-line access methods.




回答3:


Unless they provide an API of some kind your only choice would be to "screen scrape" the page - in other words load the page using curl (or some other method) and then search for "dbpedia-owl:language" and get the string that follows (dbpedia:French_language) and parse it to make it nicer looking.



来源:https://stackoverflow.com/questions/13033841/how-can-i-query-a-countrys-property-like-language-from-dbpedia

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!