46a9f80a3a60838ca4e1b0cfcbb2ed2881bb8443
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Reading / WordForm.pm
1 package Text::Tradition::Collation::Reading::WordForm;
2
3 use Moose;
4 use Lingua::Features::Structure;
5
6 =head1 NAME
7
8 Text::Tradition::Collation::Reading::WordForm - represents a
9 language/lemma/morphology triplet that can be associated with a Reading.
10
11 =head1 DESCRIPTION
12
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.
18
19 =head1 METHODS
20
21 =head2 new
22
23 Creates a new word form from the passed options.
24
25 =head2 language
26
27 Returns the language to which this word form belongs.
28
29 =head2 lemma
30
31 Returns the lemma for the word form.
32
33 =head2 morphology
34
35 Returns an array representing this word's morphology. The contents of the
36 array depend on the language being used.
37
38 =cut
39
40 has 'language' => (
41         is => 'ro',
42         isa => 'Str',
43         required => 1,
44         );
45         
46 # TODO do we need this?
47 has 'form' => (
48         is => 'ro',
49         isa => 'Str',
50         # required => 1,
51         );
52         
53 has 'lemma' => (
54         is => 'ro',
55         isa => 'Str',
56         required => 1,
57         );
58         
59 has 'morphology' => (
60         is => 'ro',
61         isa => 'Lingua::Features::Structure',
62         required => 1,
63         );
64         
65 around 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         
78 =head2 to_string
79
80 Returns a string combination of language/lemma/morphology that can be used
81 in equivalence testing.
82
83 =cut
84
85 sub to_string {
86         my $self = shift;
87         return join( '++', $self->language, $self->lemma, $self->morphology->to_string );
88 }
89         
90 no Moose;
91 __PACKAGE__->meta->make_immutable;
92
93 1;
94
95 =head1 LICENSE
96
97 This package is free software and is provided "as is" without express
98 or implied warranty.  You can redistribute it and/or modify it under
99 the same terms as Perl itself.
100
101 =head1 AUTHOR
102
103 Tara L Andrews E<lt>aurum@cpan.orgE<gt>