Ctm 1.0 Tutorial

2,190 views

Published on

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).

Published in: Technology, Travel
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,190
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
30
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Ctm 1.0 Tutorial

  1. 1. CTM 1.0 Compact Topic Maps Syntax Tutorial Lars Heuer <heuer@semagia.com> TMRA 2008, Leipzig · 15.10.2008
  2. 2. Table of Contents Introduction Overview Details Create your own topic map Questions / Answers © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 2
  3. 3. Introduction CTM is a textual Topic Maps syntax (like LTM and AsTMa=) Is meant to be human-friendly Supports TMDM Standard 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 3
  4. 4. Introduction CTM is utilised by TMCL to define constraints CTM will be used by TMQL for INSERT operations UPDATE operations DELETE operations Shares some similarities with TMQL (syntax wise) Current draft (slightly outdated) http://www.isotopicmaps.org/ctm/ © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 4
  5. 5. Introduction CTM is nearly finished (feature-wise, syntax- wise) Next draft will appear within the next two months Currently no stable, upto-date CTM parser is available (should change soon) © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 5
  6. 6. Overview – ToC Topcis Names Occurrences Literals Associations Comments Summary © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 6
  7. 7. Overview – Topics Topics are introduced with an identity and end with a dot (quot;.quot;) (often labeled as quot;topic blockquot;) 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 7
  8. 8. Overview – Topics An IRI is interpreted as subject identifier unless it is prefixed by an equal sign (or it is used as occurrence / variant value) Rootless IRIs (IRIs without quot;://quot;) are not detected, they have to be embedded into quot;<quot; quot;>quot;: Topic with a subject identifier: <mailto:heuer@semagia.com> . © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 8
  9. 9. Overview – Topics Topic statements like names and occurrences are delimited by a semicolon (quot;;quot;) 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 9
  10. 10. Overview – Names Names are introduced by a hyphen, followed by an optional name type and the value Example: john-lennon - quot;John Lennonquot;; - surname: quot;Lennonquot;. © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 10
  11. 11. Overview – Names Names are introduced by a hyphen, followed by an optional name type and the value Example: Name value john-lennon - quot;John Lennonquot;; - surname: quot;Lennonquot;. Name type © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 11
  12. 12. Overview – Names If the name type is not specified, the name uses automatically the default topic name type The name scope is introduced by an @ sign followed by comma delimited themes Example: The-Beatles - quot;The Beatlesquot;; - quot;Fab Fourquot; @nickname; - quot;Pilzköpfequot; @nickname, de . © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 12
  13. 13. Overview – Occurrences Occurrences start with the type, a colon followed by the value Example: The-Beatles website: http://www.beatles.com.uk . © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 13
  14. 14. Overview – Occurrence Scope The scope is introduced by an @ sign followed by the themes Example: The-Beatles website: http://www.beatles.com.uk ; website: http://beatles.de/ @de . © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 14
  15. 15. Overview – Literals CTM provides some built-in datatypes: String Date DateTime Integer Decimal IRI These datatypes can be used as occurrence and variant value © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 15
  16. 16. Overview – Literals – String Example: TopicMaps - quot;Topic Mapsquot;; description: quot;A technology …quot;. The datatype of the occurrence quot;descriptionquot; is set to xsd:string © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 16
  17. 17. Overview – Literals – Dates Examples: McCartney birthday: 1942-02-18. Blog-Entry created: 2008-10-12T17:30:22 . Datatype of quot;birthdayquot; is set to xsd:date, dataype of quot;createdquot; is xsd:dateTime © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 17
  18. 18. Overview – Literals – Numbers Examples: McCartney age: 66 . CTM version: 1.0 . Datatype of quot;agequot; is set to xsd:integer, dataype of quot;versionquot; is xsd:decimal © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 18
  19. 19. Overview – Literals Non-built-in datatypes can be expressed using the string value with an explicit datatype: quot;valuequot;^^datatype The quot;datatypequot; is specified by an IRI or a QName Examples: quot;09-19quot;^^xsd:gMonthDay quot;truequot;^^http://www.w3.org/2001/XMLSchema# boolean © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 19
  20. 20. Overview – Associations member-of(group: TheBeatles, member: john-lennon) © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 20
  21. 21. Overview – Associations Association type member-of(group: TheBeatles, member: john-lennon) Role types © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 21
  22. 22. Overview – Associations Association type Role players member-of(group: TheBeatles, member: john-lennon) Role types © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 22
  23. 23. Overview – Associations The (optional) scope is added to an association by the @ sign followed by the themes Example: member-of(group: blind-faith, member: eric) @year-1969 © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 23
  24. 24. Overview – Comments Single line comments start with a hash (quot;#quot;) and reach until the end of a line Multiline comments start with #( and end with )# Examples: # I am a single line comment #( line 1 line 2 )# © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 24
  25. 25. Overview – Summary Topics are introduced by an identity and end with a dot (quot;.quot;). The quot;topic blockquot; Topic statements must be delimited by a semicolon (quot;;quot;) unless it is the last statement Names are introduced with a hyphen (quot;-quot;), they have an optional explicit type and a value (string) Occurrences are introduced by the type followed by a literal © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 25
  26. 26. Overview – Summary CTM has built-in literals but the user can specify any datatype using the quot;valuequot;^^datatype notation Notation 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 26
  27. 27. Details – ToC Assigning additional identities to topics Creating type-instance / supertype-subtype relationships Reification Embedded Topics Directives Templates © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 27
  28. 28. Details - Topics Topics are not limited to one identity, any number of identities can be specified Example: McCartney http://en.wikipedia.org/Paul_McCartney ; http://de.wikipedia.org/Paul_McCartney . Topic with the item identifier quot;McCartneyquot; and two subject identifiers © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 28
  29. 29. Details - Topics Example: GoogleWebsite = http://www.google.com/ . Topic with the item identifier quot;GoogleWebsitequot; and a subject locator © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 29
  30. 30. Details – Type-Instance CTM provides the keyword quot;isaquot; to establish type-instance relationships between topics Example: john isa person . Creates a type-instance association between quot;johnquot; and quot;personquot; where quot;johnquot; plays the quot;instancequot; role and quot;personquot; plays the quot;typequot; role © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 30
  31. 31. Details – Supertype-Subtype The keyword quot;akoquot; creates a supertype- subtype association between topics Example: album ako work . Creates a supertype-subtype association between quot;albumquot; and quot;workquot; where quot;albumquot; plays the quot;subtypequot; role and quot;workquot; plays the quot;supertypequot; role © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 31
  32. 32. Details – Reification To reify a statment, use a tilde (quot;~quot;) followed by a topic reference Example: works-for(company: BigCo, employee: Barney) ~ barneys-employment barneys-employment descr: quot;Barneys employment during 1980quot;. © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 32
  33. 33. Details – Embedded Topics Everywhere where a topic reference is excpected (i.e. as type) an embedded topic can be used Embedded topics get an automatically generated item identifier It's possible to define additional (stable identities) Handy for reification or where an explicit reference to a topic is not needed © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 33
  34. 34. Details – Embedded Topics Example: works-for(company: BigCo, employee: Barney) ~ [descr: quot;Barneys…quot;] © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 34
  35. 35. Details – Directives – Prefix The quot;%prefixquot; directive can be used to assign an IRI to an identifier The identifier can be is used as prefix within a QName Example: %prefix wp http://en.wikipedia.org/ ; wp:John_Lennon – quot;John Lennonquot;. © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 35
  36. 36. Details – Directives – Prefix QNames can also be used for subject locators: %prefix wp http://en.wikipedia.org/ ; = wp:John_Lennon decription: quot;Wikipedia page about John Lennonquot;. © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 36
  37. 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 type etc.) © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 37
  38. 38. Details – Directives – Mergemap The %mergemap directive has the same semantics as the mergemap element in XTM 2.0 (merge the current topic map with the referenced one). In CTM it will be possible to specify the syntax of 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 is outdated © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 38
  39. 39. Details – Directives – Include %include: The include directive imports the referenced CTM file into the current one. Including a file makes the templates of the other file available in the current one and topics with an equal local identifier (like quot;johnquot;) are merged (this would not be the case if the %mergemap directive is used) Prefixes are not imported! © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 39
  40. 40. Details – Directives – Include Example: File A: john – quot;John Lennonquot;. File B: john – surname: quot;Lennonquot;. If file A includes file B the result would be: john – quot;John Lennonquot;; - surname: quot;Lennonquot;. © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 40
  41. 41. Details – Templates Templates are used to shorten the CTM code Especially useful for facts which occur often in a specific domain Example: def plays-for($player, $group, $instrument) plays(player: $player, group: $group, instrument: $instrument) end McCartney plays-for(The-Beatles, piano). © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 41
  42. 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 42
  43. 43. Details – Templates Since the topic is always used as first argument, it is not possible to invoke a template with no arguments within a topic block Within a template literals and topic references can be replaced with variables © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 43
  44. 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 44
  45. 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 45
  46. 46. Details – Templates Don't try to reify something within a template unless the reifier is variable otherwise the CTM processor reports violations of Topic Maps constraints Example (don't do that): def works-for($person, $company) works-for(company: $company, person: $person) ~ employment end Everytime the quot;works-forquot; template is invoked, the processor tries to reify the newly created association which leads to an error because a topic can reify only one statement © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 46
  47. 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 47
  48. 48. Details – Templates def is-beatle($beatle) # quot;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 48
  49. 49. Details – Wildcards ?foo creates an automatically generated item identifier. Everytime the parser sees ?foo again, the same topic will be reused ? creates a topic with an automatically generated item identifier, it is not possible to create a reference to the topic (c.f embedded topics) © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 49
  50. 50. Details – Wildcards Wildcards in templates create a new item identifier for every invokation def tpl() ?foo – quot;Fooquot;. assoc(role-type: ?foo) end tpl(); tpl(); # two topics created from ?foo © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 50
  51. 51. Create your own topic map Think of a music collection, where each album is specified by a PSI which starts with quot;http://psi.example.org/album/quot; (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/albumquot; Create a quot;createdquot; association between a musician or group and the first album (the musician plays the quot;creatorquot; role, the album the quot;workquot; role) Create a template quot;created-byquot; for the quot;createdquot; association The second album should use the quot;created-byquot; template to establish an association between the album and the musician Use QNames where reasonable © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 51
  52. 52. Possible solution %prefix album http://psi.example.org/album/ ; album:WhiteAlbum – quot;White Albumquot;; descr: quot;The White Album was one of the last album releases of The Beatlesquot;. The-Beatles – quot;The Beatlesquot;. created(creator: The-Beatles, work: album:WhiteAlbum) © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 52
  53. 53. Possible solution def created-by($work, $creator) created(creator: $creator, work: $work) end album:SgtPepper – quot;Sgt. Pepperquot;; created-by(The-Beatles); descr: quot;One of the first concept albumsquot;. © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 53
  54. 54. Discussion Questions? Answers! ☺ © 2008 Lars Heuer · http://www.semagia.com TMRA 2008, Leipzig · 15.10.2008 54

×