NAME

TM::Tau - Topic Maps, Tau Expressions

SYNOPSIS

use TM::Tau;
# read a map from an XTM file
$tm = new TM::Tau ('test.xtm');        # or
$tm = new TM::Tau ('file:test.xtm');   # or
$tm = new TM::Tau ('file:test.xtm >'); # or
$tm = new TM::Tau ('file:test.xtm > null:');

# read it now and write it back to the file when object goes out of scope
$tm = new TM::Tau ('test.xtm > test.xtm');

# create empty map at start and then let it automatically flush onto file
$tm = new TM::Tau ('null: > test.xtm');
$tm = new TM::Tau ('> test.xtm');

# read-in at the start (=constructor time) and then flush it back
$tm = new TM::Tau ('> test.xtm >');

# load and merge maps at constructor time
$tm = new TM::Tau ('file:test.xtm + http://..../test.atm');

# load map and filter it with a constraint at constructor time
$tm = new TM::Tau ('mymap.atm * myontology.ont');

# convert between different formats
$tm = new TM::Tau ('test.xtm > test.atm'); # if there were an output driver for AsTMa=

DESCRIPTION

This package allows you to implement a breath-in-breath-out paradigm when using topic maps coming from different provenances. This, for instance, allows you to create a topic map which is read from an AsTMa= file when it is instantiated at constructor time and then is saved into an XTM file when the topic map object goes out of scope. When, how, or whether at all the in-memory representation of the map is synchronized with these external resources, you can control with a simple language, presented below.

This language also provides two binary operators to combine maps in this process. With + maps can be merged, with * a filter can be applied to a map.

TAU EXPRESSIONS

Introduction

tau expressions serve several purposes:

  • First, they allow to address whole maps via a URI.

  • Then they allow to connect (real or virtual) topic maps together forming bigger maps. In

    # merging two map, one in AsTMa format, another in XTM
    file:tm.atm + http://topicmaps/some/map.xtm

    we use the + operator to merge two maps into one.

    NOTE: Future versions of this package will use the + operator also between maps and ontologies.

  • Tau expressions are then generalized to filter maps. Ontologies serve as filters as they are interpreted as constraints. Only those parts of the original map which conform to the ontology survive the filter process.

    # filter out according to an ontology
    product_data.atm * file:customer_view.onto

    The * operator symbolizes the filtering operation.

  • Tau expressions are also used to completely transform maps into other maps (ontological transformation).

      file:music.atm * beatles.atq
      file:music.atm * elvis.atq

    Here * symbolizes the transformation.

NOTE: Some of this filter functionality may not be yet implemented.

Map Source URLs

To address maps we use URIs. A map stored in the file system might be addressed as

file:mydir/somemap.xtm

