SYNOPSIS

    my $tm = new TM (baseuri => 'tm://whatever/');   # empty map

    # add a toplet (= minimal topic, only identification, no characteristics)
    # by specifying an internal ID
    $tm->internalize ('aaa');                        # only internal identifier
    $tm->internalize ('bbb' =>   'http://bbb/');     # with a subject address
    $tm->internalize ('ccc' => \ 'http://ccc/');     # with a subject indicator

    # without specifying an internal ID (will be auto-generated)
    $tm->internalize (undef =>   'http://ccc/');     # with a subject address
    $tm->internalize (undef => \ 'http://ccc/');     # with a subject indicator

    # get rid of toplet(s)
    $tm->externalize ('tm://whatever/aaa', ...);

    # find full URI of a toplet
    my $tid  = $tm->tids ('person');                     # returns tm://whatever/person
    my @tids = $tm->tids ('person', ...)                 # for a whole list

    my $tid  = $tm->tids (  'http://bbb/');              # with subject address
    my $tid  = $tm->tids (\ 'http://ccc/');              # with subject indicator

    my @ts   = $tm->toplets;                             # get all toplets
    my @ts   = $tm->toplets (\ '+all -infrastructure');  # only those you added

    my @as   = $tm->asserts (\ '+all -infrastructure');  # only those you added

    my @as   = $tm->retrieve;                            # all assertions
    my $a    = $tm->retrieve ('23ac4637....345');        # returns only that one assertion
    my @as   = $tm->retrieve ('23ac4637....345', '...'); # returns all these assertions

    # create standalone assertion
    my $a = Assertion->new (type    => 'is-subclass-of',
                            roles   => [ 'subclass', 'superclass' ],
                            players => [ 'rumsti', 'ramsti' ]);
    $tm->assert ($a);                                    # add that to map

    # create a name
    my $n = Assertion->new (kind    => TM->NAME,
                            type    => 'name',
                            scope   => 'us',
                            roles   => [ 'thing', 'value' ],
                            players => [ 'rumsti', new TM::Literal ('AAA') ])
    # create an occurrence
    my $o = Assertion->new (kind    => TM->OCC,
                            type    => 'occurrence',
                            scope   => 'us',
                            roles   => [ 'thing', 'value' ],
                            players => [ 'rumsti', new TM::Literal ('http://whatever/') ])

    $tm->assert ($n, $o);                                # throw them in

    $tm->retract ($a->[TM->LID], ...);                   # get rid of assertion(s)

    my @as = $tm->retrieve ('id..of...assertion');       # extract particular assertions

    # find particular assertions
    # generic search patterns
    my @as = $tm->match_forall (scope   => 'tm://whatever/sss');

    my @bs = $tm->match_forall (type    => 'tm://whatever/ttt',
                                roles   => [ 'tm://whatever/aaa', 'tm://whatever/bbb' ]);

    # specialized search patterns (see TM::Axes)
    my @cs = $tm->match_forall (type    => 'is-subclass-of',
                                arole   => 'superclass',
                                aplayer => 'tm://whatever/rumsti',
                                brole   => 'subclass');

    my @ds = $tm->match_forall (type    => 'isa',
                                class   => 'tm://whatever/person');

    # perform merging, cleanup, etc.
    $tm->consolidate;

    # check internal consistency of the data structure
    die "panic" if $tm->insane;

    # taxonomy stuff
    warn "what a subtle joke" if $tm->is_a ($tm->tids ('gw_bush', 'moron'));

    die "what a subtle joke"
        unless $tm->is_subclass ($tm->tids ('politician', 'moron'));

    # returns Mr. Spock if Volcans are subclassing Aliens
    warn "my best friends: ". Dumper [ $tm->instancesT ($tm->tids ('alien')) ];

ABSTRACT

This class provides read/write access to a data structure according to the Topic Maps paradigm. As it stands, this class implements directly so-called materialized maps, i.e. those maps which completely reside in memory. Implementations for non-materialized maps can be derived from it.

DESCRIPTION

This class implements directly so-called materialized topic maps, i.e. those maps which completely reside in memory. Non-materialized and non-materializable maps can be implemented by deriving from this class by overloading one or all of the sub-interfaces. If this is done cleverly, then any application, even a \s-1TMQL\s0 query processor can operate on non-materialized (virtual) maps in the same way as on materialized ones.

Data Structures

The Topic Maps paradigm knows two abstractions

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

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

\s-1TMRM\s0, Topic Maps Reference Model

<http://www.isotopicmaps.org/tmrm/>

For historical reasons, this package adopts an abstraction which is in between these two. Accordingly, there are only following types of data structures

Toplets:

