Implementing SPARQL with tolog
I realized quite a while ago (a year ago, maybe) that it's possible to implement SPARQL on top of tolog without too much effort. Ontopia has never done anything about this since we have not seen any interest in this feature, but recently I got some questions about this, so I figured it might be worth writing up the basic idea.
The basics
So, given a SPARQL query, how can you execute that using tolog? The difficulty, of course, is that SPARQL operates on RDF, and tolog operates on Topic Maps. However, the RTM RDF-to-Topic Maps mapping enables us to deal with this. If we have an RTM mapping for the vocabulary that is being queried that gives us enough information to translate the SPARQL query into an equivalent tolog query, since the two languages are so similar.
The best way to see how it would work is to look at an example. Below is a very simple SPARQL query that finds the description of a particular book.
PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?desc WHERE { <http://example.org/book/book1> dc:description ?desc }
Given an RTM mapping that says dc:desc is an occurrence type, it's quite obvious how this should be translated into tolog. The equivalent tolog query would be:
USING dc FOR i"http://purl.org/dc/elements/1.1/" SELECT $desc FROM dc:description(i"http://example.org/book/book1", $desc)?
Basically, each triple pattern in the SPARQL query becomes a corresponding predicate in tolog, and the RTM mapping has enough information to tell us how to construct the predicate. In the case where the RDF property maps to an association type in Topic Maps we would even know the role types played by the subject and the object respectively.
Scaling up to larger queries
Of course, handling single-pattern queries isn't much of a feat, so for this to be useful we have to also be able to handle more complex queries. This turns out to be easy, however, as SPARQL is not a very big language, and what features it has maps very neatly onto corresponding tolog features.
The following can be handled without problems:
- Filtering of literals based on logical expressions (written with the FILTER keyword) maps directly to comparison predicates in tolog.
- Conjunctive patterns (written with a period between the triple patterns in SPARQL) map directly to AND in tolog (written with a comma between the predicates).
- Optional patterns (written with the OPTIONAL keyword) map directly to OPTIONAL in tolog (written with curly braces around a predicate list).
- Unions of patterns (written with the UNION keyword) maps directly to OR in tolog (written with pipe between the alternatives).
The features that might cause some difficulties are:
- Typed literals, which currently do not exist in tolog.
- Querying multiple graphs, which is not supported in tolog.
There might also be other stumbling blocks I haven't spotted yet, but this really does look like it's not that hard.
In addition, SPARQL supports producing several kinds of output from the query, but supporting these should not be hard:
- SELECT is the same in SPARQL and tolog, so this is not an issue.
- CONSTRUCT does not exist in tolog and would have to be custom-written. This shouldn't be difficult, though.
- DESCRIBE produces an undefined description of each node in the query result. In Topic Maps this would probably translate to creating a fragment for each topic returned, which is not hard. (This feature seems contentious, so it might not stay in the final language, anyway.)
- ASK just returns true or false, depending on whether the query matches anything or not, so this is trivial to implement.
Why do this?
You need more reasons beyond the fact that it's cool? :)
Well, the main reason to do this would be to allow a Topic Maps-based system to support the SPARQL protocol, which effectively means that you can play in an RDF environment even if you are using Topic Maps. The consequence is that you really can have true interoperability between Topic Maps and RDF.
Similar posts
Typed data in tolog
We've known for a long time that sooner or later we'd have to start supporting data types (numbers, dates, ...) in tolog, but so far we haven't done it
Read | 2006-05-10 23:17
tolog updates
The tolog query language has been around for a long time, but so far it only does querying, and not updates
Read | 2006-02-21 20:49
Semantic Web adoption and the users
A hot topic at ESWC 2013, and many other places besides, was the issue of Semantic Web adoption, which after a decade and a half is still less than it should be
Read | 2013-10-18 15:43
Comments
Javi - 2008-04-03 19:32:55
If you want a Tutorial of Tolog look at this http://geocities.com/recuperacioninformacionorganiza/Tutorial_TOLOG.html