Reputation: 2522
ok it is difficult to find a title for this question...sorry...i'll try to better explain my problem!
I have a graph and an ontology. I have hundreds models like Person, Animal, Book etc. and any of them has properties with several depth:
<Person1> <hasName> <Luca>
<Person1> <hasAddress> <Address1>
<Address1> <hasStreet> "Some street"
Please NOTE that for 'model' i mean a collection of OWL/RDF Classes and properties, in the example, the model 'Person' contains classes 'Person' and 'Address'.
What I would like to do is to get an entire model instance with 1 query...like 'get('Person1')'
As an example think about Freebase. In Freebase they have topics (instances of models) which are of some types (what i call models) and a topic is fully described by a class and several properties which may refer to other classes (mediators)...when you visit the webpage of a freebase topic, you can see the entire model.
In the ontology i can't define the models, but i have them defined on other files and are available in any format, from RDF to JSON and Ruby/Python objects.
Actually i don't know how to solve this problem...i thought to use the file with models in JSON or Ruby obj to automatically create a SPARQL query for a given model, but this seems crazy when you should retrieve many models at the same time..its really slow i think...(i have something like 200 different models..)
Is there any 'pure' SPARQL way that solves my problem or i should craft a specific query for each model?
thank you for any help!
Luca
Upvotes: 1
Views: 483
Reputation: 4886
Basically what you are looking for is a SPARQL construct query. So if you want to get the RDF pertaining to http://example.org/Person1
you can do a simple describe:
describe <http://example.org/Person1>
This will return you the graph about http://example.org/Person1
. What precisely is in that graph is actually up to the RDF database; the spec does not impose any specific interpretation, such as a concise-bounded description. But often, the result will be sufficient information for your purposes.
But when it's not, you can use construct queries, for example:
construct { <http://example.org/Person1> ?p ?o . ?p rdfs:label ?l }
where {
<http://example.org/Person1> ?p ?o.
?p rdfs:label ?l.
}
That'd get you all the triples where http://example.org/Person1
is the subject and the labels of the properties it holds. You can get as complicated as you want in returning information about http://example.org/Person1
.
If you need arbitrary levels of relations to http://example.org/Person1
, then you need to look into implementing CBD or a similar strategy on your own. It's a pretty straightforward implementation, probably only 100 LOC if you need to go that route.
Upvotes: 3
Reputation: 4603
If you want to do something like the Freebase Topic API, you should really consider putting the data in a key/value datastore.
Check out this blog post from Seevl where they use Redis to do topic-by-topic queries on RDF data.
Otherwise, you'd need to build custom SPARQL queries for each topic based on your knowledge of the schema and which properties (eg. person address) need to be expanded to give a proper snapshot of that entity.
Upvotes: 0