From: tla Date: Thu, 7 Nov 2013 19:46:44 +0000 (+0100) Subject: associate Stemweb-generated stemmata with their job ID; return them on create. Needed... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=738620c7bd9343ed2ca4059ad477e1ee39f18e8e;p=scpubgit%2Fstemmatology.git associate Stemweb-generated stemmata with their job ID; return them on create. Needed for tla/stemmaweb#29 --- diff --git a/analysis/lib/Text/Tradition/HasStemma.pm b/analysis/lib/Text/Tradition/HasStemma.pm index 68e04f5..1a31c07 100644 --- a/analysis/lib/Text/Tradition/HasStemma.pm +++ b/analysis/lib/Text/Tradition/HasStemma.pm @@ -130,7 +130,7 @@ sub add_stemma { =head2 record_stemweb_result( $format, $data ) Records the result returned by a Stemweb calculation, and clears any -existing job ID. +existing job ID. Returns any new stemmata that were created. =begin testing @@ -147,11 +147,14 @@ my $t = Text::Tradition->new( is( $t->stemma_count, 0, "No stemmas added yet" ); my $answer = from_json( '{"status": 0, "job_id": "4", "algorithm": "RHM", "format": "newick", "start_time": "2013-10-26 10:44:14.050263", "result": "((((((((((((F,U),V),S),T1),T2),A),J),B),L),D),M),C);\n", "end_time": "2013-10-26 10:45:55.398944"}' ); -$t->record_stemweb_result( $answer ); +my $newst = $t->record_stemweb_result( $answer ); +is( scalar @$newst, 1, "New stemma was returned from record_stemweb_result" ); +is( $newst->[0], $t->stemma(0), "Answer has the right object" ); ok( !$t->has_stemweb_jobid, "Job ID was removed from tradition" ); is( $t->stemma_count, 1, "Tradition has new stemma" ); ok( $t->stemma(0)->is_undirected, "New stemma is undirected as it should be" ); is( $t->stemma(0)->identifier, "RHM 1382777054_0", "Stemma has correct identifier" ); +is( $t->stemma(0)->from_jobid, 4, "New stemma has correct associated job ID" ); =end testing @@ -160,22 +163,26 @@ is( $t->stemma(0)->identifier, "RHM 1382777054_0", "Stemma has correct identifie sub record_stemweb_result { my( $self, $answer ) = @_; + my $jobid = $self->stemweb_jobid; + my $stemmata = []; if( $answer->{format} eq 'dot' ) { $self->add_stemma( dot => $answer->{result} ); } elsif( $answer->{format} eq 'newick' ) { - my $stemmata = parse_newick( $answer->{result} ); + $stemmata = parse_newick( $answer->{result} ); my $title = sprintf( "%s %d", $answer->{algorithm}, str2time( $answer->{start_time} ) ); my $i = 0; foreach my $stemma ( @$stemmata ) { my $ititle = $title . "_$i"; $i++; $stemma->set_identifier( $ititle ); + $stemma->_set_from_jobid( $jobid ); $self->_add_stemma( $stemma ); } } else { $self->throw( "Cannot parse tree results with format " . $answer->{format} ); } $self->_clear_stemweb_jobid(); + return $stemmata; } 1; diff --git a/analysis/lib/Text/Tradition/Stemma.pm b/analysis/lib/Text/Tradition/Stemma.pm index 8d75edb..a5d75a7 100644 --- a/analysis/lib/Text/Tradition/Stemma.pm +++ b/analysis/lib/Text/Tradition/Stemma.pm @@ -161,6 +161,13 @@ has identifier => ( writer => 'set_identifier', predicate => 'has_identifier', ); + +has from_jobid => ( + is => 'ro', + isa => 'Str', + predicate => 'came_from_jobid', + writer => '_set_from_jobid', + ); sub BUILD { my( $self, $args ) = @_; diff --git a/analysis/t/text_tradition_hasstemma.t b/analysis/t/text_tradition_hasstemma.t index 66fc675..910f7f8 100644 --- a/analysis/t/text_tradition_hasstemma.t +++ b/analysis/t/text_tradition_hasstemma.t @@ -40,11 +40,14 @@ my $t = Text::Tradition->new( is( $t->stemma_count, 0, "No stemmas added yet" ); my $answer = from_json( '{"status": 0, "job_id": "4", "algorithm": "RHM", "format": "newick", "start_time": "2013-10-26 10:44:14.050263", "result": "((((((((((((F,U),V),S),T1),T2),A),J),B),L),D),M),C);\n", "end_time": "2013-10-26 10:45:55.398944"}' ); -$t->record_stemweb_result( $answer ); +my $newst = $t->record_stemweb_result( $answer ); +is( scalar @$newst, 1, "New stemma was returned from record_stemweb_result" ); +is( $newst->[0], $t->stemma(0), "Answer has the right object" ); ok( !$t->has_stemweb_jobid, "Job ID was removed from tradition" ); is( $t->stemma_count, 1, "Tradition has new stemma" ); ok( $t->stemma(0)->is_undirected, "New stemma is undirected as it should be" ); is( $t->stemma(0)->identifier, "RHM 1382777054_0", "Stemma has correct identifier" ); +is( $t->stemma(0)->from_jobid, 4, "New stemma has correct associated job ID" ); }