SYNOPSIS

   # somehow acquire a map (see TM and its subclasses)
   my $tm = ....

   # put a TMDM layer on top of it
   use TM::DM;
   my $tmdm = new TM::DM (map => $tm);

   # get the TMDM topic map item
   my $topicmap = $tmdm->topicmap;

   # ask for all topics
   my @topics = $topicmap->topics;
   # for all associations
   my @assocs = $topicmap->associations;

   # get a particular topic
   my $adam = $topicmap->topic ('adam');

   # get some of its properties
   $adam->id;
   $adam->subjectLocators;
   $adam->subjectIdentifiers;
   $adam->parent;
   my @ns = $adam->names;
   my @os = $adam->occurrences;

   # similar for assocs
   my @as = $topicmap->associations (iplayer => 'adam');
   $as[0]->type;
   $as[0]->parent;
   my @rs = $as[0]->roles;

ABSTRACT

This package provides a TMDM-ish (read-only) view on an existing topic map.

DESCRIPTION

\s-1TMDM\s0, the Topic Maps Data Model

http://www.isotopicmaps.org/sam/sam-model/

is the \s-1ISO\s0 standard for the high-level model for Topic Maps.

\s-1TMDM\s0 Concepts

\s-1TMDM\s0's main concepts are the

topic map item

containing any number of topic and association items

topic item

containing any number of names, occurrence items, subject locators and subject identifiers

association item

containing a type, a scope and any number of role items

name item

containing a string, a type and a scope

occurrence item

containing a data value (together with its data type), a type and a scope

role item

containing a type and a player

All items have an item id and all (except the map) have a parent which links back to where the item belongs.

This package implements for each of the above a class and access methods to retrieve actual structure and values from an existing map. Nota bene, there are some deviations from \s-1TMDM:\s0

  • only \s-1ONE\s0 identifier per item is supported

  • at most \s-1ONE\s0 subject locator per topic is supported

  • no variants are supported (might be added at some stage, poke me)

  • a scope consists only of a single topic

  • role items do not have an identity, so they also cannot be reified

Modus Operandi

Before you can use the \s-1TMDM\s0 layer, you need \s-1TM\s0 information in the form of a \s-1TM\s0 object. Any subclass should do, materialized and non-materialized maps should both be fine. Only with such a map you can instantiate a \s-1TMDM\s0 layer:

use TM::Materialized::AsTMa; my $tm = new TM::Materialized::AsTMa (file => 'test.atm');

use TM::DM; my $tmdm = new TM::DM (map => $tm);

Probably the first thing you need to do is to get a handle on the whole topic map:

my $topicmap = $tmdm->topicmap;

That is delivered as an instance of TM::DM::TopicMap as described below. From there you start to extract topics and associations and that way you then further drill down.

Implementation Notes

This implementation only supports reading map information, not changing it or modifying the structure of the map. Not that it is impossible to do, but many applications get their map content from elsewhere and a read/write interface is an overkill in these cases.

All objects generated here are ephemeral, i.e. they are only instantiated because you wanted the map information embedded into them. This implies that if you ask for one and the same topic twice, you are getting two copies of the topic information. The following will not work as expected:

my $t0 = $topicmap->topic ('adam'); my $t1 = $topicmap->topic ('adam');

warn "have the same topic!" if $t0 == $t1;

This will work:

warn "have the same topic!" if $t0->id eq $t1->id;

INTERFACES

\s-1TM::DM\s0

The \s-1TM::DM\s0 class itself does not offer much functionality itself. It only keeps the connection to the background map.

Constructor

The constructor expects exactly one parameter, namely the background map.

$tmdm = new \s-1TM::DM\s0 (map => $tm)

Methods

topicmap

$topicmap = $tmdm->topicmap This method generates a Topic Map item. See TM::DM::TopicMap .

TM::DM::TopicMap

This class provides access to all \s-1TMDM\s0 properties:

id

This returns the item identifier.

topics

@topics = $topicmap->topics (@list-of-ids) @topics = $topicmap->topics @topics = $topicmap->topics ($selection-spec) This method expects a list containing topic valid identifiers and returns for each of the topics a \*(C`TM::DM::Topic\*(C' reference. If any of the input identifiers do not denote a valid topic in the map, undef will be returned in its place. If the parameter list is empty, all topics will be returned. Have fun, I mean, use with care. Examples: # round tripping topic ids print map { $_->id } $topicmap->topics ('abel', 'cain' );

print "he again" if $topicmap->topics ('god'); If a selection is specified then the same language as in \s-1TM\s0 (method \*(C`toplets\*(C') can be used.

associations

@as = $topicmap->associations @as = $topicmap->associations (%search_spec); This method retrieves the list of \s-1ALL\s0 associations when it is invoked without a search specification. See \s-1TM\s0 for that.

reifier

This returns the topic item which reifies the association. \*(C`undef\*(C' is returned if there is none.

topic

This returns a topic item with that id. This method will die if the id is invalid. Note that always new copies are made.

TM::DM::Topic

subjectLocators

Returns the (only) subject locator (\s-1URI\s0 string) in the topic item or \*(C`undef\*(C' if there is none.

subjectIdentifiers

Returns a list of \s-1URI\s0 strings. Might be empty.

id

Returns the item id.

parent

Returns a TM::DM::TopicMap item in which this topic is embedded.

names

@names = $topic->names Returns a list of \s-1TMDM\s0 name items.

occurrences

@occurrences = $topic->occurrences Returns a list of \s-1TMDM\s0 occurrences items.

roles

@roles = $topic->roles Returns a list of TM::DM::Role items where this topic plays any role.

TM::DM::Association

id

Returns the item id.

type

Returns a TM::DM::Topic item which is the type of the association. This is always defined.

scope

Returns the scope of the association in the form of a single TM::DM::Topic item. This is always defined as for the unconstrained scope the topic \*(C`us\*(C' is used (see \s-1TM::PSI\s0).

roles

@roles = $assoc->roles Returns a list of roles of the association. Each role is a TM::DM::Role item.

parent

Returns a TM::DM::TopicMap item for the embedding map.

reifier

Returns a TM::DM::Topic item if this association is reified. \*(C`undef\*(C' otherwise.

TM::DM::Occurrence

id

Returns the item id.

value

Returns the value (together with the data type) in the form of a TM::Literal object.

type

Returns a TM::DM::Topic item which is the type of the occurrence. This is always defined.

scope

Returns the scope of the occurrence in the form of a single TM::DM::Topic item. This is always defined.

reifier

Returns a TM::DM::Topic item if this occurrence is reified. \*(C`undef\*(C' otherwise.

parent

Returns the TM::DM::Topic item of the topic where this occurrence is part of.

TM::DM::Name

id

Returns the item id.

value

Returns the string value of the name.

type

Returns a TM::DM::Topic item which is the type of the name. This is always defined.

scope

Returns the scope of the name in the form of a single TM::DM::Topic item. This is always defined.

reifier

Returns a TM::DM::Topic item if this name is reified. \*(C`undef\*(C' otherwise.

parent

Returns the TM::DM::Topic item of the topic where this name is part of.

TM::DM::Role

player

Returns a TM::DM::Topic item for the topic which is the player in this role.

type

Returns a TM::DM::Topic item for the topic which is the type of this role.

parent

Returns a TM::DM::Association item of the association where this role is in.

RELATED TO TM::DM…

\s-1TM\s0, TM::Easy

COPYRIGHT AND LICENSE

Copyright 200[68] by Robert Barta, <[email protected]>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.