logo
Generating Topic Maps < TMQL Introduction < < Home 

PrevUpnext

Generating Topic Maps

We have already seen that TMQL can generate lists (of tuples) and XML content. But with TMQL we can also generate topic maps, using information from the queried map, provided we use the FLWR style.

In the following example we iterate over all albums in our map and create a new map, one which only contains the albums and one of their names. All other album information (characteristics or association involvements) is ignored. Instead we add one homepage characteristic and one―admittedly absurd―new assocation where we claim that Jessica Simpson has created that album:

for $a in // album
return """

    {id ($a) + "-new"}
    {$a/name}
    homepage: http://music-r-us.com/{id ($a)}

    (has-created)
    creator: jessica-simpson
    opus   : {$a}

"""
      
The RETURN clause now contains a topic map, or―to be more precise―a template to generate one. For each album we have found, this template is expanded, simply by evaluating all expressions in curly brackets.

The first block follows the syntax to create a topic, so the very first thing to appear here is the internal identifier of the topic. That is computed by looking up the internal identifier of the current album and by appending it with -new.

The next line again contains a TMQL expression, this time one which computes all name characteristics. Since at this position in the notation characteristics can be declared, all these names become part of the newly generated topic. The last line of the topic declaration will take care that an occurrence of type homepage will be added to the topic. The value is a URI which is static except from the final part which is provided by the albums internal identifier.

The second block creates one association per album, claiming the unbelievable.

As this template is expanded for every album, the individual expansions are all merged into one, possibly big, topic map. As we did not say much about Jessica Simpson we might want to do so, and combine this information with our result map:

return """

   jessica-simpson isa person
   bn: Jessica Simpson
   quote: "I am an artist."

{
 # here our original query goes
}
"""
      


PrevUpnext