From: Tara L Andrews Date: Mon, 27 Aug 2012 14:29:46 +0000 (+0200) Subject: make Analysis work with new async setup X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a745c3d934ce7e7aa4894e7f71cf2d48e5cd8478;p=scpubgit%2Fstemmatology.git make Analysis work with new async setup --- diff --git a/lib/Text/Tradition/Analysis.pm b/lib/Text/Tradition/Analysis.pm index b709bc8..89d011d 100644 --- a/lib/Text/Tradition/Analysis.pm +++ b/lib/Text/Tradition/Analysis.pm @@ -6,7 +6,7 @@ use Algorithm::Diff; # for word similarity measure 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; @@ -505,9 +505,10 @@ The answer has the form 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; } @@ -536,10 +537,9 @@ sub solve_variants { 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 @@ -909,6 +909,13 @@ sub wit_stringify { 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 diff --git a/t/analysis.t b/t/analysis.t index 63e5fb1..bc5661f 100755 --- a/t/analysis.t +++ b/t/analysis.t @@ -175,7 +175,7 @@ my %num_readings; 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'}} ) { @@ -194,6 +194,8 @@ 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; @@ -223,6 +225,8 @@ $analysis_opts{'exclude_type1'} = 1; @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'}} ) { @@ -248,6 +252,8 @@ $analysis_opts{'merge_types'} = [ qw/ orthographic spelling / ]; $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';