Introduction to Topic Maps
topicmapslab.de
Topic Maps Query Language
Sven Krusty M. Sc.
Topic Maps Lab at the University of Leipzig
Session 1
Introduction to Topic Maps
topicmapslab.de
Agenda
1. Basics
● TMQL metamodel
- Compared to TMDM● Grammar
2. TMQL as language
● Topic identification● Navigation concept
Introduction to Topic Maps
topicmapslab.de
Metamodel
● represented as a topic map
● each topic can be used in the query
● Topic Maps represent different elements in TMDM
Introduction to Topic Maps
topicmapslab.de
TMQL
● Topic Map construct does not exist● no reification of topic maps possible● Query all topics difficult or Association
Introduction to Topic Maps
topicmapslab.de
TMQL
● No distinction between name and Occurrence
→ Characteristics
Introduction to Topic Maps
topicmapslab.de
TMQL
● no direct support of variants
→ Query only special feature
Introduction to Topic Maps
topicmapslab.de
Summary
● No distinction between name andOccurrences
● No variations of name
● no role constructs
● A topic map construct
Introduction to Topic Maps
topicmapslab.de
Grammar
● defined in three levels
● each level was inspired by other standards
Introduction to Topic Maps
topicmapslab.de19
Token Level
● Terminal symbols of the language
● Definition based on regular expressions
Token Level
Introduction to Topic Maps
topicmapslab.de20
Canonical Level
● Definition of production rules
Example: tuple-expression: = <value-expression>
Token Level
Canonical Level
Introduction to Topic Maps
topicmapslab.de21
Non-Canonical Level
Token Level
Canonical Level
Non-Canonical Level
● Term substitution as new production rules
● Definition of shorter terms
anchor / tm: name ==> anchor>> chracteristics tm: name
Introduction to Topic Maps
topicmapslab.de
Literals and constants
● Constants (atoms) are data types and operators
● Acquisition of CTM data types
Introduction to Topic Maps
topicmapslab.de
Literals and constantsAtom possible valueAtom Undefined | boolean | number | date | datetime | string | iri
undefined undef
boolean true or false
number decimal or integer
decimal /[+-]?/ +(/./ D d +)? /
integer /[+-]?/ D + /
date '-'? yyyy '-' mm '-' dd (zzzzzz)?
DateTime '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s +)? (Zzzzzz)?
iri see RFC 3987
string /"([^"]|/")*"/ | /'([^']|/')*'/
Introduction to Topic Maps
topicmapslab.de
Topic identification
● Use of references or string literals
● String literals translated by axes
● References are automatically translated
● Subject identifier● Subject Locator● Item Identifier
Introduction to Topic Maps
topicmapslab.de
Topic identification
● item-identifier
puccini
● subject-identifier
http://en.wikipedia.org/wiki/Puccini
● subject-locator
http://en.wikipedia.org/wiki/Puccini
Introduction to Topic Maps
topicmapslab.de
Topic identification
● Item identifier
"Puccini" <<item
● Subject-identifier
"Http://en.wikipedia.org/wiki/Puccini"<<Indicators
● Subject locator
"Http://en.wikipedia.org/wiki/Puccini"<<Locators
Introduction to Topic Maps
topicmapslab.de30
Navigation concept
● based on the proxy concept of TMRM
● Model of the topic map as an abstract bi-directional graph
● Definition of 12 axes (+2 NCL)
Introduction to Topic Maps
topicmapslab.de31
Navigation concept - Syntax
DIRECTION:: = '<<' | '>>'
AXIS-NAME:: = 'item' | 'indicators' | 'locators' | 'traverse' |'Players' | 'roles' | 'types' | 'reifier' | 'atomify' |'Characteristics' | 'super types' | 'scope'
STEP:: = DIRECTION AXIS-NAME [TOPIC-REF]
Introduction to Topic Maps
topicmapslab.de32
Axis - indicators
● no optional types
● Next: All Subject identifier of a topic
● Prev: addressing a topic with subject identifier
Introduction to Topic Maps
topicmapslab.de33
Axis - indicators
http://en.wikipedia.org/wiki/Puccini>> indicators
"Http://en.wikipedia.org/wiki/Puccini" <<indicators
Introduction to Topic Maps
topicmapslab.de34
Axis - locators
● no optional types
● Next: All Subject locator of a topic
● Prev: addressing a topic with subject Locator
Introduction to Topic Maps
topicmapslab.de35
Axis - locators
http://en.wikipedia.org/wiki/Puccini>> locators
"Http://en.wikipedia.org/wiki/Puccini" <<locators
Introduction to Topic Maps
topicmapslab.de36
Axis - item
● no optional types
● without pluralization!
Items →
● Next: all item identifier of a topic
● Prev: Addressing a topic of Item Identifier
Introduction to Topic Maps
topicmapslab.de37
Axis - item
http://en.wikipedia.org/wiki/Puccini>> item
"Http://en.wikipedia.org/wiki/Puccini" <<item
Introduction to Topic Maps
topicmapslab.de38
Axis - types
● no optional types
● Next: all types of a topic or the type of topic mapsConstruct
● Prev: all instances of a type Topic
● NCL: instances - Axis
● Next: all instances of a topic type● Prev: all types of topics or the type of Topic
Maps construct
Introduction to Topic Maps
topicmapslab.de39
Axis - types
http://en.wikipedia.org/wiki/Puccini>> types
http://psi.ontopia.net/music/composer <<types
http://en.wikipedia.org/wiki/Puccini <<instances
http://psi.ontopia.net/music/composer>> instances
Introduction to Topic Maps
topicmapslab.de40
Axis - super types
● no optional types
● forward: all the super types of a type Topic
● Prev: all sub-types of a type Topic
● NCL: subtypes - Axis
● Next: all sub-types of a type Topic● Prev: all super types of a type Topic
Introduction to Topic Maps
topicmapslab.de41
Axis - super types
http://psi.ontopia.net/music/composer>> super types
http://psi.ontopia.net/music/musician <<super types
http://psi.ontopia.net/music/composer <<subtypes
http://psi.ontopia.net/music/musician>> subtypes
Introduction to Topic Maps
topicmapslab.de44
e1
A
B C
E F
e2 g1 g2
TMQL - Type Hierarchy
E>> super types
Introduction to Topic Maps
46
Axis - characteristics
● forward: all the features of a topic
● Prev: the topic with the property
● predefined types
● all name● All Occurrences
topicmapslab.de47
>> Characteristics
http://en.wikipedia.org/wiki/Puccini>> Characteristics tm: occurrence
Introduction to Topic Maps
topicmapslab.de
e1
Name 1 t
g
Occurrence 1
Occurrence 2
t
g
TMQL - characteristics axis
TMQL Query: e1>> characteristics g
Introduction to Topic Maps
topicmapslab.de
Topic Maps Query Language
Sven Krusty M. Sc.
Topic Maps Lab at the University of Leipzig
Session 2
Introduction to Topic Maps
topicmapslab.de
Agenda
1. Navigation Concept II
2. Path Language - Draft 2010 (short view)
Introduction to Topic Maps
topicmapslab.de4
Navigation concept
● based on the proxy concept of TMRM
● Definition of 12 axes (+2 NCL)
topicmapslab.de5
DIRECTION:: = '<<' | '>>'
AXIS-NAME:: = 'item' | 'indicators' | 'locators' | 'traverse' |
'Characteristics' | 'super types' | 'scope'
STEP:: = DIRECTION AXIS-NAME [TOPIC-REF]
Introduction to Topic Maps
topicmapslab.de
Axis - indicators
●
● Next: All Subject identifier of a topic
●
Introduction to Topic Maps
topicmapslab.de10
no optional types
Items →
Next: all item identifier of a topic
topicmapslab.de
● no optional types
●
Construct
●
Next: all instances of a topic type● Prev: all types of topics or the type of Topic
Introduction to Topic Maps
13
http://en.wikipedia.org/wiki/Puccini <<instances
http://psi.ontopia.net/music/composer>> instances
Introduction to Topic Maps
topicmapslab.de17
e1
A
B CD
E F G
e2 g1 g2
TMQL - Type Hierarchy
e1>> types
topicmapslab.de
Axis - characteristics
http://en.wikipedia.org/wiki/Puccini>> Characteristics tm: name
topicmapslab.de26
Axis - players
● Next: all players an association
● by an association of type Topic● optional type = Role Type
● Prev: all association with the player
● optional type = Role Type
Introduction to Topic Maps
topicmapslab.de27
Axis - players
http://en.wikipedia.org/wiki/Puccini <<players
http://psi.ontopia.net/music/composed-by>> players
Introduction to Topic Maps
topicmapslab.de
Axis - roles
● Next: all types of roles an association
●
●
optional type = type of association
Introduction to Topic Maps
topicmapslab.de41
Draft 2010
● only path expression
● Changes
● navigation similar concept with a modified syntax●
● additional axes● Removal of some axes
Syntax closer to XPath
Standard axles for each construct type (axes optional)
Introduction to Topic Maps
topicmapslab.de42
pathspec → axis '::' anyref | axis '::' | anyref | assocpattern
filter → boolfilter | scope filter
Introduction to Topic Maps
Postfix
as a supplement for Path Expression (simple content)
● allow precise definition of the result set in PathExpressions
● Types
● Filter● Projection
Introduction to Topic Maps
topicmapslab.de15
Quantitative Boolean expression
% Prefix o http://psi.ontopia.net/music/
/ / O: composer
[
At most 3$ Opera IN / / o: operaSatisfies $ opera>> traverse o: composed-by ==.
]
→ all the composers who composed more than 3 operahave
topicmapslab.de16
Quantitative Boolean expression
numerically-free condition
● exact number of satisfying tuples irrelevant
● Maximum upper
EVERY binding-set satisfies boolean-expression
NCL-Filter - Filter Index
● special tuple from the result sequence
● empty set if index is outside the possible range
● Syntax:
[Number] → [$ # == number]● Example:
/ / Http://psi.ontopia.net/music/composer / tm: name [0]
Introduction to Topic Maps
topicmapslab.de24
●
● Zero-based indexes
all items covered by the index range
● Syntax
[A .. b] → [a <= $ # $ # AND <b]●
Introduction to Topic Maps
topicmapslab.de
NCL-Filter - Filter Scope
Filtering by Themes
@ Theme → [. >> Scope == theme]
[@ Theme] → [. >> Scope == theme]
● Example:
/ / Http://psi.ontopia.net/music/composer / tm: name
[@ Http://psi.ontopia.net/basename/short-name]
Introduction to Topic Maps
topicmapslab.de33
% Prefix o http://psi.ontopia.net/music/
/ / O: composer
(
. ,
. / Tm: occurrence,
. >> Indicators
Introduction to Topic Maps
topicmapslab.de34
Projection
% Prefix o http://psi.ontopia.net/music/
/ / O: composer
(
. ,
. / Tm: name,
. / Tm: occurrence,
. >> Indicators)
Projektionstupel
Introduction to Topic Maps
36
● allowed in so-called value-expression or content
● eg part of a Boolean expression● different types
Mathematical Operators
Comparison operators●
Introduction to Topic Maps
topicmapslab.de44
Comparison operators
● less than or equal '<='
● Supported data types:
- Number- String- Date- Time- DateTime
Introduction to Topic Maps
topicmapslab.de
Comparison operators
greater-than '>'
Supported data types:
-
-
Time
51
● Intersection of '=='
● returns the intersection of both sets● Example:
Note: Draft 2010 replaced by 'intersect'
Introduction to Topic Maps
topicmapslab.de
Review - Session 3
Postfix
● Filter
- Boolean expression- Filter types
Projection
Operators
● Description:
● returns the length of string literals
other constructs are converted to literal
Note Draft 2010: renamed 'string-length'
Introduction to Topic Maps
topicmapslab.de11
Feature - length
● Example
% Prefix o http://psi.ontopia.net/music/
→ all the names of Puccini with length 10
Introduction to Topic Maps
topicmapslab.de12
Construct literal transformation
● Topic → Name, Subject, Identifier, Subject locator Item Identifier
● Name → string literal
● Occurrence → string literal
● Variant → string literal
● Role → Item Identifier
Association → Item Identifier
Functions TMQL4J
● Identifier:
● Arguments: a set and two numeric values
● Description:
Sub-set of strings defined by numerical values● numeric values define maximum range● Example: substring ("abc", 0, 9)
= {"Abc"}
Note Draft 2010: 3 Argument defines the set of characters
Introduction to Topic Maps
topicmapslab.de20
Features - Draft 2010
● Identifier: starts-with
● Arguments: a set of literals and Vergleichsliteral
● Description:
Checking whether literal begins with Vergleichsliteral● Example: starts-with ({"ab", "bc"}, "a")
topicmapslab.de
Features - Draft 2010
Identifier: normalize-space
● Arguments:
● Description:
● remove multiple occurrences of spaces● normalize-space ({"ab", "bc"})
= {"Ab", "bc"}
26
Features - Draft 2010
● Identifier: translate
● Arguments: a set of literals, and two more literals
● Description:
replaces each character of the 2nd Literal characters by the 3rd
Example: translate ("Puccini", "PCI", "xyz")
= {"Xuyyznz"}
Introduction to Topic Maps
topicmapslab.de32
Identifier: TopicMap
Arguments: no
● Description:
● returns the instance of the Topic Map
Introduction to Topic Maps
topicmapslab.de33
Features - Draft 2010
● Lite Ralf fonctions
● Transformation of construct to literals of theType
● Features
string● boolean● number
unsorted result
{["C", "AA"] ["A", "BA"] ["C", "AB"] ["D", "AD"]}
Result?
1: {["A", "BA"] ["C", "AA"] ["C", "AB"] ["D", "AD"]}
2:
Introduction to Topic Maps
10
Sorting - Routine
... (/ Tm. Name [0] / tm. Name [1] ASC)
unsorted result
{["C", "AA"] ["A", "BA"] ["C", "AB"] ["D", "AD"]}
{["A", "BA"] ["C", "AA"] ["C", "AB"] ["D", "AD"]}
Introduction to Topic Maps
topicmapslab.de11
Sorting - Routine
Query
... (/ Tm. Name [0] DESC, / tm. Name [1])
unsorted result
{["C", "AA"] ["A", "BA"] ["C", "AB"] ["D", "AD"]}
sorted result?
Introduction to Topic Maps
topicmapslab.de12
Sorting - Routine
Query
... (/ Tm. Name [0] DESC, / tm. Name [1])
unsorted result
{["C", "AA"] ["A", "BA"] ["C", "AB"] ["D", "AD"]}
{["D", "AD"] ["C", "AA"] ["C", "AB"] ["A", "BA"]}
topicmapslab.de13
... (/ Tm. Name [0] DESC, / tm. Name [1] DESC)
{["C", "AA"] ["A", "BA"] ["C", "AB"] ["D", "AD"]}
sorted result?
topicmapslab.de
Pragma-definition - transitivity
Draft only defined as a transitive pragma
Signature
● identifier: taxonometry
QIRI: tm: intransitive
Introduction to Topic Maps
topicmapslab.de23
Pragma-definition - transitivity
% Prefix o http://psi.ontopia.net/
% Prefix tml http://www.topicmapslab.de/
% Pragma taxonometry tm: intransitive
/ / O: Composer + + / / tml: person
Introduction to Topic Maps
topicmapslab.de25
Select Style
syntactic similarity to SQL
● consists of a set of sub-expressions
● allow binding of variables
● single type with key word for duplicate - treatment andSelection
Introduction to Topic Maps
predefined variables
● reserved system variables
@ _ Current Tuple
$ # current index
%% Environment Topic Map
% _ requested Topic Map
$ [0-9] + indexed element of a tuple
$ _ write-only variable
Introduction to Topic Maps
topicmapslab.de36
Where clause
% Prefix o http://psi.ontopia.net/music/
SELECT $ composer
WHERE $ o ISA composer: composer
% Prefix o http://psi.ontopia.net/music/
% Prefix l http://psi.ontopia.net/literature/
SELECT $ composer, $ opera
WHERE $ composer ISA o: o AND composer: composed-by (l: work:$ Opera, o: composer: $ composer)
Introduction to Topic Maps
topicmapslab.de5
FLW (O) R-Style
● syntactic similarity to XML FLW (O) R or
●
● limited syntactic thickness (um Cf SELCT)
● allow binding of variables
●
Introduction to Topic Maps
topicmapslab.de6
[< for <Binding-set>>]
[ boolean-expression]
[ by <Value-expression>]
return
Introduction to Topic Maps
topicmapslab.de18
For clause
defined range of values to bind variables
can contain multiple binding definitions
● Pattern
FOR variable IN context
For other IN other context-
...
Introduction to Topic Maps
topicmapslab.de19
For clause
% Prefix o http://psi.ontopia.net/music/
% Prefix l http://psi.ontopia.net/literature/
IN FOR $ composer / o: composer
WHERE o: composed-by (l: work: $ opera, o: composer: $ composer)
ORDER BY $ composer / tm: name [0], $ opera / tm: name [0] DESC
RETURN $ composer, $ opera
→ Area of the variable $ composer limited to all composers
Introduction to Topic Maps
topicmapslab.de
For clause
% Prefix o http://psi.ontopia.net/music/
IN FOR $ composer http://en.wikipedia.org/wiki/Puccini
WHERE o: composed-by (l: work: $ opera, o: composer: $ composer)
ORDER BY $ composer / tm: name [0], $ opera / tm: name [0] DESC
Introduction to Topic Maps
XML - Content
● XML fragments are defined by XML tags
XML fragments can contain a lot of queries
●
● To use information as XML fragmentsExport (Web Services)
Introduction to Topic Maps
topicmapslab.de31
XML - Content
% Prefix o http://psi.ontopia.net/music/
% Prefix l http://psi.ontopia.net/literature/
RETURN <yml>
{
IN FOR $ composer / o: composer
RETURN <composer> $ {Composer} </composer>
}
</yml>
Introduction to Topic Maps
topicmapslab.de32
XML - Content
● Topic Maps elements are transformed into XTM fragment
● simple data types are translated into strings
Strings are not processed in the current written
topicmapslab.de
Topic Maps Query Language
Sven Krusty M. Sc.
Topic Maps Lab at the University of Leipzig
Introduction to Topic Maps
Conditional statement NCL
IN FOR $ topic / / tm: subject
RETURN
$ Topic>> indicators>> atomify [0] | | $ topic>> locator>> atomify [0]
Introduction to Topic Maps
topicmapslab.de11
TMQL Part II●
● TMQL based on Part I (TMQL - Query Language)
● syntactically based on the Draft 2007
Introduction to Topic Maps
topicmapslab.de12
TMQL Part II● defined change operations for Topic Maps
● Insert operation● Delete operation● Change operation● Merge rules
Introduction to Topic Maps
topicmapslab.de23
Merge expression● Merging of Topics under TMDM
● Definition of a set of topics that are to be merged
● Using variables
● Where clause restricts a range of values of the variables
● Grammar
merge-expression:: = MERGE <value-expression>
WHERE boolean-expression
Introduction to Topic Maps
topicmapslab.de24
Merge expression
MERGE / / http://psi.example.org/type [. / Email == "[email protected]"]
→ all topics that meet the following condition to be merged
Instance of type http://psi.example.org/type●
● Occurrence is worth at least one of these [email protected]
topicmapslab.de25
Merge expression
AND $ person / email == $ other / email
→ People with the same e-mail address are merged
Introduction to Topic Maps
topicmapslab.de
Definition of a set of association which are to merge
merge-expression:: = MERGE association definition
WHERE boolean-expression
Introduction to Topic Maps
27
equivalent to Predicate Invocation (limited syntax)
● supply quantity of the Association to match the defined pattern
● Ellipse highlights strict processing
association-definition :: = <Part [...]>
part :: = (Ident | variable) ':' (ident | variable)
Introduction to Topic Maps
topicmapslab.de28
Association definition
m: composed-by (
m: composer: http://en.wikipedia.net/wiki/Puccini)
→ delivers all the associations which● of type "composer" is● exact role of type "composer" played by
Puccini has
Introduction to Topic Maps
topicmapslab.de29
Association definition
m: composed-by (
tm: subject: http://en.wikipedia.net/wiki/Puccini, ...)
→ delivers all the associations which
● at least played a role of Puccini has→ type of role is not restricted
30
% Prefix m http://psi.ontopia.net/music/
MERGE m: composed-by (
tm: subject: http://en.wikipedia.net/wiki/Puccini, ...)
→ merge all associations of type "composed"
Introduction to Topic Maps
topicmapslab.de
● context-free changes (context, topic map!)
Add new association
→ without CTM
topicmapslab.de8
Create New Topic
● Keyword: topics
● Definition of Identifier
● Identifier already in use? → no change
UPDATE topics ADD "http://psi.example.org/topic"
→ no identifier type defined (default: Subject identifier)
Introduction to Topic Maps
topicmapslab.de9
Topic with subject identifiers to create
UPDATE topics ADD "http://psi.example.org/topic"
UPDATE topics ADD "http://psi.example.org/topic" ~
UPDATE topics ADD "http://psi.example.org/topic" <<indicators
→ new topic with a subject identifier
Introduction to Topic Maps
topicmapslab.de
Topic with Item Identifier Create
UPDATE topics ADD "http://psi.example.org/topic!
Introduction to Topic Maps
●
UPDATE associations ADD association-type (role-type: player)
→ all topics are not produced in existence
Introduction to Topic Maps
topicmapslab.de19
Name change
● Keyword: names
● Optional: no
● Context:
UPDATE names SET "name"
WHERE http://en.wikipedia.org/wiki/Puccini>> characteristicstm: name @ short-name
Introduction to Topic Maps
27
Add new subtype
● subtypes
no
Context: Topic
UPDATE ADD subtypes http://en.wikipedia.org/wiki/Puccini
WHERE http://psi.example.org/type
Introduction to Topic Maps
topicmapslab.de28
Players change
● Keyword: players
● Optional: Role type (default: all roles!)
●
UPDATE players SET composer http://psi.example.org/me
WHERE http://en.wikipedia.org/wiki/Puccini <<players
Introduction to Topic Maps
topicmapslab.de
Keyword:
● Topic (players)
Context:
WHERE http://en.wikipedia.org/wiki/Puccini <<players