Perl TM Tutorial: As Low as it Gets (Part III)

(Followup to part II)

Looking up assertions with match_forall works, but is cumbersome if you just want to find instances, types, subtypes or supertypes of a given toplet.

To experiment with this here, we need some topic map with just a few types, subtypes and some instances for these. Instead of creating them programmatically, we write the map in one of the convenient text notations and let a parser do the job.

For the notation we choose (the old and trusty) AsTMa:

use TM::Materialized::AsTMa;
my $tm = new TM::Materialized::AsTMa (inline => '
sacklpicka (cat)

rho (human)

(is-subclass-of)
subclass: human
superclass: mammal

(is-subclass-of)
subclass: cat
superclass: mammal

'
);

The map features sacklpicka as an instance of cat and rho as an instance of human.

After loading a package supporting the notation, we instantiate our map object $tm. As we are too lazy to store the AsTMa text in a file, we use the option to specify AsTMa code inline. Still, we have to tell the map to read and deserialize the content now:

$tm->sync_in;

More about persistent maps later.

Taxonometrics

As you would expect, sacklpicka will be listed as instance of cat:

use Data::Dumper;
warn Dumper [ $tm->instances ($tm->tids ('cat')) ];

Since mammal does not have any direct instances, the following list will be empty:

warn Dumper [ $tm->instances ($tm->tids ('mammal')) ];

To eventually reach also those instances which are instances of any of mammal's subtype(s), you will have to use the transitive version.

warn Dumper [ $tm->instancesT ($tm->tids ('mammal')) ];

In a similar vein the TM package offers functions to learn about

  • the subclasses, direct and indirect
  • any superclasses, direct and indirect, and
  • any types, also direct and indirect ones.

Boolean Versions

Since such taxonometric functions are pretty important, there is also a set of functions just for boolean tests:

warn "I knew it"
    if $tm->is_a ($tm->tids ('sacklpicka', 'cat'));

warn "Not sure about that"
    unless $tm->is_subclass ($tm->tids ('cat', 'mammal'));

Note how the tids function can accept lists.

Filter Versions

Finally, there are also variants to be used as filters for a certain class:

@cats = $tm->are_instances ($tm->tids ('cat',
                                       'rho',
                                       'sacklpicka') );

Sadly, at this stage the other filters are_types, are_supertypes and are_subtypes are not yet implemented.

Send more chocolate if you need them. Better than sending patches ...


Work supported by the Austrian Research Centers.

Posted In

Post new comment

The content of this field is kept private and will not be shown publicly.
Captcha
Hey, what about a little test whether you are a spammer? Or a human? Notice the difference?
Copy the characters (respecting upper/lower case) from the image.