TM::Index::Taxonomy - Topic Maps, Indexing support (match layer)


TM documentation Contained in the TM distribution.

Index


Code Index:

NAME

Top

TM::Index::Taxonomy - Topic Maps, Indexing support (match layer)

SYNOPSIS

Top

    # somehow get a map (any subclass of TM will do)
    my $tm = ... 

    # one option: create a lazy index which learns as you go
    use TM::Index::Taxonomy;
    my $idx = new TM::Index::Taxonomy ($tm)->populate;

    # for most operations which involve taxonometric functions to be called
    # that should be much faster

DESCRIPTION

Top

This index can be attached to a map if querying it for subclass/superclass and/or instances/classes is intensive.

The package inherits most of its functionality from TM::Index.

INTERFACE

Top

Constructor

The constructor/destructor is inherited from TM::Index.

Methods

SEE ALSO

Top

TM, TM::Index

COPYRIGHT AND LICENSE

Top


TM documentation Contained in the TM distribution.
package TM::Index::Taxonomy;

use strict;
use warnings;
use Data::Dumper;

use TM;
use base qw(TM::Index);

sub populate {
    my $self  = shift;
    my $map   = $self->{map};
    my $cache = $self->{cache};

    foreach my $a (values %{ $map->{assertions} }) {
	next unless $a->[TM->KIND] == TM->ASSOC;                                     # these are not interesting here
	if      ($a->[TM->TYPE] eq 'isa') {
	    my ($class, $instance) = @{ $a->[TM->PLAYERS] };
	    push @{ $cache->{"class.type:$class.isa"} },                      $a->[TM->LID];
	    push @{ $cache->{"instance.type:$instance.isa"} },                $a->[TM->LID];

	} elsif ($a->[TM->TYPE] eq 'is-subclass-of') {
	    my ($subclass, $superclass) = @{ $a->[TM->PLAYERS] };
	    push @{ $cache->{"superclass.type:$superclass.is-subclass-of"} }, $a->[TM->LID];
	    push @{ $cache->{"subclass.type:$subclass.is-subclass-of"} },     $a->[TM->LID];

	} else {
	    # ignore everything else
	}
    }
}

our $VERSION = 0.1;

1;

__END__