1 package Text::Tradition;
5 use Text::Tradition::Collation;
6 use Text::Tradition::Witness;
10 isa => 'Text::Tradition::Collation',
11 writer => '_save_collation',
16 isa => 'ArrayRef[Text::Tradition::Witness]',
18 witnesses => 'elements',
19 add_witness => 'push',
21 default => sub { [] },
27 default => 'Tradition',
30 around 'add_witness' => sub {
33 my $new_wit = Text::Tradition::Witness->new( @_ );
34 $self->$orig( $new_wit );
40 my( $self, $init_args ) = @_;
42 if( exists $init_args->{'witnesses'} ) {
43 # We got passed an uncollated list of witnesses. Make a
44 # witness object for each witness, and then send them to the
47 foreach my $wit ( %{$init_args->{'witnesses'}} ) {
48 # Each item in the list is either a string or an arrayref.
49 # If it's a string, it is a filename; if it's an arrayref,
50 # it is a tuple of 'sigil, file'. Handle either case.
52 if( ref( $wit ) eq 'ARRAY' ) {
53 $args = { 'sigil' => $wit->[0],
54 'file' => $wit->[1] };
56 $args = { 'sigil' => chr( $autosigil+65 ),
60 $self->witnesses->add_witness( $args );
61 # TODO Now how to collate these?
64 # Else we need to parse some collation data. Make a Collation object
65 my $collation = Text::Tradition::Collation->new( %$init_args,
66 'tradition' => $self );
67 $self->_save_collation( $collation );
69 # Call the appropriate parser on the given data
70 my @formats = grep { /^(Self|CollateX|CSV|CTE|KUL|TEI|Tabular)$/ } keys( %$init_args );
71 my $format = shift( @formats );
73 warn "No data given to create a collation; will initialize an empty one";
75 if( $format && $format =~ /^(KUL)$/ &&
76 !exists $init_args->{'base'} ) {
77 warn "Cannot make a collation from $format without a base text";
81 # Start and end points for all texts
82 $collation->add_reading( '#START#' );
83 $collation->add_reading( '#END#' );
90 if( $format =~ /^(KUL)$/ ) {
91 $init_args->{'data'} = $init_args->{$format};
92 $init_args->{'format'} = $format;
94 @parseargs = %$init_args;
96 @parseargs = ( $init_args->{ $format } );
98 my $mod = "Text::Tradition::Parser::$format";
100 $mod->can('parse')->( $self, @parseargs );
106 my( $self, $sigil ) = @_;
108 foreach my $wit ( $self->witnesses ) {
109 if( $wit->sigil eq $sigil ) {
110 $requested_wit = $wit;
114 # We depend on an undef return value for no such witness.
115 # warn "No such witness $sigil" unless $requested_wit;
116 return $requested_wit;
121 # The user will usually be instantiating a Tradition object, and
122 # examining its collation. The information about the tradition can
123 # come via several routes:
124 # - graphML from CollateX or elsewhere, standalone
125 # - TEI parallel segmentation
126 # - Leuven-style spreadsheet of variants, converted to CSV, plus base text
127 # - apparatus pulled from CTE, plus base text
128 # From this we should be able to get basic witness information.
130 # Alternatively the user can just give us the uncollated texts. Then
131 # instead of passing a collation, s/he is passing a set of witnesses
132 # from which we will generate a collation. Those witnesses can be in
133 # plaintext or in TEI with certain constraints adopted.
135 # So the constructor for a tradition needs to take one of these infosets,
136 # and construct the collation and the witness objects.
139 __PACKAGE__->meta->make_immutable;