refactored Analysis module with associated changes
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation / Reading.pm
index 7c0daa9..d1c69f7 100644 (file)
@@ -82,22 +82,6 @@ has 'text' => (
        writer => 'alter_text',
        );
        
-has 'punctuation' => (
-       traits => ['Array'],
-       isa => 'ArrayRef[HashRef[Str]]',
-       default => sub { [] },
-       handles => {
-                       punctuation => 'elements',
-                       add_punctuation => 'push',
-                       },
-       );
-
-has 'separate_punctuation' => (
-       is => 'ro',
-       isa => 'Bool',
-       default => 1,
-       );
-
 has 'is_start' => (
        is => 'ro',
        isa => 'Bool',
@@ -121,6 +105,12 @@ has 'is_ph' => (
        isa => 'Bool',
        default => undef,
        );
+       
+has 'is_common' => (
+       is => 'rw',
+       isa => 'Bool',
+       default => undef,
+       );
 
 has 'rank' => (
     is => 'rw',
@@ -138,12 +128,11 @@ around BUILDARGS => sub {
        } else {
                $args = { @_ };
        }
-       
+                       
        # If one of our special booleans is set, we change the text and the
        # ID to match.
-       
        if( exists $args->{'is_lacuna'} && !exists $args->{'text'} ) {
-               $args->{'text'} = sprintf( "#LACUNA_%s#", $args->{'id'} );
+               $args->{'text'} = '#LACUNA#';
        } elsif( exists $args->{'is_start'} ) {
                $args->{'id'} = '#START#';  # Change the ID to ensure we have only one
                $args->{'text'} = '#START#';
@@ -158,33 +147,6 @@ around BUILDARGS => sub {
        $class->$orig( $args );
 };
 
-# Post-process the given text, stripping punctuation if we are asked.
-sub BUILD {
-       my $self = shift;
-       if( $self->separate_punctuation && !$self->is_meta ) {
-               my $pos = 0;
-               my $wspunct = '';  # word sans punctuation
-               foreach my $char ( split( //, $self->text ) ) {
-                       if( $char =~ /^[[:punct:]]$/ ) {
-                               $self->add_punctuation( { 'char' => $char, 'pos' => $pos } );
-                       } else {
-                               $wspunct .= $char;
-                       }
-                       $pos++;
-               }
-               $self->alter_text( $wspunct );
-       }
-}
-
-sub punctuated_form {
-       my $self = shift;
-       my $word = $self->text;
-       foreach my $p ( sort { $a->{pos} <=> $b->{pos} } $self->punctuation ) {
-               substr( $word, $p->{pos}, 0, $p->{char} );
-       }
-       return $word;
-}
-
 =head2 is_meta
 
 A meta attribute (ha ha), which should be true if any of our 'special'
@@ -198,24 +160,61 @@ sub is_meta {
        return $self->is_start || $self->is_end || $self->is_lacuna || $self->is_ph;    
 }
 
-# Some syntactic sugar
+=head1 Convenience methods
+
+=head2 related_readings
+
+Calls Collation's related_readings with $self as the first argument.
+
+=cut
+
 sub related_readings {
        my $self = shift;
        return $self->collation->related_readings( $self, @_ );
 }
 
+=head2 witnesses 
+
+Calls Collation's reading_witnesses with $self as the first argument.
+
+=cut
+
+sub witnesses {
+       my $self = shift;
+       return $self->collation->reading_witnesses( $self, @_ );
+}
+
+=head2 predecessors
+
+Returns a list of Reading objects that immediately precede $self in the collation.
+
+=cut
+
 sub predecessors {
        my $self = shift;
        my @pred = $self->collation->sequence->predecessors( $self->id );
        return map { $self->collation->reading( $_ ) } @pred;
 }
 
+=head2 successors
+
+Returns a list of Reading objects that immediately follow $self in the collation.
+
+=cut
+
 sub successors {
        my $self = shift;
        my @succ = $self->collation->sequence->successors( $self->id );
        return map { $self->collation->reading( $_ ) } @succ;
 }
 
+=head2 set_identical( $other_reading)
+
+Backwards compatibility method, to add a transposition relationship
+between $self and $other_reading.  Don't use this.
+
+=cut
+
 sub set_identical {
        my( $self, $other ) = @_;
        return $self->collation->add_relationship( $self, $other,