make the first couple of tests pass
[scpubgit/stemmatology.git] / lib / Text / Tradition.pm
CommitLineData
dd3b58b0 1package Text::Tradition;
2
3use Moose;
8e1394aa 4use Text::Tradition::Collation;
5use Text::Tradition::Witness;
dd3b58b0 6
7has 'collation' => (
8e1394aa 8 is => 'ro',
9 isa => 'Text::Tradition::Collation',
10 writer => '_save_collation',
11 );
dd3b58b0 12
13has 'witnesses' => (
8e1394aa 14 traits => ['Array'],
15 is => 'rw',
16 isa => 'ArrayRef[Text::Tradition::Witness]',
17 handles => {
18 all_options => 'elements',
19 add_option => 'push',
20 map_options => 'map',
21 option_count => 'count',
22 sorted_options => 'sort',
23 },
24 );
c5104dc0 25
8e1394aa 26sub BUILD {
27 my( $self, $init_args ) = @_;
28 print STDERR "Calling tradition build\n";
c5104dc0 29
8e1394aa 30 $DB::single = 1;
31 if( exists $init_args->{'witnesses'} ) {
c5104dc0 32 # We got passed an uncollated list of witnesses. Make a
33 # witness object for each witness, and then send them to the
34 # collator.
35 my $autosigil = 0;
8e1394aa 36 foreach my $wit ( %{$init_args->{'witnesses'}} ) {
c5104dc0 37 # Each item in the list is either a string or an arrayref.
38 # If it's a string, it is a filename; if it's an arrayref,
39 # it is a tuple of 'sigil, file'. Handle either case.
40 my $args;
41 if( ref( $wit ) eq 'ARRAY' ) {
42 $args = { 'sigil' => $wit->[0],
43 'file' => $wit->[1] };
44 } else {
45 $args = { 'sigil' => chr( $autosigil+65 ),
46 'file' => $wit };
47 $autosigil++;
48 }
8e1394aa 49 $self->witnesses->push( Text::Tradition::Witness->new( $args ) );
50 # TODO Now how to collate these?
c5104dc0 51 }
52 } else {
8e1394aa 53 # Else we got passed args intended for the collator.
54 $init_args->{'tradition'} = $self;
55 $self->_save_collation( Text::Tradition::Collation->new( %$init_args ) );
56 $self->witnesses( $self->collation->create_witnesses() );
c5104dc0 57 }
8e1394aa 58}
c5104dc0 59
dd3b58b0 60# The user will usually be instantiating a Tradition object, and
61# examining its collation. The information about the tradition can
62# come via several routes:
63# - graphML from CollateX or elsewhere, standalone
64# - TEI parallel segmentation
65# - Leuven-style spreadsheet of variants, converted to CSV, plus base text
66# - apparatus pulled from CTE, plus base text
67# From this we should be able to get basic witness information.
68#
69# Alternatively the user can just give us the uncollated texts. Then
70# instead of passing a collation, s/he is passing a set of witnesses
71# from which we will generate a collation. Those witnesses can be in
72# plaintext or in TEI with certain constraints adopted.
73
74# So the constructor for a tradition needs to take one of these infosets,
75# and construct the collation and the witness objects.
76
77no Moose;
78__PACKAGE__->meta->make_immutable;