Search code examples
databasesparqldbpedia

SPARQL, dbpedia : Retrieve values of resource linked as property, type person


I need to retrieve the name of a person's mother, and I have no idea how to do so.

This is the query I'm currently working with:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX foaf: <http://xmlns.com/foaf/0.1/> 
PREFIX : <http://dbpedia.org/resource/> 


SELECT DISTINCT 
    ?resource ?depiction ?label ?parent ?bd 
WHERE { 
    ?resource a dbo:Royalty ; foaf:depiction ?depiction ; rdfs:label ?label;
    dbo:parent ?parent; dbo:birthDate ?bd; 
    dbo:birthPlace ?bp . ?bp dbo:isPartOf :England . 
    FILTER(
        LANGMATCHES(LANG(?label), 'en') && ?bd < '1900-01-01'^^xsd:date)
} 
ORDER BY DESC(?bd)

Some of it was given, some of it was added by me.

As you can see I want to retrieve all royals (with Label and depiction) who were born in England before 1900. But I also want to retrieve the name of a person's mother.

?parent contains links to the person's parents and I can't seem to figure out how to:

  1. retrieve only the mother and
  2. How to get her name/label, since this only returns the url.

For example: For: http://dbpedia.org/page/Charlotte_of_Mecklenburg-Strelitz

?parents are:

http://dbpedia.org/page/Princess_Elisabeth_Albertine_of_Saxe-Hildburghausen

and

http://dbpedia.org/page/Duke_Charles_Louis_Frederick_of_Mecklenburg

But I would need :

Princess Elisabeth Albertine of Saxe-Hildburghausen

Solution

  • As commented by @AKSW, a possibly-incomplete query (formatted here for improved clarity) --

    PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX   rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX  foaf:  <http://xmlns.com/foaf/0.1/> 
    PREFIX  yago:  <http://dbpedia.org/class/yago/>
    PREFIX      :  <http://dbpedia.org/resource/> 
    
    SELECT DISTINCT 
      ?resource
      ?label
      ?bd
      ?depiction
      ?parent
      ?parentLabel 
    WHERE
      { ?resource  a                                          dbo:Royalty ; 
                   foaf:depiction                             ?depiction ; 
                   rdfs:label                                 ?label ; 
                   dbo:parent                                 ?parent ; 
                   dbo:birthDate                              ?bd ; 
                   dbo:birthPlace/dbo:location?/dbo:isPartOf  :England . 
        ?parent    rdfs:label                                 ?parentLabel . 
        FILTER     (  LANGMATCHES ( LANG ( ?parentLabel ), 'en' )
                   && LANGMATCHES ( LANG ( ?label ), 'en' )
                   && ?bd < '1900-01-01'^^xsd:date
                   )
        { ?parent  foaf:gender                                "female"@en } 
        UNION 
        { ?parent  a                                          yago:Female109619168 } 
      } 
    ORDER BY DESC(?bd)