Rob Sedgwick
Rob Sedgwick

Reputation: 4514

Sparql get "is dbo:parent of" records from Dbpedia

I am trying to get children of persons. Some persons have children listed in "dbo:child", others have them listed as "is dbo:parent of"

Here are examples of the two types

  1. https://dbpedia.org/page/Elizabeth_II
  2. https://dbpedia.org/page/George_V

For the first one I can pull child records off as follows:

SELECT * WHERE {
  <http://dbpedia.org/resource/Elizabeth_II> 
dbo:child?child 
}

For the second it's a bit harder as I think I have to find other records which point to George_V. I'm struggling to find anything that works, this is the best I can come up with

SELECT *
WHERE
{
  ?person a              dbo:Person ;
   dbo:parent [dbo:Person dbr:George_V] 
}
limit 10

What's the best way to do this? Is there a way I can combine the two approaches?

Upvotes: 0

Views: 378

Answers (1)

Kingsley Uyi Idehen
Kingsley Uyi Idehen

Reputation: 925

Here's an example that solves the problem. Note, you have to look at the data for familial properties (relationship types) and then explore regarding data quality.

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX dbp: <http://dbpedia.org/property/> 

SELECT DISTINCT ?royal ?ancestor
WHERE {
        { 
          <http://dbpedia.org/resource/Charles,_Prince_of_Wales>
                    <http://dbpedia.org/property/father>+ ?ancestor .
        }
        UNION
        {
          <http://dbpedia.org/resource/Charles,_Prince_of_Wales>
                    <http://dbpedia.org/property/mother>+ ?ancestor .
        }
        BIND ( <http://dbpedia.org/resource/Charles,_Prince_of_Wales> as ?royal )
      }

Live DBpedia Query Solution Link.

Alternatively, which is closer to your original property preference (i.e., dbo:parent), here is another property-paths based example.

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX dbp: <http://dbpedia.org/property/> 

SELECT DISTINCT ?royal ?ancestor ?ancestorName
WHERE {
        <http://dbpedia.org/resource/Elizabeth_II>
              dbo:parent* ?ancestor     . 
        ?ancestor 
              foaf:name   ?ancestorName . 
        FILTER (LANG(?ancestorName) = "en")                

        BIND ( <http://dbpedia.org/resource/Elizabeth_II> as ?royal )
      }

Live Query Results Link.

We are working on a new DBpedia release that should have increased quality regarding this kind of information.

Finally, a tweak to some earlier suggestions (posted as comments).

PREFIX dbo: <http://dbpedia.org/ontology/> 
PREFIX dbr: <http://dbpedia.org/resource/>

SELECT DISTINCT ?royal ?child
WHERE { 
        dbr:George_V  dbo:child+|^dbo:parent+  ?child .
        BIND ( dbr:George_V AS ?royal )
      }

Live DBpedia Query Link.

Upvotes: 1

Related Questions