TM::Index::Reified - Topic Maps, Indexing support (reification axis)


TM documentation Contained in the TM distribution.

Index


Code Index:

NAME

Top

TM::Index::Reified - Topic Maps, Indexing support (reification axis)

SYNOPSIS

Top

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

    # one option: create an eager index (immediate population)
    use TM::Index::Reified;
    my $idx = new TM::Index::Reified ($tm, closed => 1);

    # for most operations which involve is_reified to be called
    # should be much faster

DESCRIPTION

Top

This index can be attached to a map if the method is_reified is about to be called very often. Most likely you will want to have the index to be closed, i.e. populated.

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

NOTE: As for all indices, modifications of the underlying map are not reflected automatically.

INTERFACE

Top

Constructor

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

Methods

attach, detach

This index attaches in a special way to the map.

populate

Invoking this, you will fill this index with authoritative information.

SEE ALSO

Top

TM, TM::Index

COPYRIGHT AND LICENSE

Top


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

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

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

sub attach {
    my $self = shift;
    my $tm   = shift || $self->{map};
warn "attach";
    $tm->{rindex} = [ $self ];                                 # there will only be one, but we will use one indirection to fool MLDBM
warn "end attach ". Dumper $tm->{rindex};
}

sub detach {
    my $self = shift;
    my $tm   = shift || $self->{map};
warn "detach";
    $tm->{rindex} = undef;
    $self->{map}  = undef;   # regardless whether this is loose coupling or not
}

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

    warn "reif populate";

    my $mid2iid = $tm->{mid2iid};

    map { $cache->{ $mid2iid->{$_}->[TM->ADDRESS] } = $_ }  # invert the index
        grep { $mid2iid->{$_}->[TM->ADDRESS] }              # only those which "reify" something survive
        keys %{$mid2iid};                                   # all toplet tids

    $self->{closed} = 1;
}

our $VERSION = 0.4;

1;

__END__