1 package Text::Tradition::Witness;
3 use Moose::Util::TypeConstraints;
7 => where { return 0 unless @$_ == 3;
8 return 0 unless $_->[0] =~ /^\d+$/;
9 return 0 unless $_->[1] =~ /^\d+$/;
10 foreach my $x ( @{$_->[2]} ) {
11 return $0 unless $x->isa( 'Text::Tradition::Collation::Reading' );
15 => message { "Correction must be ref of [ offset, length, replacement_list ]" };
18 # Sigil. Required identifier for a witness.
25 # Text. This is an array of strings (i.e. word tokens).
26 # TODO Think about how to handle this for the case of pre-prepared
27 # collations, where the tokens are in the graph already.
30 isa => 'ArrayRef[Str]',
31 predicate => 'has_text',
34 # Source. This is where we read in the witness, if not from a
35 # pre-prepared collation. It is probably a filename.
39 predicate => 'has_source',
42 # Path. This is an array of Reading nodes that should mirror the
46 isa => 'ArrayRef[Text::Tradition::Collation::Reading]',
47 predicate => 'has_path',
50 # Uncorrection. This is an array of sets of reading nodes that show
51 # where the witness was corrected.
52 has 'uncorrected' => (
54 isa => 'ArrayRef[Correction]',
55 predicate => 'has_uncorrected',
61 if( $self->has_source ) {
62 # Read the file and initialize the text.
63 open( WITNESS, $self->source ) or die "Could not open "
64 . $self->file . "for reading";
65 # TODO support TEI as well as plaintext, sometime
69 push( @words, split( /\s+/, $_ ) );
72 $self->text( \@words );
76 # If the text is not present, and the path is, and this is a 'get'
77 # request, generate text from path.
82 if( $self->has_path && !$self->has_text && !@_ ) {
83 my @words = map { $_->label } @{$self->path};
84 $self->$orig( \@words );
90 sub uncorrected_path {
93 push( @path, @{$self->path} );
94 foreach my $corr ( @{$self->uncorrected} ) {
95 splice( @path, $corr->[0], $corr->[1], @{$corr->[2]} );
101 __PACKAGE__->meta->make_immutable;