for a relative URL (relative to an application's current working directory), or via an absolute URI such as

http://myserver/somemap.atm

The package supports all those access methods (file:, http:, ...) which LWP::Simple supports.

Drivers

Obviously a different deserializer package has to be used for an XTM file than for an AsTMa or LTM file. Some topic map content may be in a TM backend database, some content may only exist virtually, being emulated by a dedicated package. While you may be mostly fine with system defaults, in some cases you may want to have precise control on how files and other external sources are to be interpreted. By their nature, drivers for sources must be subclasses of TM.

A similar consideration applies to filters. Also here the specified URI determines which filter actually has to be applied. It also can define where the content eventually is stored to. Drivers for filters must be either subclasses of TM::Tau::Filter, or alternatively must be a trait providing a method sync_out.

Binding by Schemes (implicit)

When the Tau expression is parsed, this package tries to identify which driver to use for which part of that composite map denoted by the expression. For this purpose a pattern matching approach can be used to map regular expression patterns to driver package names. If you would like to learn about the current state of affairs do a

use Data::Dumper;
print Dumper \%TM::Tau::sources;
print Dumper \%TM::Tau::filters;

Each entry contains as key a regular expression which is matched against the parsed URI and as value the name of the driver to be used. There is a distinction made between the namespace of resources (residing data) and filters (and transformers).

You can override values there:

$TM::Tau::sources{'null:'}          = 'TM';
$TM::Tau::sources{'tm:server\.com'} = 'My::Private::TopicMap::Driver';

At any time you can modify this hash, introduce new patterns, delete existing ones. The only constraint is that the driver package must already be required into your Perl program.

During parsing of a Tau expression, two cases are distinguised:

  • If the URI specifies a source, then this URI will be matched against the regexps in the TM::Tau::sources hash. The value of that entry will be used as class name to instantiate an object whereby one component (uri) will be passed as parameter like this:

    $this_class_name->new (uri => $this_uri, baseuri => $this_uri)

    This class should be a subclass of TM.

  • If te URI specifies a filter, then you have two options: Either you use as entry the name of a subclass of TM::Tau::Filter. Then an object is create like above. Alternatively, the entry is a list reference containing names of traits. Then a generic TM::Tau::Filter node is generated first and each of the traits are applied like this:

    Class::Trait->apply ( $node => $trait => { exclude => [ 'mtime', 'sync_out', 'source_in' ] } );

If there is no match, this results in an exception.

Binding by Package Pragmas (Explicit)

Another way to define which package should be used for a particular map is to specify this directly in the tau expression:

http://.../map.xtm { My::BrokenXTM }

In this case the resource is loaded and is processed using My::BrokenXTM as package to parse it (see TM::Materialized::Stream on how to write such a driver).

Syntax

The Tau expression language supports two binary operators, + and *. The + operator intuitively puts things together, the * applies the right-hand operand to the left-hand operand and behave as a transformer or a filter. The exact semantics depends on the operands. In any case, the * binds stronger than the +.

The parser understands the following syntax for Tau expression:

tau_expr    -> mul_expr

mul_expr    -> source { '*' filter }

source      -> '(' add_expr ')' | primitive

add_expr    -> mul_expr { '+' mul_expr }

filter      -> '(' filter ')' | primitive

primitive   -> uri [ module_spec ]

module_spec -> '{' name '}'

Terms in quotes are terminals, terms inside {} can appear any number of times (also zero), terms inside [] are optional. All other terms are non-terminals.

Examples

# memory-only map
null: > null:

# read at startup, sync out on request of application
file:test.atm > file:test.atm

# copy AsTMa= to XTM
file:test.atm > file:test.xtm
# this only works if the XTM driver supports outputting

# using a dedicated driver to load a map, store it onto a file
dns:my.dns.server { My::DNS::Driver } > file:dns_snapshot.atm
# this will only work if the My::DNS::Driver supports to materialize a map

# read a map and compute the statistics
file:test.atm * http://psi.tm.bond.edu.au/queries/1.0/statistics

INTERFACE

Constructor

The constructor accepts a tau-expression parameter defining how the map is supposed to be built. If that parameter is missing, null: will be assumed which results in an empty map to be created. That map, though, contains a memory component, so that things can be added to it after that. Otherwise the Tau expression must follow the tau algebra syntax given in "Syntax". If not, then an appropriate exception will be raised.

If - during the parsing process - no appropriate driver package for a particular resource can be identified, an exception will be raised.

Examples:

# map only existing in memory
my $map = new TM::Tau;

# map will be loaded as result of this tau expression
my $map = new TM::Tau ('file:music.atm * file:beatles.tmql');

Apart from the Tau expression the constructor optionally interprets a hash with the following keys:

sync_in (default: 1)

If non-zero, in-synchronisation at constructor time will happen, otherwise it is suppressed. In that case you can trigger in-synchronisation explicitly with the method sync_in.

sync_out (default: 1)

If non-zero, out-synchronisation at destruction time will happen, otherwise it is suppressed.

Example:

my $map = new TM::Tau ('test.xtm', sync_in => 0);

The (pre)parser supports the following shortcuts (I hate unnecessary typing):

  • "whatever" is interpreted as "(whatever) > -"

  • "whatever >" is interpreted as "(whatever) > -"

  • "> whatever" is interpreted as "- > (whatever)"

  • "< whatever >" is interpreted as "whatever > whatever", sync_in => 0

  • "> whatever <" is interpreted as "whatever > whatever", sync_out => 0

  • "> whatever >" is interpreted as "whatever > whatever"

  • "< whatever <" is interpreted as "whatever > whatever", sync_in => 0, sync_out => 0

  • The URI - as source is interpreted as STDIN (via the TM::Serializable::AsTMa trait).

  • The URI - as filter is interpreted as STDOUT (via the TM::Serializable::Dumper trait).

SEE ALSO

TM, TM::Tau::Filter

AUTHOR

Copyright 200[0-6], Robert Barta <drrho@cpan.org>, All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. http://www.perl.com/perl/misc/Artistic.html