Start fleshing out some of these classes
[scpubgit/stemmatology.git] / lib / Text / Tradition / Collation.pm
1 package Text::Tradition::Collation;
2 use Moose;
3
4 has 'graph' => (
5                 is => 'ro',
6                 isa => 'Graph::Easy',
7                 writer => '_init_graph',
8                 handles => {
9                     add_node => 'add_reading',
10                     del_node => 'del_reading',
11                     add_edge => 'add_path',
12                     del_edge => 'del_path',
13                     nodes => 'readings',
14                     edges => 'paths',
15                 );
16                 
17
18 # TODO do we not have a way to access the parent object?
19 has 'tradition' => (
20                     is => 'ro',
21                     isa => 'Text::Tradition',
22                     );
23
24 # The collation can be created two ways:
25 # 1. Collate a set of witnesses (with CollateX I guess) and process
26 #    the results as in 2.
27 # 2. Read a pre-prepared collation in one of a variety of formats,
28 #    and make the graph from that.
29
30 # The graph itself will (for now) be immutable, and the positions
31 # within the graph will also be immutable.  We need to calculate those
32 # positions upon graph construction.  The equivalences between graph
33 # nodes will be mutable, entirely determined by the user (or possibly
34 # by some semantic pre-processing provided by the user.)  So the
35 # constructor should just make an empty equivalences object.  The
36 # constructor will also need to make the witness objects, if we didn't
37 # come through option 1.
38
39 # TODO BUILDARGS
40
41 # Wrappers around some methods
42
43 sub merge_readings {
44     my $self = shift;
45     my $first_node = shift;
46     my $second_node = shift;
47     $first_node->merge_from( $second_node );
48     unshift( @_, $first_node, $second_node );
49     return $self->graph->merge_nodes( @_ );
50 }
51
52 no Moose;
53 __PACKAGE__->meta->make_immutable;