use strict;
use warnings;
-use Text::Tradition::Parser::GraphML;
+use Text::Tradition::Parser::GraphML qw/ graphml_parse populate_witness_path /;
=head1 NAME
Text::Tradition::Parser::CollateX
+=head1 SYNOPSIS
+
+ use Text::Tradition;
+
+ my $t_from_file = Text::Tradition->new(
+ 'name' => 'my text',
+ 'input' => 'CollateX',
+ 'file' => '/path/to/collation.xml'
+ );
+
+ my $t_from_string = Text::Tradition->new(
+ 'name' => 'my text',
+ 'input' => 'CollateX',
+ 'string' => $collation_xml,
+ );
+
=head1 DESCRIPTION
Parser module for Text::Tradition, given a GraphML file from the
=head1 METHODS
-=over
+=head2 B<parse>
+
+parse( $tradition, $init_options );
-=item B<parse>
+Takes an initialized Text::Tradition object and a set of options; creates
+the appropriate nodes and edges on the graph. The options hash should
+include either a 'file' argument or a 'string' argument, depending on the
+source of the XML to be parsed.
-parse( $graph, $graphml_string );
+=begin testing
-Takes an initialized Text::Tradition::Graph object and a string
-containing the GraphML; creates the appropriate nodes and edges on the
-graph.
+use Text::Tradition;
+binmode STDOUT, ":utf8";
+binmode STDERR, ":utf8";
+eval { no warnings; binmode $DB::OUT, ":utf8"; };
+
+my $cxfile = 't/data/Collatex-16.xml';
+my $t = Text::Tradition->new(
+ 'name' => 'inline',
+ 'input' => 'CollateX',
+ 'file' => $cxfile,
+ );
+
+is( ref( $t ), 'Text::Tradition', "Parsed our own GraphML" );
+if( $t ) {
+ is( scalar $t->collation->readings, 26, "Collation has all readings" );
+ is( scalar $t->collation->paths, 49, "Collation has all paths" );
+ is( scalar $t->witnesses, 3, "Collation has all witnesses" );
+
+ # Check an 'identical' node
+ my $transposed = $t->collation->reading( 'n15' );
+ ok( $transposed->has_primary, "Reading links to transposed primary" );
+ is( $transposed->primary->name, 'n17', "Correct transposition link" );
+}
+
+=end testing
=cut
my $TRANSKEY = 'identical';
sub parse {
- my( $tradition, $graphml_str ) = @_;
- my $graph_data = Text::Tradition::Parser::GraphML::parse( $graphml_str );
+ my( $tradition, $opts ) = @_;
+ my $graph_data = graphml_parse( $opts );
my $collation = $tradition->collation;
my %witnesses; # Keep track of the witnesses we encounter as we
# run through the graph data.
$collation->end( $gnode );
}
}
+
+ # Set the $witness->path arrays for each wit.
+ populate_witness_path( $tradition );
- # Record for each witness its sequence of readings, and determine
- # the common nodes.
- my @common_nodes = $collation->walk_witness_paths( $end_node );
-
- # Now we have added the witnesses and their paths, so have also
- # implicitly marked the common nodes. Now we can calculate their
- # explicit positions.
- $collation->calculate_positions( @common_nodes );
+ # Rank the readings.
+ $collation->calculate_ranks();
}
+=head1 BUGS / TODO
+
+=over
+
+=item * Make this into a stream parser with GraphML
+
+=item * Use CollateX-calculated ranks instead of recalculating our own
+
=back
=head1 LICENSE