1 package Text::Tradition;
5 use Text::Tradition::Collation;
6 use Text::Tradition::Witness;
10 isa => 'Text::Tradition::Collation',
11 writer => '_save_collation',
17 isa => 'ArrayRef[Text::Tradition::Witness]',
22 default => sub { [] },
26 my( $self, $init_args ) = @_;
28 if( exists $init_args->{'witnesses'} ) {
29 # We got passed an uncollated list of witnesses. Make a
30 # witness object for each witness, and then send them to the
33 foreach my $wit ( %{$init_args->{'witnesses'}} ) {
34 # Each item in the list is either a string or an arrayref.
35 # If it's a string, it is a filename; if it's an arrayref,
36 # it is a tuple of 'sigil, file'. Handle either case.
38 if( ref( $wit ) eq 'ARRAY' ) {
39 $args = { 'sigil' => $wit->[0],
40 'file' => $wit->[1] };
42 $args = { 'sigil' => chr( $autosigil+65 ),
46 $self->witnesses->push( Text::Tradition::Witness->new( $args ) );
47 # TODO Now how to collate these?
50 # Else we need to parse some collation data. Make a Collation object
51 my $collation = Text::Tradition::Collation->new( %$init_args,
52 'tradition' => $self );
53 $self->_save_collation( $collation );
55 # Call the appropriate parser on the given data
56 my @formats = grep { /^(GraphML|CSV|CTE|TEI)$/ } keys( %$init_args );
57 my $format = shift( @formats );
59 warn "No data given to create a collation; will initialize an empty one";
61 if( $format && $format =~ /^(CSV|CTE)$/ &&
62 !exists $init_args->{'base'} ) {
63 warn "Cannot make a collation from $format without a base text";
67 # Starting point for all texts
68 my $last_node = $collation->add_reading( '#START#' );
74 if( $format =~ /^(CSV|CTE)$/ ) {
75 $init_args->{'data'} = $init_args->{$format};
76 $init_args->{'format'} = $format;
78 @parseargs = %$init_args;
80 @parseargs = ( $init_args->{ $format } );
82 my $mod = "Text::Tradition::Parser::$format";
84 $mod->can('parse')->( $self, @parseargs );
90 my( $self, $sigil ) = @_;
92 foreach my $wit ( @{$self->witnesses} ) {
93 $requested_wit = $wit if $wit->sigil eq $sigil;
95 # We depend on an undef return value for no such witness.
96 # warn "No such witness $sigil" unless $requested_wit;
97 return $requested_wit;
103 my $new_wit = Text::Tradition::Witness->new( @_ );
104 push( @{$self->witnesses}, $new_wit );
108 # The user will usually be instantiating a Tradition object, and
109 # examining its collation. The information about the tradition can
110 # come via several routes:
111 # - graphML from CollateX or elsewhere, standalone
112 # - TEI parallel segmentation
113 # - Leuven-style spreadsheet of variants, converted to CSV, plus base text
114 # - apparatus pulled from CTE, plus base text
115 # From this we should be able to get basic witness information.
117 # Alternatively the user can just give us the uncollated texts. Then
118 # instead of passing a collation, s/he is passing a set of witnesses
119 # from which we will generate a collation. Those witnesses can be in
120 # plaintext or in TEI with certain constraints adopted.
122 # So the constructor for a tradition needs to take one of these infosets,
123 # and construct the collation and the witness objects.
126 __PACKAGE__->meta->make_immutable;