1 package Text::Tradition::Collation::Reading::WordForm;
3 use Lingua::Features::Structure;
6 use Text::Tradition::Error;
11 Text::Tradition::Collation::Reading::WordForm - represents a
12 language/lemma/morphology triplet that can be associated with a Reading.
16 Text::Tradition is a library for representation and analysis of collated
17 texts, particularly medieval ones. A word form is used for the analysis of
18 Reading objects; it consists of a lemma, a language, and a code to
19 represent its part of speech. In general the word forms for a particular
20 language should be read from / written to some morphological database.
26 Creates a new word form from the passed options.
30 Returns the language to which this word form belongs.
34 Returns the lemma for the word form.
38 Returns an array representing this word's morphology. The contents of the
39 array depend on the language being used.
61 around BUILDARGS => sub {
64 my $args = @_ == 1 ? $_[0] : { @_ };
65 if( exists $args->{'JSON'} ) {
66 my @data = split( / \/\/ /, $args->{'JSON'} );
67 # print STDERR "Attempting to parse " . $data[2] . " into structure";
68 $args = { 'language' => $data[0], 'lemma' => $data[1],
69 'morphstr' => $data[2] };
70 } elsif( exists $args->{'morphology'} ) {
72 my $mobj = delete $args->{'morphology'};
73 $args->{'morphstr'} = $mobj->to_string()
76 $class->$orig( $args );
81 Returns a Lingua::Features::Structure object that corresponds to morphstr.
87 return unless $self->morphstr;
90 $struct = Lingua::Features::Structure->from_string( $self->morphstr );
92 throw( "Morphology string " . $self->morphstr . " does not parse" );
99 Returns a string combination of language/lemma/morphology that can be used
100 in equivalence testing.
106 return JSON->new->convert_blessed(1)->encode( $self );
109 # Rather than spitting it out as a JSON hash, encode it as a string so that
110 # the XML serialization doesn't become insane.
113 return sprintf( "%s // %s // %s", $self->language, $self->lemma,
118 Text::Tradition::Error->throw(
119 'ident' => 'Wordform error',
125 __PACKAGE__->meta->make_immutable;