read lexeme info in GraphML parsing
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Reading / WordForm.pm
CommitLineData
cca4f996 1package Text::Tradition::Collation::Reading::WordForm;
2
3use Moose;
70745e70 4use Lingua::Features::Structure;
cca4f996 5
6=head1 NAME
7
8Text::Tradition::Collation::Reading::WordForm - represents a
9language/lemma/morphology triplet that can be associated with a Reading.
10
11=head1 DESCRIPTION
12
13Text::Tradition is a library for representation and analysis of collated
14texts, particularly medieval ones. A word form is used for the analysis of
15Reading objects; it consists of a lemma, a language, and a code to
16represent its part of speech. In general the word forms for a particular
17language should be read from / written to some morphological database.
18
19=head1 METHODS
20
21=head2 new
22
23Creates a new word form from the passed options.
24
25=head2 language
26
27Returns the language to which this word form belongs.
28
29=head2 lemma
30
31Returns the lemma for the word form.
32
33=head2 morphology
34
35Returns an array representing this word's morphology. The contents of the
36array depend on the language being used.
37
38=cut
39
40has 'language' => (
41 is => 'ro',
42 isa => 'Str',
43 required => 1,
44 );
45
46# TODO do we need this?
47has 'form' => (
48 is => 'ro',
49 isa => 'Str',
50 # required => 1,
51 );
52
53has 'lemma' => (
54 is => 'ro',
55 isa => 'Str',
56 required => 1,
57 );
58
59has 'morphology' => (
60 is => 'ro',
6ad2ce78 61 isa => 'Lingua::Features::Structure',
cca4f996 62 required => 1,
63 );
64
70745e70 65around BUILDARGS => sub {
66 my $orig = shift;
67 my $class = shift;
68 my $args = @_ == 1 ? $_[0] : { @_ };
69 if( exists $args->{'serial'} ) {
70 my( $lang, $lemma, $morph ) = split( /\+\+/, delete $args->{'serial'} );
71 $args->{'language'} = $lang;
72 $args->{'lemma'} = $lemma;
73 $args->{'morphology'} = Lingua::Features::Structure->from_string( $morph );
74 }
75 $class->$orig( $args );
76};
77
6ad2ce78 78=head2 to_string
79
80Returns a string combination of language/lemma/morphology that can be used
81in equivalence testing.
82
83=cut
84
85sub to_string {
cca4f996 86 my $self = shift;
6ad2ce78 87 return join( '++', $self->language, $self->lemma, $self->morphology->to_string );
cca4f996 88}
6ad2ce78 89
cca4f996 90no Moose;
91__PACKAGE__->meta->make_immutable;
92
931;
94
95=head1 LICENSE
96
97This package is free software and is provided "as is" without express
98or implied warranty. You can redistribute it and/or modify it under
99the same terms as Perl itself.
100
101=head1 AUTHOR
102
103Tara L Andrews E<lt>aurum@cpan.orgE<gt>