use Encode qw/ decode_utf8 encode_utf8 /;
use Exporter 'import';
use Graph;
-use JSON qw/ to_json /;
+use JSON qw/ to_json decode_json /;
use LWP::UserAgent;
use Set::Scalar;
use Text::Tradition::Analysis::Result;
sub solve_variants {
my( @groups ) = @_;
- # Are we using a local result directory?
+ # Are we using a local result directory, or did we pass an empty value
+ # for the directory?
my $dir;
- if( ref( $groups[0] ) eq 'Text::Tradition::Directory' ) {
+ unless( ref( $groups[0] ) eq 'HASH' ) {
$dir = shift @groups;
}
my $ua = LWP::UserAgent->new();
my $resp = $ua->post( $SOLVER_URL, 'Content-Type' => 'application/json',
'Content' => $json );
- my $answer;
+ my $answer;
if( $resp->is_success ) {
- $answer = Text::Tradition::Analysis::Result->new(
- decode_json( $resp->content ) );
+ $answer = decode_json( $resp->content );
throw( "Unexpected answer from IDP: $answer" ) unless ref( $answer ) eq 'ARRAY';
} else {
throw( "IDP solver returned " . $resp->status_line . " / " . $resp->content
1;
+sub throw {
+ Text::Tradition::Error->throw(
+ 'ident' => 'Analysis error',
+ 'message' => $_[0],
+ );
+}
+
=head1 LICENSE
This package is free software and is provided "as is" without express
my @all_variant_ranks = sort { $a <=> $b } keys( %expected );
# Look through the results
my $c = $tradition->collation;
-my %analysis_opts = ( calcdsn => $calcdsn );
+my %analysis_opts;
my $results = run_analysis( $tradition, %analysis_opts );
my @analyzed;
foreach my $row ( @{$results->{'variants'}} ) {
# every reading should independently occur exactly once, and the total
# number of changes + maybe-changes should equal the total number of
# readings who have that one as a parent.
+ ok( !exists $row->{'unsolved'}, "Got a solution for the stated problem" );
+ next if exists $row->{'unsolved'};
if( $row->{'genealogical'} ) {
# Make the mapping of parent -> child readings
my %is_parent;
@analyzed = ();
$results = run_analysis( $tradition, %analysis_opts );
foreach my $row ( @{$results->{'variants'}} ) {
+ ok( !exists $row->{'unsolved'}, "Got a solution for the stated problem" );
+ next if exists $row->{'unsolved'};
push( @analyzed, $row->{id} );
my $type = 'genealogical';
if( grep { $_->{'is_conflict'} } @{$row->{'readings'}} ) {
$results = run_analysis( $tradition, %analysis_opts );
foreach my $row ( @{$results->{'variants'}} ) {
push( @analyzed, $row->{id} );
+ ok( !exists $row->{'unsolved'}, "Got a solution for the stated problem" );
+ next if exists $row->{'unsolved'};
my $type = 'genealogical';
if( grep { $_->{'is_conflict'} } @{$row->{'readings'}} ) {
$type = 'conflict';