NAME

Lingua::Thesaurus::Term - parent class for thesaurus terms

SYNOPSIS

my $term = $thesaurus->fetch_term($term_string);

# methods for specific relations
my $scope_note = $term->SN;
my @synonyms   = $term->UF;

# exploring several relations at once
foreach my $pair ($term->related(qw/NT RT/)) {
  my ($rel_type, $item) = @$pair;
  printf "  %s(%s) = %s\n", $rel_type->description, $rel_type->rel_id, $item;
}

# transitive search
foreach my $quadruple ($term->transitively_related(qw/NT/)) {
  my ($rel_type, $related_term, $through_term, $level) = @$quadruple;
  printf "  %s($level): %s (through %s)\n", 
     $rel_type->rel_id,
     $level,
     $related_term->string,
     $through_term->string;
}

DESCRIPTION

Objects of this class encapsulate terms in a thesaurus. They possess methods for navigating through relations, reaching other terms or external data.

CONSTRUCTOR

new

my $term = Lingua::Thesaurus::Term->new(
  storage => $storage, # an object playing role Lingua::Thesaurus::Storage
  id      => $id,      # unique id for this term
  string  => $string,  # the actual term string
  origin  => $origin,  # an identifier for the file where this term was found
);

Creates a new term object; not likely to be called from client code, because such objects are created automatically from the thesaurus through "search_terms" in Lingua::Thesaurus and "fetch_term" in Lingua::Thesaurus methods.

ATTRIBUTES

storage

Reference to the storage object from which this term was issued.

id

unique storage id for the term

string

the term itself

origin

tagname of the dumpfile where this term was found

METHODS

my @pairs = $term->related(@relation_ids);

Returns a list of items related to the current term, through one or several @relation_ids. Each returned item is a pair, where the first element is an instance of Lingua::Thesaurus::RelType, and the second element is either a plain string (when the relation type is "external"), or another term (when the relation type is "internal").

NT, BT, etc.

my @narrower_terms = $term->NT;
my $broader_term   = $term->BT;
...

Specific navigation methods, such as NT, BT, etc., depend on the relation types declared in the thesaurus; once those relations are known, a subclass of Lingua::Thesaurus::Term is automatically created, with the appropriate additional methods.

Internally these methods are implemented of course by calling the "related" method described above; but instead or returning a list of pairs, they just return related items (since the relation type is explicitly requested in the method call, it would be useless to return it again as a result). The result is either a list or a single related item, depending on the calling context.

my @quadruples = $term->transitively_related(@relation_ids);

Returns a list of items directly or indirectly related to the current term, through one or several @relation_ids. Each returned item is a quadruple, where the first two elements are as in the ""related" method, and the two remaining elements are

  • the last intermediate term through wich this relation was reached

  • the level of transitive steps