I want to retrieve all properties from yago which is an RDFS knowledge base(.nt format).I tried with bellow query
SELECT distinct ?x WHERE { ?y ?x ?z . }
This gives me all the predicates.
In the web they defined predicates as predicates(properties). According to this my result should be correct. But my professor suggested me bellow query
SELECT distinct ?x WHERE { ?y ?x ?z . ?z a ?zt. }
He didn't explain the reason. The results are a little bit different for this 2 query. The result of the 2nd query is a subset of 1st query. Does it mean more precise?
Can anyone help me understand why he added ?z a ?zt .
? Will the object used to obtain properties always be rdf:type
of a different class?
According to the RDF 1.1 specification:
The core structure of the abstract syntax is a set of triples, each consisting of a subject, a predicate and an object.
[...]
The predicate itself is an IRI and denotes a property, that is, a resource that can be thought of as a binary relation.
According to these definitions, you can get all properties in SPARQL with your first request:
SELECT distinct ?x WHERE { ?y ?x ?z . }
The second request is more specific:
SELECT distinct ?x WHERE { ?y ?x ?z . ?z a ?zt. }
It lists all properties used at least once in a triple where the object is also involved in a rdf:type
triple as a subject.
Note that in SPARQL a
is a shortcut for rdf:type
.