4

I'm trying to extract entity dictionary contains person name etc. from dbpedia using sparql.

PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT ?name
WHERE {
    ?person a owl:Person .

    ?person dbpprop:name ?name . FILTER(lang(?name) = "en")
}

The query above did succeed, but when I change the language name to fr, there is nothing to fetch.

How can I fetch names in other languages?

Moreover, why can't I filter language using query below?

SELECT ?name
WHERE {
    ?person a owl:Person .
    ?person dbpprop:language "English"
    ?person dbpprop:name ?name . 
}
// this query returns nothing

I tried to fetch all languages using

SELECT DISTINCT ?lanName
WHERE {
    ?person a owl:Person .
    ?person dbpprop:language ?lanName .
}

and the result set contains English.

Tilney
  • 318
  • 2
  • 17

2 Answers2

5

You need to filter based on the language of the value of the property. Not every property will have values in different languages, but some properties will. It seems, from your example, that dbpprop:name doesn't have values in every language. You may find more values in other languages if you look on the other language specific DBpediae.

However, for something like a name, you'll probably get multi-language results if you use the rdfs:label property. For instance, to get the names of Barack Obama, Daniel Webster, and Johnny Cash in Russian, you could do:

select ?label {
  values ?person { dbpedia:Johnny_Cash dbpedia:Barack_Obama dbpedia:Daniel_Webster }
  ?person rdfs:label ?label .
  filter langMatches(lang(?label),"ru")
}

SPARQL results

As an aside, note the use of langMatches rather than equality for matching language tags. This is usually a better approach, because it will correctly handle the different language tags within a language For example (from the SPARQL specification), you can find both of the French literals:

"Cette Série des Années Soixante-dix"@fr .
"Cette Série des Années Septante"@fr-BE .

with langMatches(lang(?title),"fr"), but only the first one with lang(?title) = "fr".

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
0

You are looking for rdfs:label for a name, of course all the names are English, you are looking at the English dbpedia.

PREFIX owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
SELECT distinct *
WHERE {
    ?person a owl:Person .
    ?person rdfs:label ?name . 
    FILTER(lang(?name) = "fr")
}

Again, for the second one, if you replace the name with the rdfs: label you can have:

    PREFIX owl: <http://dbpedia.org/ontology/>
    PREFIX dbpprop: <http://dbpedia.org/property/>
    SELECT distinct *
        WHERE {
    ?person a owl:Person .
    ?person rdfs:label ?name .
    ?person dbpprop:language <http://dbpedia.org/resource/English_language>.
}
user205512
  • 8,798
  • 29
  • 28
Artemis
  • 3,271
  • 2
  • 20
  • 33
  • 1
    Running `select ?label { dbpedia:England rdfs:label ?label }` on http://dbpedia.org/sparql/ returns [twelve different results](http://goo.gl/ZGVXrB) and only one is in English. It's not so clear that "**You are looking for rdfs:label for a name, of course all the names are English**". – Joshua Taylor Mar 16 '15 at 15:08
  • 1
    And it's better to use `langMatches(lang(?name),"fr")` than `lang(?name) = "fr"`. – Joshua Taylor Mar 16 '15 at 15:09
  • Thanks, is there any detailed documents on these properties? The official ontology hierarchy(such as http://mappings.dbpedia.org/server/ontology/classes/Person) only contains some simple comments. – Tilney Mar 17 '15 at 01:59
  • 1
    @Tilney The properties in `http://dbpedia.org/ontology/` are from the DBpedia ontology and typically have much cleaner values than the properties in `http://dbpedia.org/property/`, which are much closed to the raw infobox data. Have a look at [4.3 Infobox data](http://wiki.dbpedia.org/Datasets#h434-10). – Joshua Taylor Mar 17 '15 at 03:01
  • Thanks so much! I'm checking on the ontology page. By the way, does dbpedia sparql endpoint limit the size of the result set? I can only get 10,001 records even after I increase the time-out field. – Tilney Mar 17 '15 at 03:16