21

How to get a list of properties for a specific class? Consider the class dbpedia-owl:Person. All instances of the Person class have some properties prefixed with dbpprop:. How can I get all the dbpprop: properties that we may find for all the instance of the Person class?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
user878812
  • 349
  • 1
  • 2
  • 6

2 Answers2

28

The one that works is:

select distinct ?property where { 
   ?property <http://www.w3.org/2000/01/rdf-schema#domain> 
                             <http://dbpedia.org/ontology/Person> . }

In this query you are asking for all the properties that have dbpedia:Person as rdfs:domain. This query requires a schema definition to work and sometime datasets don't really follow perfectly the schemas. For those datasets you would try this other query

select distinct ?property where {
         ?instance a <http://dbpedia.org/ontology/Person> . 
         ?instance ?property ?obj . }

This query looks at every instance of person binding every property that comes out of it. It is much harder than the first one, and in the dbpedia public instance you will get a time out. So you are better off with the first one if you want to use the public endpoint.

Manuel Salvadores
  • 16,287
  • 5
  • 37
  • 56
  • 1
    This only finds those properties whose domain is *exactly* dbpedia-owl:Person. However, since each person is an instance of every superclass of Person, any properties "applicable" to the superclass is also applicable to the Person. You should probably retrieve all the properties whose domain is Person or a superclass of it. Cf. http://stackoverflow.com/q/22797424/1281433. – Joshua Taylor May 22 '14 at 14:56
  • Why you need `distinct` here? Maybe I haven't really understand the functionality of this keyword. – gsamaras Dec 03 '15 at 21:20
  • Otherwise you get all properties for every single statement. With distinct they only show once. It is like a applying a uniq to list with duplicates. – Manuel Salvadores Dec 04 '15 at 18:14
5

To get all transitive properties you can ask this query

select distinct ?property where{
{
  ?property rdfs:domain ?class . 
  dbpedia-owl:Person rdfs:subClassOf+ ?class.
} UNION {
  ?property rdfs:domain dbpedia-owl:Person.
}}

The '+' in the 'rdfs:subClassOf' is a property path expression [1] that fetches all uperclasses of Person as well. These properties are also valid for Person.

Also note that the dbprop namespace is not recommended because the data is raw and not normalized to a datatype.

[1] http://www.w3.org/TR/2010/WD-sparql11-property-paths-20100126/

Disclosure: I am a DBpedia developer

jimkont
  • 913
  • 1
  • 11
  • 18
  • How can I get the propriest of a query independently of the class? For example I have a query "Paris" how can I extract all its properties alongside the values – Hani Goc Feb 20 '15 at 09:30
  • 1
    something like `select * where {dbr:Paris ?p ?o}` – jimkont Feb 21 '15 at 09:34
  • Jim I have a question that I posted earlier http://stackoverflow.com/questions/28671935/dbpedia-return-relations-information-is-dbpedia-owl-of. I really don't understand why some of the properties are missing. what's wrong with my query? – Hani Goc Feb 23 '15 at 12:05