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 @format_standalone = qw/ Self CollateX CSV CTE TEI Tabular /;
71 my @format_basetext = qw/ KUL /;
73 my $format = $init_args->{'input'};
75 warn "No data given to create a collation; will initialize an empty one";
77 if( $format && !( grep { $_ eq $format } @format_standalone )
78 && !( grep { $_ eq $format } @format_basetext ) ) {
79 warn "Unrecognized input format $format; not parsing";
82 if( $format && grep { $_ eq $format } @format_basetext ) {
84 if( !exists $init_args->{'base'} ) {
85 warn "Cannot make a collation from $format without a base text";
93 $format = 'BaseText'; # Use the BaseText module for parsing,
94 # but retain the original input arg.
96 my $mod = "Text::Tradition::Parser::$format";
98 $mod->can('parse')->( $self, $init_args );
104 my( $self, $sigil ) = @_;
106 foreach my $wit ( $self->witnesses ) {
107 if( $wit->sigil eq $sigil ) {
108 $requested_wit = $wit;
112 # We depend on an undef return value for no such witness.
113 # warn "No such witness $sigil" unless $requested_wit;
114 return $requested_wit;
119 # The user will usually be instantiating a Tradition object, and
120 # examining its collation. The information about the tradition can
121 # come via several routes:
122 # - graphML from CollateX or elsewhere, standalone
123 # - TEI parallel segmentation
124 # - Leuven-style spreadsheet of variants, converted to CSV, plus base text
125 # - apparatus pulled from CTE, plus base text
126 # From this we should be able to get basic witness information.
128 # Alternatively the user can just give us the uncollated texts. Then
129 # instead of passing a collation, s/he is passing a set of witnesses
130 # from which we will generate a collation. Those witnesses can be in
131 # plaintext or in TEI with certain constraints adopted.
133 # So the constructor for a tradition needs to take one of these infosets,
134 # and construct the collation and the witness objects.
137 __PACKAGE__->meta->make_immutable;