Versa: Path-Based RDF Query Language
by Chimezie Ogbuji
|
Pages: 1, 2, 3, 4
EVersa?
Query Scoping
The following "extension" functions were added to 4Suite's Versa implementation at a later point in time:
- scoped-subquery()
- scope()
These both have to do with named graphs. The first function (scoped-subquery) takes a string as its first argument and a list of resources or strings as its second argument. The first argument is evaluated as a Versa query with respect to copies of the current context, each of which is associated with graphs named by the second argument as a list. Once again, the most common conversion scenario is going from a string or resource to a list, in which case the result is a list of the string or resource as its only member.
The second function (scope) is very different. It essentially asks the underlying RDF graph to give the scopes (contexts, named graphs) that the given resource (or list of resources) belongs to. More specifically, the scopes of all statements made about the given resource (or resources) are returned. In practice, I've found that the ability to dynamically determine the current context within a traversal and then limit an RDF query to that context is a very common and powerful pattern in RDF query optimization.
Others
Finally, some additional functions can be defined as shorthand for common expressions:
class([member])
as shorthand for:
. - rdf:type -> *
and
member - rdf:type -> *
value([valuedResource])
as shorthand for:
. - rdf:value -> *
and
valuedResource - rdf:value -> *
Splenda for your Versa?
Turtle Constructs
The timing of the advent of SPARQL was such that it could take advantage of a recent RDF serialization syntax that's directly related to Tim Berners-Lee's Notation 3. Unfortunately, Versa was developed during an earlier period where there was no precedent for RDF querying other than RDQL and similar languages.
In the early brainstorming sessions we decided that XPath was the better contemporary for querying RDF data. The result is a very expressive analogy that nevertheless relies quite a bit on functions to perform common operations. Augmenting the syntax with forms that emerged at a later point (Notation 3) would go a long way in alleviating this particular limitation, as well as make Versa even more expressive in general.
I. Versa could easily be extended to work with RDF Literals (and XSD data types) by making use of Notation 3's abbreviated syntax for data types in expressions such as:
all() |- rdf:value -> eq("1.0e6"^^xsd:double)
II. SPARQL's mapping of operator expressions to SPARQL and XPath 2.0 functions (as well as XPath 1.0 boolean expressions) can be adopted as alternatives to:
- lt/lte
- gt/gte
- eq/neq
Like so:
SPARQL
SELECT ?title ?price
WHERE { ?x ns:price ?price .
FILTER ?price < 30 .
?x dc:title ?title . }
Versa
distribute(
all() - ns:price -> < "30",
'dc:title',
'. - ns:price -> *',
)
or
[ - ns:price -> < "30"] - list(dc:title ns:price) -> *
III. This latter form makes use of Notation 3's [ .. ] to represent traversal expressions evaluated against blank nodes as existential placeholders or wildcards. The term [ - predicates -> objects] would be shorthand for (all() |- predicates -> objects).
Versa originally used "[" and "]" as predicate filters (in the same way that XPath does), but this didn't make it to the final specification. Given the nature of blank nodes (as placeholders for statements made about resources where the identity is unimportant), Notation 3's use of the same form seems preferable.
IV. Finally, Python list iteration and indexing operators (such as in [:3], [1:3], and [:-4]) can be adopted as alternatives to: member, item, rest, tail, and slice.
Consider the following query that returns the title of the most recent rss:item in a feed:
sortq(type(rss:item),'. - dc:date-> *')[-1] - rss:title -> *
This would conflict with the earlier suggested use of "[". A different set of bracketing characters could be used for either instead: "{" and "}" perhaps.
Revisiting Syntax in the Semantic Web Stack
The success of the Semantic Web initiative is very heavily dependent on the ubiquitous adoption of its various syntaxes. These fall into the following groups:
- Rules (OWL,RDFS,SWRL,N3,etc.)
- Query (SPARQL,Versa,etc.)
- Knowledge Representation (RDF/XML,N3)
This can be seen as a bottom-up stack with components in common with traditional Expert Systems. The lower end of this stack (knowledge representation in particular) is the more matured level (in both Semantic Technologies and Expert Systems). The adoption of Notation 3 syntax (and other subsets of Notation 3) into the more recent RDF standards is evidence of this. The middle portion of the stack is where the focus has recently shifted, and the rich spectrum of graph traversal syntaxes (spanning between Versa and SPARQL) stands poised to move the initiative to the next step and towards the final goal: what essentially amounts to the framework for a massively distributed expert system.
Resources
|
- Emeka - Versa bot
2005-07-21 07:51:25 Chimezie Ogbuji