Commit | Line | Data |
dd3b58b0 |
1 | package Text::Tradition::Witness; |
2 | use Moose; |
3 | |
784877d9 |
4 | # Sigil. Required identifier for a witness. |
dd3b58b0 |
5 | has 'sigil' => ( |
d047cd52 |
6 | is => 'ro', |
7 | isa => 'Str', |
8 | required => 1, |
9 | ); |
dd3b58b0 |
10 | |
d047cd52 |
11 | # Text. This is an array of strings (i.e. word tokens). |
12 | # TODO Think about how to handle this for the case of pre-prepared |
13 | # collations, where the tokens are in the graph already. |
dd3b58b0 |
14 | has 'text' => ( |
d047cd52 |
15 | is => 'rw', |
16 | isa => 'ArrayRef[Str]', |
17 | ); |
dd3b58b0 |
18 | |
d047cd52 |
19 | # Source. This is where we read in the witness, if not from a |
20 | # pre-prepared collation. It is probably a filename. |
21 | has 'source' => ( |
22 | is => 'ro', |
23 | isa => 'Str', |
24 | ); |
784877d9 |
25 | |
26 | sub BUILD { |
27 | my $self = shift; |
d047cd52 |
28 | if( $self->has_source ) { |
784877d9 |
29 | # Read the file and initialize the text. |
d047cd52 |
30 | open( WITNESS, $self->source ) or die "Could not open " |
784877d9 |
31 | . $self->file . "for reading"; |
32 | # TODO support TEI as well as plaintext, sometime |
33 | my @words; |
34 | while(<WITNESS>) { |
35 | chomp; |
36 | push( @words, split( /\s+/, $_ ) ); |
37 | } |
38 | close WITNESS; |
d047cd52 |
39 | $self->text( \@words ); |
784877d9 |
40 | } |
41 | } |
42 | |
dd3b58b0 |
43 | no Moose; |
44 | __PACKAGE__->meta->make_immutable; |