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.
49 # TODO do we need this?
64 isa => 'Lingua::Features::Structure',
68 around BUILDARGS => sub {
71 my $args = @_ == 1 ? $_[0] : { @_ };
72 if( exists $args->{'JSON'} ) {
73 my @data = split( / \/\/ /, $args->{'JSON'} );
74 # print STDERR "Attempting to parse " . $data[2] . " into structure";
77 $morph = Lingua::Features::Structure->from_string( $data[2] );
79 throw("Could not parse string " . $data[2] . " into morphological structure");
81 $args = { 'language' => $data[0], 'lemma' => $data[1],
82 'morphology' => $morph };
84 $class->$orig( $args );
89 Returns a string combination of language/lemma/morphology that can be used
90 in equivalence testing.
96 return JSON->new->convert_blessed(1)->encode( $self );
99 # Rather than spitting it out as a JSON hash, encode it as a string so that
100 # the XML serialization doesn't become insane.
103 return sprintf( "%s // %s // %s", $self->language, $self->lemma,
104 $self->morphology->to_string() );
108 Text::Tradition::Error->throw(
109 'ident' => 'Wordform error',
115 __PACKAGE__->meta->make_immutable;
121 This package is free software and is provided "as is" without express
122 or implied warranty. You can redistribute it and/or modify it under
123 the same terms as Perl itself.
127 Tara L Andrews E<lt>aurum@cpan.orgE<gt>