1 package Text::Tradition::Collation::Reading;
6 use overload '""' => \&_stringify, 'fallback' => 1;
10 Text::Tradition::Collation::Reading - represents a reading (usually a word)
15 Text::Tradition is a library for representation and analysis of collated
16 texts, particularly medieval ones. A 'reading' refers to a unit of text,
17 usually a word, that appears in one or more witnesses (manuscripts) of the
18 tradition; the text of a given witness is composed of a set of readings in
25 Creates a new reading in the given collation with the given attributes.
30 =item collation - The Text::Tradition::Collation object to which this
31 reading belongs. Required.
33 =item id - A unique identifier for this reading. Required.
35 =item text - The word or other text of the reading.
37 =item is_start - The reading is the starting point for the collation.
39 =item is_end - The reading is the ending point for the collation.
41 =item is_lacuna - The 'reading' represents a known gap in the text.
43 =item is_ph - A temporary placeholder for apparatus parsing purposes. Do
44 not use unless you know what you are doing.
46 =item rank - The sequence number of the reading. This should probably not
51 One of 'text', 'is_start', 'is_end', or 'is_lacuna' is required.
67 Accessor methods for the given attributes.
73 isa => 'Text::Tradition::Collation',
88 writer => 'alter_text',
94 predicate => 'has_language',
130 predicate => 'has_rank',
131 clearer => 'clear_rank',
134 ## For morphological analysis
136 has 'normal_form' => (
139 predicate => 'has_normal_form',
142 # Holds the lexemes for the reading.
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 Methods for the morphological information (if any) attached to readings.
280 A reading may be made up of multiple lexemes; the concatenated lexeme
281 strings ought to match the reading's normalized form.
283 See L<Text::Tradition::Collation::Reading::Lexeme> for more information
284 on Lexeme objects and their attributes.
288 Returns a true value if the reading has any attached lexemes.
292 Returns the Lexeme objects (if any) attached to the reading.
296 Wipes any associated Lexeme objects out of the reading.
298 =head2 add_lexeme( $lexobj )
300 Adds the Lexeme in $lexobj to the list of lexemes.
304 If the language of the reading is set, this method will use the appropriate
305 Language model to determine the lexemes that belong to this reading. See
306 L<Text::Tradition::lemmatize> if you wish to lemmatize an entire tradition.
312 unless( $self->has_language ) {
313 warn "Please set a language to lemmatize a tradition";
316 my $mod = "Text::Tradition::Language::" . $self->language;
318 $mod->can( 'reading_lookup' )->( $self );
322 # For graph serialization. Return a string representation of the associated
324 sub _serialize_lexemes {
326 return Dump( [ $self->lexemes ] );
337 ## TODO will need a throw() here
340 __PACKAGE__->meta->make_immutable;