# 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;
This package provides a TMDM-ish (read-only) view on an existing topic map.
TMDM, the Topic Maps Data Model
http://www.isotopicmaps.org/sam/sam-model/
is the ISO standard for the high-level model for Topic Maps.
TMDM's main concepts are the
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 TMDM:
Before you can use the TMDM layer, you need TM information in the form of a TM object. Any subclass should do, materialized and non-materialized maps should both be fine. Only with such a map you can instantiate a TMDM 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.
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;
The TM::DM 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 TM::DM (map => $tm)
Methods
This method generates a Topic Map item. See TM::DM::TopicMap .
This class provides access to all TMDM properties:
@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 "TM::DM::Topic" 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 TM (method "toplets") can be used.
@as = $topicmap->associations (%search_spec);
This method retrieves the list of ALL associations when it is invoked without a search specification. See TM for that.
Returns a list of TMDM name items.
Returns a list of TMDM occurrences items.
Returns a list of TM::DM::Role items where this topic plays any role.
Returns a list of roles of the association. Each role is a TM::DM::Role item.
TM, TM::Easy
Copyright 200[68] by Robert Barta, <drrho@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.