Einführung in Topic...
Transcript of Einführung in Topic...
Einführung in Topic Maps
topicmapslab.de2
Oct. 2004
– matriculation at the university of cooperative
education at Leipzig
Sep 2007
– graduation in Computer Science with the diploma
Oct 2007
– matriculation at the university of Leipzig
introduce myself
Einführung in Topic Maps
topicmapslab.de3
May 2009
– joining the Topic Maps Lab at the university of
Leipzig
Sep 2009
– finishing my study with the Master of Computer
Science
– the subject of my master's thesis was the
implementation of TMQL4J
introduce myself
Einführung in Topic Maps
topicmapslab.de4
1 Introduction of the language TMQL
1.1 Why do we need a language like TMQL?
1.2 How can we use TMQL?
1.3 Are there any alternatives for TMQL?
2 TMQL – the basics of the ISO draft
2.1 grammar levels
2.2 literals and references
2.3 navigation
2.4 variables and other concepts
Agenda
Einführung in Topic Maps
topicmapslab.de5
3 Learning the high-level expressions
3.1 Path Expression
3.2 Select Expression
3.3 Flwr Expression
Agenda
Einführung in Topic Maps
topicmapslab.de7
Introduction of the language TMQL
● TMQL is a topic maps query language
● part of ISO standardization ( ISO 18048 )
● discussions about parts of the final standard
● supports different styles of querying
● supports the definition of ontology in context of a query
Einführung in Topic Maps
topicmapslab.de8
Why do we need a language like TMQL?
● the number of applications using topic maps increases
fast
● the data base becomes to complex
● complex handling by using TMAPI code fragments
● complex terminology and ontology
● number of topics and associations too huge
● different views of the data in context of different
business processes
Einführung in Topic Maps
topicmapslab.de9
Why do we need a language like TMQL?
● example TMAPI vs TMQL
→ extract all player names of the association
member_of
Einführung in Topic Maps
topicmapslab.de10
● TMAPI ( for example in Java )
TopicMapSystemFactory factory = TopicMapSystemFactory.newInstance();
TopicMapSystem topicMapSystem = factory.newTopicMapSystem();
TopicMap topicMap = topicMapSystem.getTopicMap("my-topic-map");
// type of the association
Topic type = (Topic)topicMap.getConstructById("member_of");
// extract all association items of the type member-of
TypeInstanceIndex index = topicMap.getIndex(TypeInstanceIndex.class);
for ( Association association : index.getAssociations(type)){
// extract all roles of the association item
for ( Role role : association.getRoles()){
// extract the role player and the names
names.addAll(role.getPlayer().getNames());
}
Einführung in Topic Maps
topicmapslab.de11
● TMQL4J Version 1.1
TopicMapSystemFactory factory = TopicMapSystemFactory.newInstance();
TopicMapSystem topicMapSystem = factory.newTopicMapSystem();
TopicMap topicMap = topicMapSystem.getTopicMap("my-topic-map");
// initialize the tmql4j engine
IQuery query = new QueryImpl("member_of << types >> players / tm:name")
TMQLRuntime runtime = new TMQLRuntime(topicMapSystem,
Arrays.asList(new TopicMap[] { topicMap }), query);
runtime.run();
// extract result set
names.addAll((ITupleSequence<Name>) runtime
.getStoredValue(TMQLRuntime.TMQL_RUNTIME_RESULTPROCESSING_RESULT));
Einführung in Topic Maps
topicmapslab.de12
How can we use TMQL?
● different opportunities
● TMQL4J
● PerlTM
● Ontopia Topic Maps Engine ( tmql4ontopia )
Einführung in Topic Maps
topicmapslab.de13
TMQL4Ontopia
● generic query plug-in for the Omnigator
● current version 0.0.1
● use the TMQL4J engine
● implements Ontopia specific modules
● allows result export as CSV file
Einführung in Topic Maps
topicmapslab.de16
Are there any alternatives for TMQL?
● there are other languages for querying topic maps
● Tolog
– a language similar to Prolog
– supports predicate-invocations and boolean
combinations
● Toma
– a language similar to SQL
– developed by Rani Pinchuk
Einführung in Topic Maps
topicmapslab.de17
Are there any alternatives for TMQL?
● but:
● there expressiveness are lower than TMQL
● TMQL supports different query styles for different domains
● TMQL supports transformations to CTM and XTM
Einführung in Topic Maps
topicmapslab.de19
TMQL – the basics of the ISO draft
● only the basics of the ISO draft
● basics important to understand the syntax of TMQL
● learning high-level expressions at chapter 3
Einführung in Topic Maps
topicmapslab.de20
TMQL – grammar levels
● define the terminals of the language
● based on Regular Expressions
example: $variable | SELECT | FOR
Token Level
Einführung in Topic Maps
topicmapslab.de21
TMQL – grammar levels
● define the production rules of TMQL
● combination of terminals
example: tuple-expression := <value-expression>
Token Level
Canonical Level
Einführung in Topic Maps
topicmapslab.de22
TMQL – grammar levels
Token Level
Canonical Level
Non-Canonical Level
● define the shortcuts as term substitutions
anchor / tm:name ==> anchor >> chracteristics tm:name
Einführung in Topic Maps
topicmapslab.de23
TMQL – literals or atoms
● atoms defined as constant literals
● atoms are data-types and operators
● supported data-types are an extract of the CTM data-
types and XSD date and dateTime
Einführung in Topic Maps
topicmapslab.de24
TMQL – literals or atoms
atom possible value
atom 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 /"([^"]|\")*"/ | /'([^']|\')*'/
source: http://www.isotopicmaps.org/tmql/tmql.html
Einführung in Topic Maps
topicmapslab.de25
TMQL – references
● references used to identify topics in context of a TMQL
query
● supports
– item-identifier
– subject-identifier
– subject-locators
● possible to use relative IRI as identifier or locator
Einführung in Topic Maps
topicmapslab.de26
TMQL – references example
● item-identifier
puccini
● subject-identifier
http://psi.ontopedia.net/Puccini
● subject-locator
http://locators.ontopedia.net/Puccini
Einführung in Topic Maps
topicmapslab.de27
TMQL – navigation
● based on the TMRM ( Topic Maps Reference Model )
● define 12 axes
● can use as a part of path expression
● symbolize navigation throw the abstract topic map graph
● each axis can used in two directions
● syntax
navigation := axis-name direction optional-type
direction := << | >>
Einführung in Topic Maps
topicmapslab.de28
TMQL – identifier axes
● one axis for each identifier type
● do not supports optional types
● forward-direction
● deliver the identifier of the given topic
● only supports topic items
● backward-direction
● deliver the topic with this identifier
● only supports string literals
Einführung in Topic Maps
topicmapslab.de29
TMQL – identifier axes examples
● item-identifier
http://psi.ontopedia.net/Puccini >> item
● subject-identifier
http://psi.ontopedia.net/Puccini >> indicators
● subject-locator
http://psi.ontopedia.net/Puccini << locators
Einführung in Topic Maps
topicmapslab.de30
TMQL – type-hierarchy axes
● supports is-instance-of and a-kind-of associations
● forward-direction
● deliver the types of given instance ( type-instance)
● deliver the supertypes of given type ( supertype-subtype)
● supports topic items or association items
● backward-direction
● deliver the instances of given type ( type-instance)
● deliver the subtypes of given type ( supertype-subtype)
● supports topic items or association items
Einführung in Topic Maps
topicmapslab.de31
TMQL – type hierarchy axes examples
● type-instance
http://psi.ontopedia.net/Puccini >> types
http://psi.ontopedia.net/Composer << types
● supertype-subtype
http://psi.ontopedia.net/Composer >> supertypes
http://psi.ontopedia.net/Composer << supertypes
Einführung in Topic Maps
topicmapslab.de32
TMQL – type hierarchy axes examples
e1
A
B CD
E F G
e2 g1 g2
Einführung in Topic Maps
topicmapslab.de33
e1
A
B CD
E F G
e2 g1 g2
TMQL – type hierarchy axes examples
TMQL-Query: e1 >> types
Einführung in Topic Maps
topicmapslab.de34
e1
A
B CD
E F G
e2 g1 g2
TMQL – type hierarchy axes examples
TMQL-Query: E >> supertypes
Einführung in Topic Maps
topicmapslab.de35
e1
A
B CD
E F G
e2 g1 g2
TMQL – type hierarchy axes examples
TMQL-Query: A >> instances
Einführung in Topic Maps
topicmapslab.de36
TMQL – association axes
● forward-direction
● deliver all roles of given association ( roles )
● deliver all players of given association ( players )
● deliver all players playing with given topic ( traverse )
● backward-direction
● deliver all association items using the given role ( roles )
● deliver all association items using the given player ( players )
● deliver all associations items connected with the given
association by the same player ( traverse )
Einführung in Topic Maps
topicmapslab.de37
TMQL – association axes examples
● roles
http://psi.ontopedia.net/composed_by >> roles
http://psi.ontopedia.net/Composer << roles
● players
http://psi.ontopedia.net/composed_by >> players
http://psi.ontopedia.net/Puccini << players
● traverse
http://psi.ontopedia.net/Puccini >> traverse
http://psi.ontopedia.net/composed_by << traversee
Einführung in Topic Maps
topicmapslab.de39
TMQL – association axes
TMQL-Query: p2 << players >> roles [ . >> player == p2 ]
r1 a1
p1 p3p2
r2 r3 r4a2
Einführung in Topic Maps
topicmapslab.de40
r1 a1
p1 p3p2
r2 r3 r4a2
TMQL – association axes
TMQL-Query: a1 >> players
Einführung in Topic Maps
topicmapslab.de41
r1 a1
p1 p3p2
r2 r3 r4a2
TMQL – association axes
TMQL-Query: p2 >> traverse
Einführung in Topic Maps
topicmapslab.de42
TMQL – characteristics axis
● forward-direction
● deliver all names and occurrences of given topic
● only supports topic items
● backward-direction
● deliver the topic item using the given characteristic
● only supports names and occurrences
Einführung in Topic Maps
topicmapslab.de43
TMQL – characteristics axis examples
● all names of puccini
http://psi.ontopedia.net/Puccini >> characteristics
tm:name
● all occurrences of puccini
http://psi.ontopedia.net/Puccini >> characteristics
tm:occurrence
Einführung in Topic Maps
topicmapslab.de44
e1
Name 1
Name 2
t
g
Occurrence 1
Occurrence 2
t
g
TMQL – characteristics axis examples
Einführung in Topic Maps
topicmapslab.de45
e1
Name 1
Name 2
t
g
Occurrence 1
Occurrence 2
t
g
TMQL – characteristics axis examples
TMQL-Query: e1 >> characteristics g
Einführung in Topic Maps
topicmapslab.de46
TMQL – scope axis
● forward-direction
● deliver the scope of the given construct
● supports names, occurrences or associations
● backward-direction
● deliver all constructs with the given scope
● only supports topic items
Einführung in Topic Maps
topicmapslab.de47
TMQL – scope axis examples
● the scope of the names of puccini
http://psi.ontopedia.net/Puccini >> characteristics
tm:name >> scope
● all constructs with the scope web
http://psi.ontopedia.net/Web << scope
Einführung in Topic Maps
topicmapslab.de48
TMQL – reifier axis
● forward-direction
● deliver the reifier of the given construct
● supports names, occurrences or associations
● backward-direction
● deliver the construct reifies by the given topic item
● only supports topic items
Einführung in Topic Maps
topicmapslab.de49
TMQL – reifier axis examples
● the construct reified by the topic item A Philatelic
History
http://home.prcn.org/~pauld/opera/ >> reifier
● the reifier of this construct
http://home.prcn.org/~pauld/opera/ >> reifier <<
reifier
Einführung in Topic Maps
topicmapslab.de50
TMQL – atomify axis
● forward-direction
● deliver the value of the given characteristics
● supports names or occurrences
● backward-direction
● deliver the characteristics with the given value
● supports all literals
Einführung in Topic Maps
topicmapslab.de51
TMQL – atomify axis examples
● the value of the name puccini
http://psi.ontopedia.net/Puccini >>
characteristics tm:name >> atomify
or
http://psi.ontopedia.net/Puccini / tm:name
Einführung in Topic Maps
topicmapslab.de52
TMQL – variables
● using in context of high-level expression
● supported by select expression and flwr expression
● different prefixes
$ only bind literals or items
@ only bind a tuple
% only bind a sequence
Einführung in Topic Maps
topicmapslab.de53
TMQL – variables
Tuple
Tuples are ordered collections of simple values (atoms and items).
Tuple-Sequence
Tuple sequences are sequences of tuples where all tuples have identical length. Tuple sequences can be generated with tuple expressions.
Einführung in Topic Maps
topicmapslab.de54
TMQL – protected variables
● variable names can post-fixed by different number of primes '
● variables only differ in number of primes
● can not be bind to the same value
Einführung in Topic Maps
topicmapslab.de55
TMQL – variables example
● variables
$composer // can be bind to puccini
@composers // can be bind to a tuple
%composers // can be bind to a sequence
Einführung in Topic Maps
topicmapslab.de56
TMQL – variables example
● tuple
( puccini , "puccini" , “1900-01-01” )
● sequence
{ ( puccini , "puccini" , “1900-01-01” ) ,
( fontane , "fontane" , “1900-01-01” ) }
Einführung in Topic Maps
topicmapslab.de59
TMQL – Environment Clause
● define additional environment information for the querying
process
● new environment information only valid during the querying
process and in the scope of the current query
● define prefixes and pragmas
Einführung in Topic Maps
topicmapslab.de60
TMQL – Prefix definitions
● define qnames for relative IRIs
● like using-clause of tolog
● always triplets
● starts with the keyword %prefix
● syntax: %prefix identifier QIRI
Einführung in Topic Maps
topicmapslab.de61
TMQL – Pragma definitions
● define ontology knowledge
● stored as topics
● always triplets
● starts with the keyword %pragma
● syntax: %pragma identifier QIRI
Einführung in Topic Maps
topicmapslab.de62
TMQL – Environment Clause Examples
%prefix tml http://www.topicmapslab.de/
%prefix ontopedia http://psi.ontopedia.net/
%pragma taxonometry tm:intransitive
Einführung in Topic Maps
topicmapslab.de64
TMQL – Path Expression
● combination of navigation steps or predicate invocations
● predicate-invocation
– describe associations
– similar to tolog
Einführung in Topic Maps
topicmapslab.de65
TMQL – Predicate Invocations
● describe associations
● define a set of role-player-restrictions
● predicate invocations are a strict operation
– does not match if number of restrictions and association
roles are different
– hint: tolog predicates are not strict
● the ellipsis extension effects in non-strict operation
Einführung in Topic Maps
topicmapslab.de66
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : le_villi , … )
Einführung in Topic Maps
topicmapslab.de67
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : le_villi , … )
association type
Einführung in Topic Maps
topicmapslab.de68
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : le_villi , … )
role type
Einführung in Topic Maps
topicmapslab.de69
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : le_villi , … )
player
Einführung in Topic Maps
topicmapslab.de70
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : le_villi , … )
ellipsis
Einführung in Topic Maps
topicmapslab.de71
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : $OPERA )
{composer:puccini, opera:le_villi };
{composer:puccini, opera:la_boheme};
{composer:puccini, opera:la_rondine, co-composer:x };
Einführung in Topic Maps
topicmapslab.de72
TMQL – predicate-invocation example
composed_by ( composer : puccini , opera : $OPERA )
{composer:puccini, opera:le_villi };
{composer:puccini, opera:la_boheme};
{composer:puccini, opera:la_rondine, co-composer:x };
→ strict operation does not match
Einführung in Topic Maps
topicmapslab.de73
TMQL – filter and projection
● filters
– post-fixed after navigation
– surrounded by square brackets
– supported filters
– index [ number ]
– index-range [ number .. number ]
– types [ ^ type ]
– scope [ @ scope ]
– boolean-expressions [ … ]
Einführung in Topic Maps
topicmapslab.de74
TMQL – filter and projection
● projection
– post-fixed after navigation
– surrounded by round brackets
– defined as a tuple-expression
– simple navigation from current node
– current node symbolize by dot
Einführung in Topic Maps
topicmapslab.de75
TMQL – filter and projection example
● the first name of puccini
http://psi.ontopedia.net/Puccini >> characteristics tm:name [0]
● projection of characteristics and associations played by
instances of composer
http://psi.ontopedia.net/Composer << types
( . >> characteristics , . << players )
Einführung in Topic Maps
topicmapslab.de76
TMQL – filter and projection example
composer << types ( . >> characteristics , . << players )
navigation
Einführung in Topic Maps
topicmapslab.de77
TMQL – filter and projection example
composer << types ( . >> characteristics , . << players )
projection definition
Einführung in Topic Maps
topicmapslab.de78
TMQL – filter and projection example
composer << types ( . >> characteristics , . << players )
current node
Einführung in Topic Maps
topicmapslab.de79
TMQL – filter and projection example
composer << types ( . >> characteristics , . << players )
projection
Einführung in Topic Maps
topicmapslab.de81
TMQL – Select Expression
● structure is similar to SQL
● supports the concept of variables
● variable can bind depending on condition
● any used variable have to bind to a valid value
Einführung in Topic Maps
topicmapslab.de82
TMQL – Select Expression
select-expression ::= select < value-expression >[ from value-expression ][ where boolean-expression ][ order by < value-expression > ][ unique ][ offset value-expression ][ limit value-expression ]
Einführung in Topic Maps
topicmapslab.de83
TMQL – Select Clause
● only non-optional clause of a select expression
● starts with the keyword SELECT
● contains a number of value expressions
– variables
– navigations
– Functions
● variables have to bind in context of where-clauses
Einführung in Topic Maps
topicmapslab.de84
TMQL – Select Clause example
SELECT http://psi.ontopedia.net/Puccini / tm:name ,
http://psi.ontopedia.net/Puccini / tm:occurrence
Einführung in Topic Maps
topicmapslab.de85
TMQL – Where Clause
● optional clause of a select expression
● starts with the keyword WHERE
● contains a number of boolean-expressions
– exists-clause
– forall-clause
– negation
– conjunction
– disjunction
Einführung in Topic Maps
topicmapslab.de86
TMQL – Where Clause example
SELECT $composer
WHERE $composer ISA http://psi.ontopedia.net/Composer
Einführung in Topic Maps
topicmapslab.de88
TMQL – Exists Clause● specifies the number of items satisfying a condition
● numerically unrestricted
– number of satisfying items is not important
– starts with keyword EXISTS or SOME
– can contain path expressions
● numerically restricted
– define the number of satisfying items as upper or lower
bounds
AT LEAST number set SATISFIES boolean-expression
AT MOST number set SATISFIES boolean-expression
Einführung in Topic Maps
topicmapslab.de89
TMQL – Exists Clause example
SELECT $composer
WHERE EXISTS $composer ISA http://psi.ontopedia.net/Composer
SELECT $composer
WHERE AT LEAST 4 $opera IN // http://psi.ontopedia.net/Opera
SATISFIES http://psi.ontopedia.net/composed_by
( http://psi.ontopedia.net/Composer : $composer ,
http://psi.ontopedia.net/Work : $work )
Einführung in Topic Maps
topicmapslab.de90
TMQL – Forall Clause
● all items have to satisfy the condition
EVERY variable IN content SATISFIES boolean-expression
Einführung in Topic Maps
topicmapslab.de91
TMQL – Forall Clause example
SELECT $composer
WHERE
EVERY $opera IN $composer >> traverse
SATISFIES $opera == http://psi.ontopedia.net/Le_Villi
Einführung in Topic Maps
topicmapslab.de92
TMQL – boolean combination
● negation symbolized by the keyword NOT
● conjunction symbolized by the keyword AND
● disjunction symbolized by the keyword OR
Einführung in Topic Maps
topicmapslab.de93
TMQL – boolean combination example
SELECT $composer
WHERE NOT ( $composer ISA
http://psi.ontopedia.net/Composer )
SELECT $composer , $opera
WHERE
$composer ISA http://psi.ontopedia.net/Composer
AND
$opera ISA http://psi.ontopedia.net/Opera
Einführung in Topic Maps
topicmapslab.de95
TMQL – From Clause
● optional clause of a select expression
● starts with the keyword FROM
● define the context of the select expression
● have to return a topic map or sequence of constructs
Einführung in Topic Maps
topicmapslab.de96
TMQL – From Clause example
SELECT $composer
FROM // http://psi.ontopedia.net/Musician
WHERE $composer ISA http://psi.ontopedia.net/Composer
Einführung in Topic Maps
topicmapslab.de97
TMQL – Unique Clause
● optional clause of a select expression
● only the keyword UNIQUE
● unify the result set
Einführung in Topic Maps
topicmapslab.de98
TMQL – Unique Clause example
SELECT $composer
FROM // http://psi.ontopedia.net/Musician
WHERE $composer ISA http://psi.ontopedia.net/Composer
UNIQUE
Einführung in Topic Maps
topicmapslab.de99
TMQL – Order-By Clause
● optional clause of a select expression
● starts with the keyword ORDER BY
● define an order of the variable bindings of the where clause
Einführung in Topic Maps
topicmapslab.de100
TMQL – Order-By Clause example
SELECT $composer
FROM // http://psi.ontopedia.net/Musician
WHERE $composer ISA http://psi.ontopedia.net/Composer
ORDER BY $composer / tm:name [0]
Einführung in Topic Maps
topicmapslab.de101
TMQL – Limit and Offset
● optional clauses of a select expression
● starts with the keyword LIMIT or OFFSET
● define the selection window after querying
Einführung in Topic Maps
topicmapslab.de102
TMQL – Limit and Offset example
SELECT $composer
FROM // http://psi.ontopedia.net/Musician
WHERE $composer ISA http://psi.ontopedia.net/Composer
ORDER BY $composer / tm:name
OFFSET 2
LIMIT 10
Einführung in Topic Maps
topicmapslab.de104
TMQL – Flwr Expression
● similar to a programming or scripting language
● supports the concept of variables
● supports the definition of possible binding-set for variables
Einführung in Topic Maps
topicmapslab.de105
TMQL – Return Clause
● only non-optional clause of a flwr expression
● starts with the keyword RETURN
● contains a number of value expressions
– variables
– navigations
– functions
– XTM and CTM fragments
Einführung in Topic Maps
topicmapslab.de106
TMQL – Return Clause example
RETURN http://psi.ontopedia.net/Puccini / tm:name
Einführung in Topic Maps
topicmapslab.de107
TMQL – For Clause
● optional clause of a flwr expression
● starts with the keyword FOR
● can contain more than one for-clause
● define a variable set
Einführung in Topic Maps
topicmapslab.de108
TMQL – For Clause example
FOR $composer IN // http://psi.ontopedia.net/Composer
RETURN $composer
FOR $composer IN // http://psi.ontopedia.net/Composer
FOR $opera IN // http://psi.ontopedia.net/Opera
RETURN $composer, $opera
Einführung in Topic Maps
topicmapslab.de109
TMQL – Where Clause and Order-By
● optional clauses of a flwr expression
● same syntax and meaning like as a part of select expressions
Einführung in Topic Maps
topicmapslab.de110
Additional Information
[ISO-08] ISO Draft of TMQL
[SK-09] Conception, implementation and evaluation of a
TMQL-parser and interpreter