Reputation: 305
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:
- http://www.w3.org/2000/01/rdf-schema#seeAlso
- http://www.w3.org/2002/07/owl#sameAs
- http://www.w3.org/2002/07/owl#differentFrom
- http://dbpedia.org/property/deathPlace
- http://dbpedia.org/ontology/associatedBand
- http://dbpedia.org/ontology/author
- http://dbpedia.org/ontology/associatedMusicalArtist
- http://dbpedia.org/ontology/field
- http://dbpedia.org/ontology/governor
- http://dbpedia.org/ontology/lastAppearance
- http://dbpedia.org/ontology/managerClub
- http://dbpedia.org/ontology/recordLabel
- http://dbpedia.org/ontology/relation
- http://dbpedia.org/ontology/related
- http://dbpedia.org/ontology/relative
- http://dbpedia.org/ontology/starring
- http://dbpedia.org/property/p
- http://dbpedia.org/property/title
- http://purl.org/linguistics/gold/hypernym
Upvotes: 0
Views: 1738
Reputation: 21
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.
Upvotes: 0
Reputation: 9444
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...
Upvotes: 2