These are like \s-1TMDM\s0 topics, but only contain addressing information (subject identifiers and subject addresses) along with an internal identifier.

Assertions:

These are like \s-1TMDM\s0 associations, but are generalized to host also occurrences and names. Also associations using predefined association types, such as \*(C`isa\*(C' (instance-class) and \*(C`iko\*(C' (subtype-supertype) are represented as assertions.

Variants:

No idea what they are good for. They can be probably safely ignored.

The data manipulation interface is very low-level and directly exposes internal data structures. As long as you do not mess with the information you get and you follow the \s-1API\s0 rules, this can provide a convenient, fast, albeit not overly comfortable interface. If you prefer more a TMDM-like style of accessing a map then have a look at \s-1TM::DM\s0.

Identifiers

Of course, \s-1TM\s0 supports the subject locator and the subject indicator mechanism as mandated by the Topic Maps standards.

Additionally, this package also uses internal identifiers to address everything which looks and smells like a topic, also associations, names and occurrences. For topics the application (or author) of the topic map will most likely provide these internal identifiers. For the others the identifiers are generated.

Since v1.31 this package distinguishes between 3 kinds of internal identifiers:

canonicalized toplet identifiers

These identifiers are always interpreted local to a map, in that the \*(C`baseuri\*(C' of the map is used as prefix. So, a local identifier chinese-working-conditions will become tm://nirvana/chinese-working-conditions if the base \s-1URI\s0 of the map were tm://nirvana/ So if you want to use identifiers such as these, then you should either use the absolut version (including the base \s-1URI\s0) or use the method \*(C`tids\*(C' to find the absolute version.

sacrosanct toplet identifiers

All toplets from the infrastructure are declared sacrosanct, i.e. untouchable. Examples are \*(C`isa\*(C', \*(C`class\*(C' or \*(C`us\*(C' (universal scope). These identifiers are always the same in all maps this package system manages. That implies that if you use such an identifier, then you cannot attach a local meaning to it. And it implies that at merging time, toplets with these identifiers will merge. Even if there were no subject indicators or addresses involved. It is probably a good idea to leave such toplets alone as the software is relying on the stability of the sacrosanct identifiers.

assertion identifiers

Each assertion also has an (internal) identifier. It is a function from the content, so it is characteristic for the assertion.

Consistency

An application using a map may expect that a map is consolidated, i.e. that the following consistency conditions are met:

A1 (fixed on)

Every identifier appearing in some assertion as type, scope, role or player is also registered as toplet.

Indicator_based_Merging (default: on)

Two (or more) toplets sharing the same subject identifier are treated as one toplet.

Subject_based_Merging (default: on)

Two (or more) toplets sharing the same subject locator are treated as one toplet.

TNC_based_Merging (default: off)

Two (or more) toplet sharing the same name in the same scope are treated as one toplet.

While A1 is related with the internal consistency of the data structure (see \*(C`insane\*(C'), the others are a choice the application can make (see \*(C`consistency\*(C').

Consistency is not automatically provided when a map is modified by the application. It is the applications responsibility to trigger the process to consolidate the map. As that may be potentially expensive, the control remains at the application.

When an \s-1IO\s0 driver is consuming a map from a resource, say, loading from an \s-1XTM\s0 file, then that driver will ensure that the map is consolidated according to the current settings before it hands it to the application. The application is then in full control of the map as it can change, add and delete toplets and assertions. The map can become unconsolidated in this process. The method \*(C`consolidate\*(C' reinstates consistency again.

You can change these defaults by (a) providing an additional option to the constructor

new TM (...., consistency => [ TM->Subject_based_Merging, TM->Indicator_based_Merging ]);

or (b) by later using the accessor \*(C`consistency\*(C' (see below).

MAP INTERFACE

Constructor

$tm = new \s-1TM\s0 (...)

The constructor will create an empty map, or, to be more exact, it will fill the map with the taxonomy from \s-1TM::PSI\s0 which covers basic Topic Maps concepts such as topic or associations.

The constructor understands a number of key/value pair parameters: Every toplet in the map has an unique local identifier (e.g. \*(C`shoesize\*(C'). The \*(C`baseuri\*(C' parameter controls how an absolute \s-1URI\s0 is built from this identifier. This controls the consistency settings. They can be changed later with the \*(C`consistency\*(C' method.

Methods

baseuri

$bu = $tm->baseuri This methods retrieves the base \s-1URI\s0 component of the map. This is a read-only method. The base \s-1URI\s0 is always defined.

consistency

@merging_constraints = $tm->consistency $tm->consistency (@list_of_consistency_constants) This method provides read/write access to the consistency settings. If no parameters are provided, then the current list of consistency settings is returned. If parameters are provided, that list must consist of the constants defined under \*(L"Consistency\*(R". \s-1NOTE\s0: Changing the consistency does \s-1NOT\s0 automatically trigger \*(C`consolidate\*(C'.

last_mod

Returns the Time::HiRes date of last time the map has been modified (content-wise).

consolidate

$tm->consolidate $tm->consolidate (@list_of_consistency_constants) This method consolidates a map by performing the following actions:

  • perform merging based on subject address (see \s-1TMDM\s0 section 5.3.2)

  • perform merging based on subject indicators (see \s-1TMDM\s0 section 5.3.2)

  • remove all superfluous toplets (those which do not take part in any assertion) \s-1NOTE\s0: Not implemented yet!

This method will normally use the map's consistency settings. These settings can be overridden by adding consistency settings as parameters (see \*(L"Consistency\*(R"). In that case the map's settings are not modified, so use this carefully. \s-1NOTE\s0: In all cases the map will be modified. \s-1NOTE\s0: After merging some of the lids might not be reliably point to a topic.

clear

$tm->clear This method removes all toplets and assertions (except the infrastructure). Everything else remains.

add

$tm->add ($tm2, ...) This method accepts a list of \s-1TM\s0 objects and adds all content from these maps to the current object. \s-1NOTE\s0: There is \s-1NO\s0 merging done for user-supplied toplets. Use explicitly method \*(C`consolidate\*(C' for it. Merging is done for all sacrosanct toplets, i.e. those from the infrastructure. From v1.31 onwards this method tries to favour the internal identifiers (LIDs) of this map over LIDs of the added maps. This means, firstly, that internal identifiers of this map are not touched (or re-generated) in any way and that any shorthands (without a baseuri prefix) will remain valid when using \*(C`tids\*(C'. Secondly, LIDs in the added map will be attempted to blend into this map by changing simply their prefix. If that newly generated \s-1LID\s0 is already taken by something in this map, then the original \s-1LID\s0 will be used. That allows many added LIDs be used together with \*(C`tids\*(C' without (much) change in code. Of course, the only reliable way to reach a topic is a subject locator or an indicator. This is all about convenience. \s-1NOTE\s0: This procedure implies that some assertions are recomputed, so that also their \s-1LID\s0 will change!

diff

$diff = $new_tm->diff ($old_tm) $diff = TM::diff ($new_tm, $old_tm) $diff = TM::diff ($new_tm, $old_tm,

                     {consistency => \ @list_of_consistency_consts,
                      include_changes => 1})

\*(C`diff\*(C' compares two topic maps and returns their differences as a hash reference. While it works on any two maps, it is most useful after one map (the old map) is modified into a new map. If \*(C`diff\*(C' is used in OO-style, the current map is interpreted as the new map and the map in the arguments as the old one. By default, the toplet and assertion identifiers for any changes are returned; the option \*(C`include_changes\*(C' causes the return of the actual toplets and assertions themselves. This option makes \*(C`diff\*(C''s output more self-contained: enabled, one can fully (re)create the new map from the old one using the diff (or vice versa). The \*(C`consistency\*(C' option uses the same format as the \s-1TM\s0 constructor (see \*(L"Constructor\*(R") and describes how corresponding toplets in the two maps are to be identified. Toplets with the same internal ids are always considered equal. If subject based consistency is active, toplets with the same subject locator are considered equal (overriding the topic identities). If indicator based consistency is active, toplets with a matching subject indicator are considered equal (overriding the previous identities). \s-1NOTE\s0: This overriding of previous conditions for identity is necessary to keep the equality relationship unique and one-to-one. As an example, consider the following scenario: a toplet a in the old map is split into multiple new toplets a and b in the new map. If a had a locator or identifier that is moved to b (and if consistency options were active), then the identity detector will consider b to be equal to a, and not a in the new map to correspond to a in the old map. However, this will never lead to loss of information: a in the new map is flagged as completely new toplet. The differences between old and new map are returned underneath the keys plus, minus, identities and modified. If \*(C`include_changes\*(C' is on, the extra keys plus_midlets, minus_midlets and assertions are populated. The values of all these keys are hash references themselves.

plus, minus

The \*(C`plus\*(C' and \*(C`minus\*(C' hashes list new or removed toplets, respectively (with their identifiers as keys). For each toplet, the value of the hash is an array of associated assertion ids. The array is empty but defined if there are no associated assertions. For toplets the attached assertions are the usual ones (names, occurrences) and class-instance relationships (attached to the instance toplet). For associations, the assertions are attached to the type toplet.

identities

This hash consists of the non-trivial toplet identities that were found. If neither Subject- nor Indicator-based merging is active and if neither map object was created with a \s-1TM\s0 version before 1.31, then this hash is empty. Otherwise, the keys are toplet identifiers in the old map, with the corresponding topic identifier in the new map as value. This includes standalone topics as well as assertions and associations that were renamed due to changed player or role identities. For diff operations between maps where one map was created with a \s-1TM\s0 version before 1.31 (which can happen with frozen/thawed or MLDBM-based maps) extra identifying steps are performed (because the identifier format for assertions and infrastructure toplets and the stored format of toplets have changed). This situation is detected automatically, and if so the identities hash will also include all map elements that were identical but have different names due to the version incompatibility.

modified

The modified hash contains the changes for matched toplets. The key is the toplet identifier in the old map (which is potentially different from the one in the new map; see the note about identities above). The value is a hash with three keys: plus, minus and identities. The value for the \*(C`identities\*(C' key is defined if and only if the toplet associated with this toplet has changed (i.e. Subject Locator or Indicators have changed). The values for the \*(C`plus\*(C' and \*(C`minus\*(C' keys are arrays with the new or removed assertions that are attached to this toplet. These arrays are defined but empty where no applicable information is present.

plus_midlets, minus_midlets

These hashes hold the actual new or removed toplets if the option \*(C`include_changes\*(C' is active. Keys are the toplet ids, values are references to the actual toplet data structures.

assertions

This hash holds the actual assertions where the maps differ; it exists only if the option \*(C`include_changes\*(C' is active. Keys are the assertion identifiers, values the references to the actual assertion data structure. Note that assertion ids uniquely identify the assertion contents, therefore this hash can hold assertions from both new and old map.

melt (\s-1DEPRECATED\s0)

$tm->melt ($tm2) This - probably more auxiliary - function copies relevant aspect of a second map into the object.

insane

warn \*(L"topic map broken\*(R" if $tm->insane This method tests invariant conditions inside the \s-1TM\s0 structure of that map. Specifically,

  • each toplet has a \s-1LID\s0 which points to a toplet with the same address

It returns a string with a message or \*(C`undef\*(C' if everything seems fine. \s-1TODO:\s0 add test whether all variant entries have a proper \s-1LID\s0 (and toplet)

TOPLET INTERFACE

Toplets are light-weight versions of \s-1TMDM\s0 topics. They only carry addressing information and are represented by an array (struct) with the following fields: The internal identifier. Mostly it repeats the key in the toplet hash, but also aliased identifiers may exist. It contains the subject locator (address) \s-1URI\s0, if known. Otherwise \*(C`undef\*(C'. This is a reference to a list containing subject identifiers (indicators). The list can be empty, no duplicate removal is attempted at this stage.

You can create this structure manually, but mostly you would leave it to \*(C`internalize\*(C' to do the work.

Example:

# dogmatic way to produce it my $to = Toplet->new (lid => $baseuri . 'my-lovely-cat', saddr => 'http://subject-address.com/', sinds => []);

# also good and well my $to = [ $baseuri . 'my-lovely-cat', 'http://subject-address.com/', [] ];

# better my $to = $tm->internalize ('my-lovely-cat' => 'http://subject-address.com/');

To access the individual fields, you can either use the struct accessors \*(C`saddr\*(C' and \*(C`sinds\*(C', or use the constants defined above for indices into the array:

Example:

warn "indicators: ", join (", ", @{$to->sinds});

warn "locator: ", $to->[TM->ADDRESS];

Methods

internalize

$iid = $tm->internalize ($some_id) $iid = $tm->internalize ($some_id => $some_id) @iids = $tm->internalize ($some_id => $some_id, ...) This method does some trickery when a new toplet should be added to the map, depending on how parameters are passed into it. The general scheme is that pairs of identifiers are passed in. The first is usually the internal identifier, the second a subject identifier or the subject locator. The convention is that subject identifier URIs are passed in as string references, whereas subject locator URIs are passed in as strings. The following cases are covered:

If the \s-1ID\s0 is already an absolute \s-1URI\s0 and contains the \*(C`baseuri\*(C' of the map as prefix, then this \s-1URI\s0 is used as internal toplet identifier. If the \s-1ID\s0 is some other \s-1URI\s0, then a toplet with that \s-1URI\s0 as subject locator is searched in the map. If such a toplet already exists, then nothing special needs to happen. If no such toplet existed, a new \s-1URI\s0, based on the \*(C`baseuri\*(C' and a random number will be created for the internal identifier and the original \s-1URI\s0 is used as subject address. \s-1NOTE\s0: Using \*(C`URI => URI\*(C' implies that you use two different URIs as subject addresses. This will result in an error. Like above, only that the \s-1URI\s0 is directly interpreted as subject address. Like above, only that the \s-1URI\s0 is interpreted as another subject identifier. If the toplet already existed, then this subject identifier is simply added. Duplicates are suppressed (since v1.31). Like above, only that the internal identifier is auto-created if there is no toplet with the \s-1URI\s0 as subject address. Attention: If you call internalize like this $tm->internalize(undef => $whatever) then perl will (un)helpfully replace the required undef with the string \*(L"undef\*(R" and wreck the operation. Using either a variable to hold the undef or replacing the (syntactic sugar) arrow with a comma works around this issue. Attention: If you call internalize like this $tm->internalize(undef => $whatever) then perl will (un)helpfully replace the required undef with the string \*(L"undef\*(R" and wreck the operation. Using either a variable to hold the undef or replacing the (syntactic sugar) arrow with a comma works around this issue. Like above, only that the \s-1URI\s0 us used as subject identifier. A toplet with an auto-generated \s-1ID\s0 will be inserted.

In any case, the internal identifier(s) of all inserted (or existing) toplets are returned for convenience.

toplet (old name midlet)

$t = $tm->toplet ($mid) @ts = $tm->toplet ($mid, ....) This function returns a reference to a toplet structure. It can be used in scalar and list context.

toplets (old name midlets)

@mids = $tm->toplets @mids = $tm->toplets (@list_of_ids) @mids = $tm->toplets ($selection_spec) This function returns toplet structures from the map. \s-1NOTE\s0: This has changed from v 1.13. Before you got ids. If no parameter is provided, all toplets are returned. This includes really everything also infrastructure toplets. If an explicit list is provided as parameter, then all toplets with these identifiers are returned. If a search specification is used, it has to be passed in as string reference. That string contains the selection specification using the following simple language (curly brackets mean repetition, round bracket grouping, vertical bar alternatives): specification -> { ( '+' | '-' ) group } whereby group is one of the following:

refers to all toplets in the map. This includes those supplied by the application. The list also includes all infrastructure topics which the software maintains for completeness. refers to all toplets the infrastructure has provided. This implies that all - infrastructure is everything the user (application) has supplied.

Examples: # all toplets except those from TM::PSI $tm->toplets (\ '+all -infrastructure') \s-1NOTE\s0: No attempt is made to make this list unique. \s-1NOTE\s0: The specifications are not commutative, but are interpreted from left-to-right. So \*(C`all -infrastructure +infrastructure\*(C' is not the same as \*(C`all +infrastructure -infrastructure\*(C'. In the latter case the infrastructure toplets have been added twice, and are then deducted completely with \*(C`-infrastructure\*(C'.

tids (old name mids)

$mid = $tm->tids ($some_id) @mids = $tm->tids ($some_id, ...) This function tries to build absolute versions of the identifiers passed in. \*(C`undef\*(C' will be returned if no such can be constructed. Can be used in scalar and list context.

  • If the passed-in identifier is a relative \s-1URI\s0, so it is made absolute by prefixing it with the map \*(C`baseuri\*(C' and then we look for a toplet with that internal identifier.

  • If the passed-in identifier is an absolute \s-1URI\s0, where the \*(C`baseuri\*(C' is a prefix, then that \s-1URI\s0 will be used as internal identifier to look for a toplet.

  • If the passed-in identifier is an absolute \s-1URI\s0, where the \*(C`baseuri\*(C' is \s-1NOT\s0 a prefix, then that \s-1URI\s0 will be used as subject locator and such a toplet will be looked for.

  • If the passed-in identifier is a reference to an absolute \s-1URI\s0, then that \s-1URI\s0 will be used as subject identifier and such a toplet will be looked for.

externalize

$tm->externalize ($some_id, ...) This function simply deletes the toplet entry for the given internal identifier(s). The function returns all deleted toplet entries. \s-1NOTE\s0: Assertions in which this topic is involved will not be removed. Use \*(C`consolidate\*(C' to clean up all assertion where non-existing toplets still exist.

ASSERTIONS INTERFACE

One assertion is a record containing its own identifier, the scope, the type of the assocation, an field whether this is an association, an occurrence or a name and then all roles and all players, both in separate lists.

Assertions consist of the following components: Every assertion has an identifier. It is a unique identifier generated from a canonicalized form of the assertion itself. This component holds the scope of the assertion. For technical reasons (read: it is faster) we distinguish between full associations (\*(C`ASSOC\*(C'), names (\*(C`NAME\*(C') and occurrences (\*(C`OCC\*(C'). The toplet id of the type of this assertion. A list reference which holds a list of toplet ids for the roles. A list reference which holds a list of toplet IDs for the players. Either 1 or \*(C`undef\*(C' to signal whether this assertion has been (already) canonicalized (see \*(L"canonicalize\*(R"). If an assertion is canonicalized, then the players and roles lists are sorted (somehow), so that assertions can be easily compared.

Obviously the lists for roles and players always have the same length, so that every player corresponds to exactly one role. If one role is played by several players, the role appears multiple times.

As a special case, names and occurrences are mapped into assertions, by

  • setting the roles to \*(C`thing\*(C' and \*(C`value\*(C',

  • setting the players to the toplet id in question and using a TM::Literal as the player for \*(C`value\*(C',

  • using the type component to store the name/occurrence type,

  • using as kind either \*(C`NAME\*(C' or \*(C`OCC\*(C'

Example:

# general association $a = Assertion->new (type => 'is-subclass-of', roles => [ 'subclass', 'superclass' ], players => [ 'rumsti', 'ramsti' ])

warn $a->scope . " is the same as " . $a->[TM->SCOPE];

# create a name use TM::Literal; $n = Assertion->new (kind => TM->NAME, type => 'name', scope => 'us', roles => [ 'thing', 'value' ], players => [ 'rumsti', new TM::Literal ('AAA') ]);

# create an occurrence use TM::Literal; $n = Assertion->new (kind => TM->OCC, type => 'occurrence', scope => 'us', roles => [ 'thing', 'value' ], players => [ 'rumsti', new TM::Literal ('http://whatever/') ]);

Special Assertions

This package adopts the following conventions to store certain assertions: Associations of this type should have one role \*(C`subclass\*(C' and another \*(C`superclass\*(C'. The scope should always be \*(C`us\*(C'. Associations of this type should have one role \*(C`instance\*(C' and another \*(C`class\*(C'. The scope should always be \*(C`us\*(C'. Assertions for names should have the \*(C`KIND\*(C' component set to it and use the \*(C`TYPE\*(C' component to store the name type. The two roles to use are \*(C`value\*(C' for the value and \*(C`thing\*(C' for the toplet carrying the name. Assertions for occurrences should have the \*(C`KIND\*(C' component set to it and use the \*(C`TYPE\*(C' component to store the occurrence type. The two roles to use are \*(C`value\*(C' for the value and \*(C`thing\*(C' for the toplet carrying the name.

Methods

assert

@as = $tm->assert (@list-of-assertions) This method takes a list of assertions, canonicalizes them and then injects them into the map. If one of the newly added assertions already existed in the map, it will be ignored. In this process, all assertions will be completed (if fields are missing).

Then the assertion will be canonicalized (unless it already was). This implies that non-canonicalized assertions will be modified, in that the role/player lists change. Any assertion not having an \s-1LID\s0 will get one. The method returns a list of all asserted assertions. Example: my $a = Assertion->new (type => 'rumsti'); $tm->assert ($a); \s-1NOTE\s0: Maybe the type will default to association in the future.

retrieve

$assertion = $tm->retrieve ($some_assertion_id) @assertions = $tm->retrieve ($some_assertion_id, ...) This method takes a list of assertion IDs and returns the assertion(s) with the given (subject) \s-1ID\s0(s). If the assertion is not identifiable, \*(C`undef\*(C' will be returned in its place. Called in list context, it will return a list of assertion references.

asserts

@assertions = $tm->asserts ($selection_spec) If a search specification is used, it has to be passed in as string reference. That string contains the selection specification using the following simple language (curly brackets mean repetition, round bracket grouping, vertical bar alternatives): specification -> { ( '+' | '-' ) group } whereby group is one of the following:

refers to all assertions in the map. This includes those supplied by the application, but also all predefined associations, names and occurrences. refers to all assertions which are actually associations refers to all assertions which are actually name characteristics refers to all assertions which are actually occurrences refers to all assertions the infrastructure has provided. This implies that all - infrastructure is everything the user (application) has supplied.

Examples: # all toplets except those from TM::PSI $tm->asserts (\ '+all -infrastructure')

# like above, without assocs, so with names and occurrences $tm->asserts (\ '+all -associations') \s-1NOTE\s0: No attempt is made to make this list unique. \s-1NOTE\s0: The specifications are not commutative, but are interpreted from left-to-right. So \*(C`all -associations +associations\*(C' is not the same as \*(C`all +associations -associations\*(C'. \*(C`-infrastructure\*(C'.

is_asserted

$bool = $tm->is_asserted ($a) This method will return 1 if the passed-in assertion exists in the store. The assertion will be canonicalized before checking, but no defaults will be added if parts are missing.

retract

$tm->retract (@list_of_assertion_ids) This methods expects a list of assertion IDs and will remove the assertions from the map. If an \s-1ID\s0 is bogus, it will be ignored. \s-1NOTE\s0: Only these particular assertions will be deleted. Any toplets mentioned in these assertions will remain. Use \*(C`consolidate\*(C' to remove unnecessary toplets.

match, match_forall, match_exists

@assertions = $tm->match (\s-1TM-\s0>\s-1FORALL\s0 [ , search-spec ] ); @assertions = $tm->match (\s-1TM-\s0>\s-1EXISTS\s0 [ , search-spec ] ); @assertions = $tm->match_forall ( [ search-spec ] ); @assertions = $tm->match_exists ( [ search-spec ] ); These methods take a search specification and return matching assertions. The result list contains references to the assertions themselves, not to copies. You can change the assertions themselves on your own risk (read: better not do it). For \*(C`match\*(C', if the constant \*(C`FORALL\*(C' is used as first parameter, this method returns a list of all assertions in the store following the search specification. If the constant \*(C`EXISTS\*(C' is used, the method will return a non-empty value if at least one can be found. Calling the more specific \*(C`match_forall\*(C' is the same as calling \*(C`match\*(C' with \*(C`FORALL\*(C'. Similar for \*(C`match_exists\*(C'. \s-1NOTE\s0: \*(C`EXISTS\*(C' is not yet implemented. For search specifications there are two alternatives:

Generic Search

Here the search specification is a hash with the same fields as for the constructor of an assertion: Example: $tm->match (TM->FORALL, type => '...', scope => '..., roles => [ ...., ....], players => [ ...., ....]); Any combination of assertion components can be used, all are optional, with the only constraint that the number of roles must match that for the players. All involved IDs should be absolutized before matching. If you use \*(C`undef\*(C' for a role or a player, then this is interpreted as dont-care (wildcard).

Specialized Search

The implementation also understands a number of specialized search specifications. These are listed in TM::Axes.

\s-1NOTE\s0: Some combinations will be very fast, while others quite slow. If you experience problems, then it might be time to think about indexing (see TM::Index). \s-1NOTE\s0: For the assertion type and the role subclassing is honored.

Role Retrieval

is_player, is_x_player

$bool = is_player ($tm, $assertion, $player_id, [ $role_id ]) $bool = is_x_player ($tm, $assertion, $player_id, [ $role_id ]) This function returns 1 if the identifier specified by the \*(C`player_id\*(C' parameter plays any role in the assertion provided as \*(C`assertion\*(C' parameter. If the \*(C`role_id\*(C' is provided as third parameter then it must be exactly this role (or any subclass thereof) that is played. The 'x'-version is using equality instead of 'subclassing' ('x' for \*(L"exact\*(R").

get_players, get_x_players

@player_ids = get_players ($tm, $assertion, [ $role_id ]) @player_ids = get_x_players ($tm, $assertion, $role_id) This function returns the player(s) for the given role. If the role is not provided all players are returned. The \*(L"x\*(R" version does not honor subclassing.

is_role, is_x_role

$bool = is_role ($tm, $assertion, $role_id) $bool = is_x_role ($tm, $assertion, $role_id) This function returns 1 if the \*(C`role_id\*(C' is a role in the assertion provided. The \*(L"x\*(R" version of this function does not honor subclassing.

get_roles

@role_ids = get_roles ($tm, $assertion, $player) This function returns a list of roles a particular player plays in a given assertion.

get_role_s

@role_ids = @{ get_role_s ($tm, $assertion) } This function extracts a reference to the list of role identifiers.

Auxiliary Functions

absolutize

$assertion = absolutize ($tm, $assertion) This method takes one assertion and makes sure that all identifiers in it (for the type, the scope and all the role and players) are made absolute for the context map. It returns this very assertion. It will not touch canonicalized assertions.

canonicalize

$assertion = canonicalize ($tm, $assertion) This method takes an assertion and reorders the roles (together with their respective players) in a consistent way. It also makes sure that the \s-1KIND\s0 is defined (defaults to \*(C`ASSOC\*(C'), that the type is defined (defaults to \*(C`THING\*(C') and that all references are made absolute LIDs. Finally, the field \*(C`CANON\*(C' is set to 1 to indicate that the assertion is canonicalized. The function will not do anything if the assertion is already canonicalized. The component \*(C`CANON\*(C' is set to 1 if the assertion has been canonicalized. Conveniently, the function returns the same assertion, albeit a maybe modified one. \s-1TODO:\s0 remove map parameter, it is no longer necessary

TAXONOMICS AND SUBSUMPTION

The following methods provide useful basic, ontological functionality around transitive subclassing between classes and instance/type relationships.

\s-1NOTE\s0: Everything is a subclass of \*(C`thing\*(C' (changed in v1.35).

\s-1NOTE\s0: Everything is an instance of \*(C`thing\*(C'.

\s-1NOTE\s0: See \s-1TM::PSI\s0 for predefined things.

Boolean Methods

is_subclass

$bool = $tm->is_subclass ($superclass_id, $subclass_id) This function returns 1 if the first parameter is a (transitive) superclass of the second, i.e. there is an assertion of type is-subclass-of in the context map. It also returns 1 if the superclass is a $TM::PSI::THING or if subclass and superclass are the same (reflexive).

is_a

$bool = $tm->is_a ($something_lid, $class_lid) This method returns 1 if the thing referenced by the first parameter is an instance of the class referenced by the second. The method honors transitive subclassing.

List Methods

subclasses, subclassesT

@lids = $tm->subclasses ($lid, ...) @lids = $tm->subclassesT ($lid, ...) \*(C`subclasses\*(C' returns all direct subclasses of the toplet identified by $lid. If the toplet does not exist, the list will be empty. \*(C`subclassesT\*(C' is a variant which honors the transitive subclassing (so if A is a subclass of B and B is a subclass of C, then A is also a subclass of C). Duplicates are suppressed.

superclasses, superclassesT

@lids = $tm->superclasses ($lid, ...) @lids = $tm->superclassesT ($lid, ...) The method \*(C`superclasses\*(C' returns all direct superclasses of the toplet identified by $lid. If the toplet does not exist, the list will be empty. \*(C`superclassesT\*(C' is a variant which honors transitive subclassing. Duplicates are suppressed.

types, typesT

@lids = $tm->types ($lid, ...) @lids = $tm->typesT ($lid, ...) The method \*(C`types\*(C' returns all direct classes of the toplet identified by $lid. If the toplet does not exist, the list will be empty. \*(C`typesT\*(C' is a variant which honors transitive subclassing (so if a is an instance of type A and A is a subclass of B, then a is also an instance of B). Duplicates will be suppressed.

instances, instancesT

@lids = $tm->instances ($lid, ...) @lids = $tm->instancesT ($lid, ...) These methods return the direct (\*(C`instances\*(C') and also indirect (\*(C`instancesT\*(C') instances of the toplet identified by $lid. Duplicates are suppressed.

Filters

Quite often one needs to walk through a list of things to determine whether they are instances (or types, subtypes or supertypes) of some concept. This list of functions lets you do that: you pass in a list (reference) and the function behaves as filter, returning a list reference.

are_instances

@id = $tm->are_instances ($class_id, @list_of_ids) Returns all those ids where the topic is an instance of the class provided.

are_types (Warning: placeholder only)

@ids = $tm->are_types ($instance_id, @list_of_ids) Returns all those ids where the topic is a type of the instance provided.

are_supertypes (Warning: placeholder only)

@ids = $tm->are_supertypes ($class_id, @list_of_ids) Returns all those ids where the topic is a supertype of the class provided.

are_subtypes (Warning: placeholder only)

@ids = $tm->are_subtypes ($class_id, @list_of_ids) Returns all those ids where the topic is a subtype of the class provided.

REIFICATION

is_reified

($tid) = $tm->is_reified ($assertion) ($tid) = $tm->is_reified ($url) In the case that the handed-in assertion is internally reified in the map, this method will return the internal identifier of the reifying toplet. Or \*(C`undef\*(C' if there is none. In the case that the handed-in \s-1URL\s0 is used as subject address of a toplet, this method will return the internal identifier of the reifying toplet. Or \*(C`undef\*(C' if there is none.

reifies

$url = $tm->reifies ($tid) $assertion = $tm->reifies ($tid) Given a toplet identifier, this method returns either the internally reified assertion, an externally reified object via its \s-1URL\s0, or \*(C`undef\*(C' if that toplet does not reify at all. No comment.

variants

$tm->variants ($id, $variant) $tm->variants ($id) With this method you can get/set a variant tree for any topic. According to the standard only basenames (aka topic names) can have variants, but, hey, this is such an ugly beast (I am digressing). According to this data model you can have variants for all toplets/maplets. You only need their id. The structure is like this: $VAR1 = { 'tm:param1' => { 'variants' => { 'tm:param3' => { 'variants' => undef, 'value' => 'name for param3' } }, 'value' => 'name for param1' }, 'tm:param2' => { 'variants' => undef, 'value' => 'name for param2' } }; The parameters are the keys (there can only be one, which is a useful, cough, restriction of the standard) and the data is the value. Obviously, one key value (i.e. parameter) can only exists once. Caveat: This is not very well tested (read: not tested at all).

LOGGING

The \s-1TM\s0 module hosts (since 1.29) the Log4Perl object $TM::log. It is initialized with some reasonable defaults, but an using application can access it, tweak it, or overwrite it completely.

RELATED TO TM…

\s-1TM::PSI\s0, Log::Log4perl

COPYRIGHT AND LICENSE

Copyright 200[1-8] 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.