The purpose of the SQL Interface extension required to accomodate the WSML-Flight-A query language is to provide an easy to use syntactic extension for querying ontologies and to facilitate the following main features:
This is mainly a use case driven extension of SQL originally required to accomodate the WSML-Flight-A query language. Additional motivations and details are given in [1]. Furthermore since this query language is layered on top of WSML-Flight, there are no compatability issues. There is no need to adjust existing ontologies, reasoning components, or other existing dependent software due to the architecture chosen.
The allowed syntax for WSML-Flight-A queries closely corresponds to standard SQL syntax. For an exhaustive, in-depth description we again refer to [1], while [2] and [3] provide a concise overview of the SQL syntax. This section is only meant to serve as a short introduction.
A WSML-Flight-A query in general is of the following form:
SELECT X1, ...,Xn FROM o WHERE Q
Whereby Q is an ordinary WSML-Flight query, X1, ..., Xn are a subset of the variables appearing in Q, and o is the IRI of the ontology over which the query is placed. The WSML-Flight-A extension allows for SQL-like projection via the select expression in the usual SQL-like syntax and semantics. It explicitly supports the following constructs:
With the exception of COUNT(*), all aggregate functions exclude NULL values, as in SQL. The type of the returned value for SUM is subject to deterministic widening to ensure lossless results. Numeric aggregates obviously only return values if and only if all bindings of a variable are also numeric. The return value type for COUNT is integer, for MIN, MAX and AVG it is the same type as the column, for SOME and EVERY it is boolean. For VAR_POP, VAR_SAMP, STDDEV_POP and STDDEV_SAMP statistical functions, the type is always double. Additionally the usual further SQL constructs are possible:
Where orderExpression denotes the usual:
{ column number | column alias | select Expression } [ASC | DESC]
And LIMIT n m creates the result set for the SELECT statement first and then discards the first n rows (OFFSET) and returns the first m rows of the remaining result set (LIMIT).
Following are some short examples for the query expressions. The basic usage of the query extension is very
simple. Queries are passed as ordinary String objects, and the
WSMLQuery class is the only entry point. Results are returned in
the expected WSML2Reasoner wrappers.
String query = "<query>" WSMLQuery wqe = new WSMLQuery(); Set<Map<Variable, Term>> r = wqe.executeQuery(query);
Complete usage examples are contained in the WSML2Reasoner org.wsml.reasoner.ext.sql test package. Following are short examples
to illustrate the syntax of queries and same basic combinations. The first query
illustrates one of the simplest use cases of the query extension, in which basically no
features are used.
SELECT ?x FROM _http://someontology WHERE ?x memberOf ?y"
The second example illustrates the possibility to order query results according to certain variable bindings.
SELECT ?place, ?employee FROM _http://someontology WHERE ?employee[hasWorkingPlace hasValue ?place] ORDER BY 1, 2
Furthermore it is possible to use aggregates, group results and impose further restrictions on the projection, as in standard SQL.
SELECT ?place, COUNT(?place) FROM _http://someontology WHERE ?employee[hasWorkingPlace hasValue ?place] GROUP BY ?place HAVING COUNT(?place) > 4
Also the order of sorting can be specified, as usual, and the number of results can then be limited to a certain desired amount.
SELECT ?place, COUNT(?place) FROM _http://someontology
WHERE ?employee[hasWorkingPlace hasValue ?place] GROUP BY ?place HAVING COUNT(?place) > 4 ORDER BY ?place DESC LIMIT 2
[1] D1.4: Process Ontology Query Language, Technical report, SUPER
IST Project 026850. Stijn Heymans, Cristina Feier, Jos de Bruijn, Stefan Züller, Emilia
Cimpian
[2] MySQL 3.23, 4.0, 4.1 Reference Manual - http://dev.mysql.com/doc/refman/4.1/en/
[3] HSQLDB User Guide, Chapter 9. SQL Syntax - http://hsqldb.org/doc/guide/ch09.html