0

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
TallTed
  • 9,069
  • 2
  • 22
  • 37
fetahokey
  • 185
  • 2
  • 16
  • what do you understand as "inverse"? Your example shows just predicates for which some persons are both subject and object of the triple. That doesn't mean anything, it would even return the predicates if there is just one such triple. And the property characteristic you're really asking for here is *symmetry*, i.e. `p(s,o)->p(o,s)` – UninformedUser Dec 16 '19 at 19:00
  • by the way, your returned result shows that most of them are useless, or why should title connect two persons? – UninformedUser Dec 16 '19 at 19:02
  • for inverse properties you obviously have to compute pairs of properties, don't you? `SELECT DISTINCT ?predicate1 ?predicate2 WHERE { ?subject a dbo:Person . ?object a dbo:Person . ?subject ?predicate1 ?object . ?object ?predicate2 ?subject . filter(?predicate1 != ?predicate2) }` – UninformedUser Dec 16 '19 at 19:03
  • Clearly, this doesn't provide any really meaningful thing, you still would have to compute how often those pairs `(p1, p2) do occur given `p1` (or `p2` - in science the common metrics are confidence and support given that your task is nothing more than mining rules (here `p1(s,o) ->p2(o,s)`) – UninformedUser Dec 16 '19 at 19:06
  • @AKSW sorry for coming late, By inverse properties i mean two predicate P1 <> P2 they are inverse, iff (A,P1,B), and (B,P2,A), A and B are Subject, Object respectively – fetahokey Dec 17 '19 at 09:29

2 Answers2

2

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...

TallTed
  • 9,069
  • 2
  • 22
  • 37
0

To get all available inverse properties in a specific domain, such as Person, you can use the following SPARQL query

SELECT DISTINCT ?p ?p_inv
WHERE {
  ?s a <http://dbpedia.org/ontology/Person> .
  ?s ?p ?o .
  OPTIONAL { 
    ?o ?p_inv ?s 
    FILTER NOT EXISTS { ?s ?p_inv ?o }
  }
}

This query will return all properties (?p) that have an inverse property (?p_inv) in the domain of Person. Note that some properties may have multiple inverse properties, and this query will return each pair of inverse properties separately.