views:

1133

answers:

2

How can i get all the class properties and its sub classes with properties from an RDF datasource using SPARQL query given a class name and namespace?

+1  A: 

How about this:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#&gt;
SELECT ?subClass, ?predicate 
WHERE {
   ?subClass rdfs:subClassOf <http://dbpedia.org/ontology/Work&gt; .
   ?predicate rdfs:domain ?subClass
}

Give it a try on DBPedia's SNORQL interface.

Simon Gibbs
A: 

Are you trying to do a recursive SPARQL query? In other words, select a given individual and all of it's properties. Where the object of the property is another individual, select its properties, and so on.

I don't believe SPARQL supports this.

The naive approach would be to do something like this (and, assuming you mean individuals and not classes, this actually matches your requirements but doesn't handle the next "level" of triples).

CONSTRUCT {
    ?s ?p ?o .
    ?o ?p2 ?o2 .
} WHERE {
    ?s ?p ?o .
    ?o ?p2 ?o2 .
}

Note that if ?o2 is the subjects of any statements, this query will not return them.

Phil M