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

前端 未结 3 1992
青春惊慌失措
青春惊慌失措 2020-12-22 13:16

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

3条回答
  •  没有蜡笔的小新
    2020-12-22 13:53

    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

      
    

    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 , and dbpedia-owl:language is short for .

    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.

提交回复
热议问题