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