1 package Text::Tradition::Collation::Reading;
5 use overload '""' => \&_stringify, 'fallback' => 1;
9 Text::Tradition::Collation::Reading - represents a reading (usually a word)
14 Text::Tradition is a library for representation and analysis of collated
15 texts, particularly medieval ones. A 'reading' refers to a unit of text,
16 usually a word, that appears in one or more witnesses (manuscripts) of the
17 tradition; the text of a given witness is composed of a set of readings in
24 Creates a new reading in the given collation with the given attributes.
29 =item collation - The Text::Tradition::Collation object to which this
30 reading belongs. Required.
32 =item id - A unique identifier for this reading. Required.
34 =item text - The word or other text of the reading.
36 =item is_start - The reading is the starting point for the collation.
38 =item is_end - The reading is the ending point for the collation.
40 =item is_lacuna - The 'reading' represents a known gap in the text.
42 =item is_ph - A temporary placeholder for apparatus parsing purposes. Do
43 not use unless you know what you are doing.
45 =item rank - The sequence number of the reading. This should probably not
50 One of 'text', 'is_start', 'is_end', or 'is_lacuna' is required.
66 Accessor methods for the given attributes.
72 isa => 'Text::Tradition::Collation',
87 writer => 'alter_text',
93 predicate => 'has_language',
129 predicate => 'has_rank',
130 clearer => 'clear_rank',
133 ## For morphological analysis
135 has 'normal_form' => (
138 predicate => 'has_normal_form',
141 # Holds the word form. If is_disambiguated is true, the form at index zero
142 # is the correct one.
143 has 'reading_lexemes' => (
145 isa => 'ArrayRef[Text::Tradition::Collation::Reading::Lexeme]',
147 lexemes => 'elements',
148 has_lexemes => 'count',
149 clear_lexemes => 'clear',
150 add_lexeme => 'push',
152 default => sub { [] },
155 ## For prefix/suffix readings
157 has 'join_prior' => (
170 around BUILDARGS => sub {
180 # If one of our special booleans is set, we change the text and the
182 if( exists $args->{'is_lacuna'} && !exists $args->{'text'} ) {
183 $args->{'text'} = '#LACUNA#';
184 } elsif( exists $args->{'is_start'} ) {
185 $args->{'id'} = '#START#'; # Change the ID to ensure we have only one
186 $args->{'text'} = '#START#';
188 } elsif( exists $args->{'is_end'} ) {
189 $args->{'id'} = '#END#'; # Change the ID to ensure we have only one
190 $args->{'text'} = '#END#';
191 } elsif( exists $args->{'is_ph'} ) {
192 $args->{'text'} = $args->{'id'};
195 $class->$orig( $args );
200 A meta attribute (ha ha), which should be true if any of our 'special'
201 booleans are true. Implies that the reading does not represent a bit
202 of text found in a witness.
208 return $self->is_start || $self->is_end || $self->is_lacuna || $self->is_ph;
211 =head1 Convenience methods
213 =head2 related_readings
215 Calls Collation's related_readings with $self as the first argument.
219 sub related_readings {
221 return $self->collation->related_readings( $self, @_ );
226 Calls Collation's reading_witnesses with $self as the first argument.
232 return $self->collation->reading_witnesses( $self, @_ );
237 Returns a list of Reading objects that immediately precede $self in the collation.
243 my @pred = $self->collation->sequence->predecessors( $self->id );
244 return map { $self->collation->reading( $_ ) } @pred;
249 Returns a list of Reading objects that immediately follow $self in the collation.
255 my @succ = $self->collation->sequence->successors( $self->id );
256 return map { $self->collation->reading( $_ ) } @succ;
259 =head2 set_identical( $other_reading)
261 Backwards compatibility method, to add a transposition relationship
262 between $self and $other_reading. Don't use this.
267 my( $self, $other ) = @_;
268 return $self->collation->add_relationship( $self, $other,
269 { 'type' => 'transposition' } );
279 A few methods to try to tack on morphological information.
295 unless( $self->has_language ) {
296 warn "Please set a language to lemmatize a tradition";
299 my $mod = "Text::Tradition::Language::" . $self->language;
301 $mod->can( 'reading_lookup' )->( $self );
312 ## TODO will need a throw() here
315 __PACKAGE__->meta->make_immutable;