This is a specification proposal for Boulder Vice Versa. Since the hope is that it becomes official Versa 2.0, from here on it will just be called "Versa".

Introduction

Versa is a graph traversal language that serves for general-purpose Web data query. It's designed to query metadata and RESTful relationships between resources (this is a broad umbrella that would accommodate underlying models from RDF, to linked XML or HTML+microformats documents, social networks and such). Versa comprises a simple data model and a query language.

Where used in this document, the keywords "SHOULD", "MUST", and "MUST NOT" are to be interpreted as described in RFC 2119 [RFC2119]. However, for readability, these words do not appear in all uppercase letters in this specification.

Domain of Operation

Data Model

Query Structure

Versa Query Structure

Versa defines queries. A query is a combination of literals, traversals and filters, variable references and function calls. Traversals and filters are expressions that match patterns in the information space by selecting sets of starting resources, relationships, conditions for selecting end-point values, and options for accessing attributes within matched tuples.

A Versa query has a prologue and a query body. The prologue is a collection of namespace prefix, variable, and function declarations. The query body is an expression that returns a value, which is the result of the entire query. Constructs in the prologue may be superseded or otherwise affected by the implementation binding.

Context

Many Versa constructs are evaluated with regard to a context. The context is a value of any data type, and it can be referred to explicitly in an expression using the token "."

There is always a set of namespace declarations and variable bindings in effect, and a set of function definitions in scope, but these are not formally considered part of the context, as they are in XPath.

Grouping

Subexpressions can be grouped using the grouping symbols '(' and ')', generally for purposes of disambiguation of precedence. The results of a grouped expression are the same as the result of the contained expression.

Literals

Versa includes constructs for expressing literals for each of the core data types. In addition you can express extended types by combining a string with a type specifier. The following are some examples of literals

"foo"                   A string
"foo" as xsd:string     A string explictly stated as type string (using The literal with the value of "foo" in the datatype xsd:string.
'foo'                   Same as first query, apostrophes are interchangable with quotes.
"10" as xsd:int         The only way to express a true integer in Versa (whose numbers are technically floats)
"10.0" as xsd:float     Same as plain 10.0 or 10 in Versa
"true" as xsd:boolean   same as literal true

String Escaping

Strings support the following escape characters to allow embedding of various content within the strings.

"\\"    becomes         '\'
"\""    becomes         '"'
"\'"    becomes         '\''
"\n"    becomes         '\n'
"\r"    becomes         '\r'
"\t"    becomes         '\t'
"\uXXYY"        becomes         unicode character XXYY
"\xXX"  becomes         character XX

Traversal and filter expressions

Traversal and filter expressions are the core of Versa. They provide a system for matching patterns in an RDF model by specifying desired nodes and arcs in the graph representing the model. The traversal and filter operators are the bases of the respective expression, and result in a list.

Note: <uri1> - <uri2> -> <uri3> is equiv. to set(ground(<uri1>)) - set(ground(<uri2>)) -> member(set(ground(<uri3>)),.)

Forward traversal and filter expressions

The forward traversal operator matches patterns based on given sets of subjects and predicates. It returns a list of resulting objects. It takes the following form:

set-expression - set-expression -> filter-expression

The forward filter operator matches patterns based on given sets of subjects and predicates. In contrast to the forward traversal operator, it returns a list of the subjects that result from the patterns rather than the objects. It takes the following form:

set-expression |- set-expression -> filter-expression

In both cases the first set-expression is a evaluated to obtain list (cast if need be) which are the subjects of statements. Each of these resources is set as the context for evaluating the second set-expression, which is treated as a list of predicates(cast if need be). All statements in the model with these subjects and predicates are marked as candidate statements. The object of each of the candidate statements is evaluated as the context of the filter-expression.

In the case of forward traversal, if the result, after conversion to boolean type, of evaluating the filter-expression is true, the object is added to the list of results. In the case of forward filtering, if the result, after conversion to boolean type, of evaluating the filter-expression is true, the subject of the corresponding statement is added to the list of results.

Unless an ordering aggregate function (see below) is used, the order of the resulting elements in the list is undefined in Versa, and is determined by the underlying model.

Backward traversal and filter expression

The backward traversal operator is similar to the forward traversal operator, but it is used to match patterns using the inverses of predicates. A backward traversal expression takes the following form:

filter-expression <- set-expresion - set-expression

The backward filter operator is similar to the forward filter operator, but it is used to match patterns using the inverses of predicates. A backward filter expression takes the following form:

filter-expression <- set-expression -| set-expression

In both cases, the first set is a set of resources which are the objects of statements, the predicates of which are given by the resources in the second set expression. In the case of traversal, the results are a list of matching statements, and the subject of each statement is evaluated as the context of the boolean expression. If the result, after conversion to boolean type, is true, the subject is added to the list of results. Conversions are automatically applied, as with forward traversal expressions. In the case of filter, the results are the objects of the original statements.

Aggregate functions

Versa provides a set of special functions which are designed to be used within traversal operations to transform partial results within the context of the traversal.

sortq

sortq(set, expression [, vsort:number | vsort:string [, vsort:ascending | vsort:descending ] ])

Existenstial expressions

Existential expressions are away to all optimizers signal that ahe source expression is over the set of all resources in the model. In all four cases, the expression could be rewritten by addind all() as the missing expression. So the exitensial expression

[ - rdf:type -> rdfs:Class ] 

is evaluated as

all() - rdf:type -> rdfs:Class 

Prologue

The prologue .

Grammar

Functions

Versa/Boulder_vice/Specification (last edited 2008-11-24 18:46:31 by localhost)