1 package Text::Tradition::Collation::Reading;
4 use overload '""' => \&_stringify, 'fallback' => 1;
8 Text::Tradition::Collation::Reading - represents a reading (usually a word) in a collation.
12 Text::Tradition is a library for representation and analysis of collated
13 texts, particularly medieval ones. A 'reading' refers to a unit of text,
14 usually a word, that appears in one or more witnesses (manuscripts) of the
15 tradition; the text of a given witness is composed of a set of readings in
22 Creates a new reading in the given collation with the given attributes.
27 =item collation - The Text::Tradition::Collation object to which this reading belongs. Required.
29 =item id - A unique identifier for this reading. Required.
31 =item text - The word or other text of the reading.
33 =item is_start - The reading is the starting point for the collation.
35 =item is_end - The reading is the ending point for the collation.
37 =item is_lacuna - The 'reading' represents a known gap in the text.
39 =item is_ph - A temporary placeholder for apparatus parsing purposes. Do not use unless you know what you are doing.
41 =item rank - The sequence number of the reading. This should probably not be set manually.
45 One of 'text', 'is_start', 'is_end', or 'is_lacuna' is required.
61 Accessor methods for the given attributes.
67 isa => 'Text::Tradition::Collation',
82 writer => 'alter_text',
118 predicate => 'has_rank',
119 clearer => 'clear_rank',
122 ## For morphological analysis
124 has 'normal_form' => (
127 predicate => 'has_normal_form',
133 predicate => 'has_lemma',
136 has 'morphology' => (
139 predicate => 'has_morphology',
142 has 'morph_possibilities' => (
144 isa => 'HashRef[Str]',
145 default => sub { {} },
148 ## For prefix/suffix readings
150 has 'join_prior' => (
163 around BUILDARGS => sub {
173 # If one of our special booleans is set, we change the text and the
175 if( exists $args->{'is_lacuna'} && !exists $args->{'text'} ) {
176 $args->{'text'} = '#LACUNA#';
177 } elsif( exists $args->{'is_start'} ) {
178 $args->{'id'} = '#START#'; # Change the ID to ensure we have only one
179 $args->{'text'} = '#START#';
181 } elsif( exists $args->{'is_end'} ) {
182 $args->{'id'} = '#END#'; # Change the ID to ensure we have only one
183 $args->{'text'} = '#END#';
184 } elsif( exists $args->{'is_ph'} ) {
185 $args->{'text'} = $args->{'id'};
188 $class->$orig( $args );
193 A meta attribute (ha ha), which should be true if any of our 'special'
194 booleans are true. Implies that the reading does not represent a bit
195 of text found in a witness.
201 return $self->is_start || $self->is_end || $self->is_lacuna || $self->is_ph;
204 =head1 Convenience methods
206 =head2 related_readings
208 Calls Collation's related_readings with $self as the first argument.
212 sub related_readings {
214 return $self->collation->related_readings( $self, @_ );
219 Calls Collation's reading_witnesses with $self as the first argument.
225 return $self->collation->reading_witnesses( $self, @_ );
230 Returns a list of Reading objects that immediately precede $self in the collation.
236 my @pred = $self->collation->sequence->predecessors( $self->id );
237 return map { $self->collation->reading( $_ ) } @pred;
242 Returns a list of Reading objects that immediately follow $self in the collation.
248 my @succ = $self->collation->sequence->successors( $self->id );
249 return map { $self->collation->reading( $_ ) } @succ;
252 =head2 set_identical( $other_reading)
254 Backwards compatibility method, to add a transposition relationship
255 between $self and $other_reading. Don't use this.
260 my( $self, $other ) = @_;
261 return $self->collation->add_relationship( $self, $other,
262 { 'type' => 'transposition' } );
276 __PACKAGE__->meta->make_immutable;