Search code examples
sparqlrdfsemantic-webdbpediasparqlwrapper

How to get all inverse properties using SPARQL?


I need a SPARQL query to get all available inverse properties. exp (before, after, spouse, ... etc) i tried this, on specific domain (Person) :

SELECT
DISTINCT ?predicate
WHERE 

{
  ?subject a dbo:Person .
  ?object a dbo:Person . 
  ?subject ?predicate ?object .
  ?object ?predicate ?subject .
}

RESULT:

  1. http://www.w3.org/2000/01/rdf-schema#seeAlso
  2. http://www.w3.org/2002/07/owl#sameAs
  3. http://www.w3.org/2002/07/owl#differentFrom
  4. http://dbpedia.org/property/deathPlace
  5. http://dbpedia.org/ontology/associatedBand
  6. http://dbpedia.org/ontology/author
  7. http://dbpedia.org/ontology/associatedMusicalArtist
  8. http://dbpedia.org/ontology/field
  9. http://dbpedia.org/ontology/governor
  10. http://dbpedia.org/ontology/lastAppearance
  11. http://dbpedia.org/ontology/managerClub
  12. http://dbpedia.org/ontology/recordLabel
  13. http://dbpedia.org/ontology/relation
  14. http://dbpedia.org/ontology/related
  15. http://dbpedia.org/ontology/relative
  16. http://dbpedia.org/ontology/starring
  17. http://dbpedia.org/property/p
  18. http://dbpedia.org/property/title
  19. http://purl.org/linguistics/gold/hypernym

Solution

  • Note that you're not asking for the inverse properties; you're asking for symmetric (or reciprocal, or reflective) properties -- where each subject/object pair is also described as an object/subject pair.

    If you really want something closer to inverse, you might try something like --

    SELECT DISTINCT ?predicate 
                    ?reverse_predicate
    WHERE 
      {
        ?subject a                  dbo:Person .
        ?object  a                  dbo:Person . 
        ?subject ?predicate         ?object .
        ?object  ?reverse_predicate ?subject .
      }
    ORDER BY ?predicate ?reverse_predicate
    

    -- but if you look at the results from that query, you'll notice that many "reflected" relationships are not expressed with properties that are actually the inverse of each other.

    ex:child and ex:parent are probably easily understood as inverse -- but how about ex:sibling, ex:brother, ex:sister? Also note just how many "reflected" properties there are for, for instance, <http://dbpedia.org/ontology/child>!

    Probably, describing why you need these, and how you plan to make use of them, will help others provide more relevant answers or other information...