Upload
tmra
View
1.723
Download
2
Embed Size (px)
DESCRIPTION
CTM is the compact Topic Maps syntax for Topic Maps. This tutorial teaches the language model and syntax. It introduces the basic syntactical constructs and demonstrates their use in a number of examples. Attendees are expected to have a good understanding of the Topic Maps Data Model (TMDM).
Citation preview
CTM 1.0Compact Topic Maps Syntax
Tutorial
Lars Heuer <[email protected]>
TMRA 2008, Leipzig · 15.10.2008
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 2
Table of Contents
IntroductionOverviewDetailsCreate your own topic mapQuestions / Answers
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 3
Introduction
CTM is a textual Topic Maps syntax (like LTM and AsTMa=)Is meant to be human-friendlySupports TMDMStandard format (ISO 13250-6) unlike LTM and AsTMa=Human-readable, usable for examples, papers
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 4
Introduction
CTM is utilised by TMCL to define constraintsCTM will be used by TMQL for
INSERT operationsUPDATE operationsDELETE operations
Shares some similarities with TMQL (syntaxwise)Current draft (slightly outdated)http://www.isotopicmaps.org/ctm/
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 5
Introduction
CTM is nearly finished (feature-wise, syntax-wise)Next draft will appear within the next twomonthsCurrently no stable, upto-date CTM parser isavailable (should change soon)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 6
Overview – ToC
TopcisNamesOccurrencesLiteralsAssociationsCommentsSummary
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 7
Overview – Topics Topics are introduced with an identity and end with a dot (".") (often labeled as "topicblock")Typically topics start with a simple identifier, a subject identifier, or subject locator.
john-lennon . # Topic with an item identifier
http://en.wikipedia.org/wiki/John_Lennon . # subj. ident.
= http://www.google.com/ . # subject locator
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 8
Overview – Topics
An IRI is interpreted as subject identifierunless it is prefixed by an equal sign(or it is used as occurrence / variant value)Rootless IRIs (IRIs without "://") are notdetected, they have to be embedded into "<" ">":Topic with a subject identifier:
<mailto:[email protected]> .
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 9
Overview – Topics
Topic statements like names and occurrences are delimited by a semicolon(";")The semicolon is optional iff it is the last statement (if the next character is the dot which marks the end of the topic)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 10
Overview – Names
Names are introduced by a hyphen, followedby an optional name type and the valueExample:john-lennon- "John Lennon";- surname: "Lennon".
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 11
Overview – Names
Names are introduced by a hyphen, followedby an optional name type and the valueExample:john-lennon- "John Lennon";- surname: "Lennon".
Name type
Name value
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 12
Overview – Names
If the name type is not specified, the nameuses automatically the default topic nametypeThe name scope is introduced by an @ signfollowed by comma delimited themesExample:The-Beatles - "The Beatles";- "Fab Four" @nickname;- "Pilzköpfe" @nickname, de .
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 13
Overview – Occurrences
Occurrences start with the type, a colonfollowed by the valueExample:The-Beatleswebsite: http://www.beatles.com.uk.
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 14
Overview – Occurrence Scope
The scope is introduced by an @ sign followedby the themesExample:The-Beatleswebsite: http://www.beatles.com.uk ;website: http://beatles.de/ @de .
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 15
Overview – Literals
CTM provides some built-in datatypes:StringDateDateTimeIntegerDecimalIRI
These datatypes can be used as occurrenceand variant value
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 16
Overview – Literals – String
Example:TopicMaps- "Topic Maps";description: "A technology …".
The datatype of the occurrence "description" isset to xsd:string
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 17
Overview – Literals – Dates
Examples:McCartneybirthday: 1942-02-18.
Blog-Entrycreated: 2008-10-12T17:30:22 .
Datatype of "birthday" is set to xsd:date, dataype of "created" is xsd:dateTime
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 18
Overview – Literals – Numbers
Examples:McCartneyage: 66 .
CTMversion: 1.0 .
Datatype of "age" is set to xsd:integer, dataypeof "version" is xsd:decimal
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 19
Overview – Literals
Non-built-in datatypes can be expressed usingthe string value with an explicit datatype:"value"^^datatypeThe "datatype" is specified by an IRI or a QNameExamples:"09-19"^^xsd:gMonthDay"true"^^http://www.w3.org/2001/XMLSchema# boolean
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 20
Overview – Associations
member-of(group: TheBeatles,
member: john-lennon)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 21
Overview – Associations
member-of(group: TheBeatles,
member: john-lennon)
Association type
Role types
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 22
Overview – Associations
member-of(group: TheBeatles,
member: john-lennon)
Association type
Role types
Role players
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 23
Overview – Associations
The (optional) scope is added to an association by the @ sign followed by thethemesExample:member-of(group: blind-faith,
member: eric) @year-1969
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 24
Overview – Comments
Single line comments start with a hash ("#") and reach until the end of a lineMultiline comments start with #( and end with)#Examples:# I am a single line comment
#( line 1line 2 )#
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 25
Overview – Summary
Topics are introduced by an identity and end with a dot ("."). The "topic block"Topic statements must be delimited by a semicolon (";") unless it is the last statementNames are introduced with a hyphen ("-"), theyhave an optional explicit type and a value(string)Occurrences are introduced by the typefollowed by a literal
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 26
Overview – Summary
CTM has built-in literals but the user canspecify any datatype using the"value"^^datatype notationNotation for associations:
assoc-type(role-type1: role-player1,role-type2: role-player2, …)
The scope of a statement is introduced by the@ sign followed by comma-delimited themes
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 27
Details – ToC
Assigning additional identities to topicsCreating type-instance / supertype-subtyperelationshipsReificationEmbedded TopicsDirectivesTemplates
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 28
Details - Topics
Topics are not limited to one identity, anynumber of identities can be specifiedExample:
McCartneyhttp://en.wikipedia.org/Paul_McCartney ; http://de.wikipedia.org/Paul_McCartney .
Topic with the item identifier "McCartney" and two subject identifiers
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 29
Details - Topics
Example:
GoogleWebsite= http://www.google.com/ .
Topic with the item identifier"GoogleWebsite" and a subject locator
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 30
Details – Type-Instance
CTM provides the keyword "isa" to establishtype-instance relationships between topicsExample:john isa person .
Creates a type-instance associationbetween "john" and "person" where "john" plays the "instance" role and "person" playsthe "type" role
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 31
Details – Supertype-Subtype
The keyword "ako" creates a supertype-subtype association between topicsExample:album ako work .
Creates a supertype-subtype associationbetween "album" and "work" where "album" plays the "subtype" role and "work" plays the"supertype" role
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 32
Details – Reification
To reify a statment, use a tilde ("~") followedby a topic referenceExample:works-for(company: BigCo,
employee: Barney) ~ barneys-employment
barneys-employmentdescr: "Barneys employment during 1980".
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 33
Details – Embedded Topics
Everywhere where a topic reference isexcpected (i.e. as type) an embedded topiccan be usedEmbedded topics get an automaticallygenerated item identifierIt's possible to define additional (stableidentities)Handy for reification or where an explicitreference to a topic is not needed
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 34
Details – Embedded Topics
Example:
works-for(company: BigCo, employee: Barney) ~ [descr: "Barneys…"]
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 35
Details – Directives – Prefix
The "%prefix" directive can be used to assignan IRI to an identifierThe identifier can be is used as prefix within a QNameExample:
%prefix wp http://en.wikipedia.org/ ;wp:John_Lennon – "John Lennon".
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 36
Details – Directives – Prefix
QNames can also be used for subject locators:
%prefix wp http://en.wikipedia.org/ ;
= wp:John_Lennondecription: "Wikipedia page aboutJohn Lennon".
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 37
Details – Directives – Prefix
QNames can be used everywhere where a reference to a topic should be made (i.e. as association type, occurrence type, name typeetc.)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 38
Details – Directives –Mergemap
The %mergemap directive has the samesemantics as the mergemap element in XTM 2.0 (merge the current topic map with thereferenced one).In CTM it will be possible to specify the syntaxof the referenced file. I.e. it will be possible to merge-in a topic map which is encoded in XTM 2.0, or in LTM etc.This directive will change, current spec isoutdated
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 39
Details – Directives – Include
%include:The include directive imports the referencedCTM file into the current one. Including a filemakes the templates of the other file availablein the current one and topics with an equallocal identifier (like "john") are merged (thiswould not be the case if the %mergemapdirective is used)Prefixes are not imported!
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 40
Details – Directives – Include
Example:File A:john – "John Lennon".
File B: john – surname: "Lennon".If file A includes file B the result would be:john – "John Lennon"; - surname: "Lennon".
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 41
Details – Templates
Templates are used to shorten the CTM codeEspecially useful for facts which occur often in a specific domainExample:def plays-for($player, $group, $instrument)
plays(player: $player, group: $group,instrument: $instrument)
endMcCartney plays-for(The-Beatles, piano).
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 42
Details – Templates
If templates are invoked within a topic block, the first argument of the template is the topic!Again:
McCartney plays-for(The-Beatles, piano).is translated to:
plays-for(McCartney, The-Beatles, piano)If a templates are invoked outside a topic block, all parameters have to be specified:
plays-for(McCartney, The-Beatles, piano)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 43
Details – Templates
Since the topic is always used as firstargument, it is not possible to invoke a template with no arguments within a topicblockWithin a template literals and topic references canbe replaced with variables
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 44
Details – Templates
def born($person, $date, $place) $person isa person; birthday: $date . born-in(person : $person, birthplace : $place).
end
mccartney born(1942-06-12, Liverpool).
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 45
Details – Templates
Result:
mccartney isa person; birthday: 1942-06-12 .
born-in(person: mccartney, birthplace: Liverpool)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 46
Details – TemplatesDon't try to reify something within a template unlessthe reifier is variable otherwise the CTM processorreports violations of Topic Maps constraintsExample (don't do that):def works-for($person, $company)
works-for(company: $company,person: $person) ~ employment
end
Everytime the "works-for" template is invoked, theprocessor tries to reify the newly created associationwhich leads to an error because a topic can reify onlyone statement
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 47
Details – Templates
This works:def works-for($person, $company, $reifier)
works-for(company: $company,person: $person) ~ $reifier
end
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 48
Details – Templatesdef is-beatle($beatle) # "Decorates 'is-member-of'
is-member-of($beatle, The-Beatles) end def is-member-of($member, $group)
member-of(member: $member, group: $group) end is-member-of(sting, The-Police)is-beatle(john)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 49
Details – Wildcards
?foo creates an automatically generated itemidentifier. Everytime the parser sees ?fooagain, the same topic will be reused? creates a topic with an automaticallygenerated item identifier, it is not possible to create a reference to the topic (c.f embeddedtopics)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 50
Details – WildcardsWildcards in templates create a new itemidentifier for every invokation
def tpl()?foo – "Foo".assoc(role-type: ?foo)
endtpl();tpl(); # two topics created from ?foo
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 51
Create your own topic mapThink of a music collection, where each album is specified by a PSI which starts with "http://psi.example.org/album/" (i.e. http://psi.example.org/album/WhiteAlbum )Create at least two album topics incl. a name and an occurrence(i.e. a description)Both albums are instances of http://psi.music.com/album"Create a "created" association between a musician or group and the first album (the musician plays the "creator" role, the album the"work" role)Create a template "created-by" for the "created" associationThe second album should use the "created-by" template to establish an association between the album and the musicianUse QNames where reasonable
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 52
Possible solution%prefix album http://psi.example.org/album/ ;
album:WhiteAlbum – "White Album";descr: "The White Album was one of the last album releases of The Beatles".
The-Beatles – "The Beatles".
created(creator: The-Beatles, work: album:WhiteAlbum)
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 53
Possible solutiondef created-by($work, $creator)
created(creator: $creator,work: $work)
end
album:SgtPepper – "Sgt. Pepper";created-by(The-Beatles);descr: "One of the first concept albums".
© 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 54
Discussion
Questions?
Answers! ☺