logo
Setting Off < TMQL Introduction < < Home 

PrevUpNext

Setting Off

If you have used SQL before, then you will not be completely puzzled by the following query:

select $album
where
   is-produced-by (production: $album, producer: tom-waits)

This query (technically a query expression) will return all albums where Tom Waits is known to be a producer. tom-waits is an identifier of a topic which we happen to know to uniquely pinpoint that topic about that person in the map we query. The query processor will try to find an association of type is-produced-by and will check whether the topic tom-waits is playing the role producer there. If so, it will bind the variable $album to the topic playing the role production in that very same association. It will so work through the whole map and will collect all these variable bindings. Because we asked so in the select clause, the query processor will return a list of the bindings for that variable. What exactly we will get returned into the application, we will discuss a bit later.

If we wanted to make the query more watertight to return albums only (and not something else produced), then we will have to add another constraint to the WHERE clause:

select $album
where
   is-produced-by (production: $album, producer: tom-waits) &
   $album isa album
The special binary predicate isa checks now additionally whether the thing we have bound to $album is also an instance of the class album, at least according to the map we query. It is worth noting, that isa honors the (transitive) subclass-superclass relationship, i.e. if one album were an instance of compilation, and compilation, in turn, were a (direct or indirect) subclass of album, then also these topics would be successfully bound.

If we are not fixated on Tom Waits and would instead want a list of all albums together with their producers, we can extend the wishlist in the SELECT clause:

select $album, $producer
where
   is-produced-by (production: $album, producer: $producer) &
   $album isa album
Again, the processor would walk through the whole map, will find all associations of the given type and will bind the playing topics to their respective variables. One particular set of bindings now consists of a pair (tuple of two components) of bindings, each for one variable; all these pairs are collected in a list which is then eventually returned.


PrevUpNext