问题
I have defined a rdf class for Books. Another rdf class for describing people. The Book class contains authoredBy field which links book instances to people instances.
Properties of Book
Book
-Id
-name
-authoredBy
Person
-id
-firstName
-LastName
-designation
For retrieving book properties, i use the following sparql query
DESCRIBE ?book WHERE { ?book a rdf:Book ;
}
I am able to retrieve all the properties belonging to Book using DESCRIBE i.e the predicate , subject and object. However when it comes to authoredBy field, the above query returns me only URI of the author.
I would like to see all predicates that belong to author as well (i.e its firstname, lastname). Can the above DESCRIBE query be modified to achieve this ?
回答1:
all the properties belonging to Book using DESCRIBE
Properties don't "belong" to things. OWL isn't an object-oriented programming language.
However, you can certainly get the properties and values of books and their authors. The particular results of a describe query are implementation dependent. Even though the implementation that you're using gives you certain results, there's no guarantee that other implementations would give you that. It's safer to use a construct query. In your case, it sounds like you want
construct where {
?book a ex:Book ;
?p ?o ;
ex:authoredBy* ?author .
?author ?ap ?ao .
}
That will return a graph of all the triples about all books and their authors.
i use the following sparql query
DESCRIBE ?book WHERE { ?book a rdf:Book ; }
Note that you really shouldn't be defining your own terms in the RDF namespace (e.g., as you have with rdf:Book). You should use some other namespace for your own classes.
来源:https://stackoverflow.com/questions/25652715/sparql-describe-query-to-get-data-about-linked-objects