Lingua::Thesaurus::Storage - Role for thesaurus storage


This role specifies the interface for thesaurus storage classes.


Retrieval methods


Implementation for "search_terms" in Lingua::Thesaurus.


Implementation for "fetch_term" in Lingua::Thesaurus.

Implementation for "related" in Lingua::Thesaurus::Term.


Implementation for "rel_types" in Lingua::Thesaurus.


Implementation for "fetch_rel_type" in Lingua::Thesaurus.

Populating the database


Called by an IO class to initialize storage before a load operation.



Will execute $coderef within a transaction. This is used by "load" in Lingua::Thesaurus::IO to store all terms and relations in a single step.


  my $term_id = $storage->store_term($term_string);

Stores a new term, and returns the unique storage id for this term. Depending on the implementation, an exception could be raised if several attempts are made to store the same $term_string.


  $storage->store_rel_type($rel_id, $description, $is_external);

Stores a new relation type.

  • $rel_id is a unique identifier string for this relation type (such as 'NT' or 'UF').

  • $description is an optional free text description

  • $is_external is a boolean which tells whether related items will be other terms or external data.


  $storage->store_relation($term_id, $rel_id, $related,
                           $is_external, $inverse_id);

Stores a relation, where

  • $term_id is the unique identifier for the first term in the relation

  • $rel_id is the unique identifier for relation type

  • $related is an arrayref of items to relate to the term; if $is_external is true, these items can be any scalar; if $is_external is false, items should be identifiers of other terms.

    The storage should preserve the order of items in $related, i.e. the "related" method should return items in the same order.

  • $is_external is a boolean which tells what kind of items are related, as explained above

  • $inverse_id is the optional identifier of the inverse relation type; if non-null, relations will be stored in both directions.


Will be called by IO classes after loading files. Storage implementations may use this to perform cleanup operations if needed.