1 package Text::Tradition::Collation::Reading::Lexeme;
8 Text::Tradition::Collation::Reading::Lexeme - represents the components of
13 Text::Tradition is a library for representation and analysis of collated
14 texts, particularly medieval ones. A word form is used for the analysis of
15 Reading objects; it consists of a lemma, a language, and a code to
16 represent its part of speech. In general the word forms for a particular
17 language should be read from / written to some morphological database.
23 Creates a new lexeme from the passed options.
27 Returns the language to which this lexeme belongs.
31 Returns the canonical string version of this lexeme.
35 Returns the number of possible word forms for this lexeme, as drawn from
36 the appropriate database.
40 Returns an array of the possible word forms for this lexeme.
42 =head2 matching_form( $index )
44 Returns the form at $index in the list of matching forms.
46 =head2 is_disambiguated
48 Returns true if a single wordform has been picked as 'correct' for this
49 lexeme in its context.
53 Returns the correct word form (if any has been selected) for the lexeme in
58 # TODO need to be able to populate this from DB
71 has 'wordform_matchlist' => (
72 isa => 'ArrayRef[Text::Tradition::Collation::Reading::WordForm]',
76 'matching_forms' => 'elements',
77 'matching_form' => 'get',
78 'add_matching_form' => 'push',
82 has 'is_disambiguated' => (
90 isa => 'Text::Tradition::Collation::Reading::WordForm',
91 writer => '_set_form',
94 # Do auto-disambiguation if we were created with a single wordform
98 if( $self->matches == 1 ) {
99 $self->disambiguate( 0 );
103 =head2 disambiguate( $index )
105 Selects the word form at $index in the list of matching forms, and asserts
106 that this is the correct form for the lexeme.
111 my( $self, $idx ) = @_;
112 my $form = $self->matching_form( $idx );
113 throw( "There is no candidate wordform at index $idx" )
115 $self->_set_form( $form );
116 $self->is_disambiguated( 1 );
121 Uses the module for the declared language to look up the lexeme in the
122 language database (if any.) Sets the returned morphological matches in
123 matching_forms, and returns the list as an array of WordForm objects.
129 my $lang = $self->language;
132 my $langmod = "Text::Tradition::Language::$lang";
134 @answers = $langmod->can( 'word_lookup' )->( $self->string );
136 throw( "No language module for $lang, or the module has no word_lookup functionality" );
138 $self->clear_matching_forms;
139 $self->add_matching_form( @answers );
144 __PACKAGE__->meta->make_immutable;
150 This package is free software and is provided "as is" without express
151 or implied warranty. You can redistribute it and/or modify it under
152 the same terms as Perl itself.
156 Tara L Andrews E<lt>aurum@cpan.orgE<gt>