X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=stemmaweb%2Flib%2Fstemmaweb%2FController%2FStexaminer.pm;h=e556e320c4cdae5d5e16667ca742028a9275d137;hb=e41080b62247df50142675a091efb3b369d08f1d;hp=bdabcaa6cef34f42b98994f17389c81f56f805c6;hpb=5c9ecf6629514c0b83ccf41052f13f5f02e982f2;p=scpubgit%2Fstemmatology.git diff --git a/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm b/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm index bdabcaa..e556e32 100644 --- a/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm +++ b/stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm @@ -1,9 +1,12 @@ package stemmaweb::Controller::Stexaminer; use Moose; use namespace::autoclean; +use Encode qw/ decode_utf8 /; use File::Temp; use JSON; -use Text::Tradition::Analysis qw/ run_analysis /; +use Text::Tradition::Analysis qw/ run_analysis wit_stringify /; +use Text::Tradition::Collation; +use Text::Tradition::Stemma; BEGIN { extends 'Catalyst::Controller' } @@ -18,29 +21,79 @@ The stemma analysis tool with the pretty colored table. =head1 METHODS +=head2 index + GET stexaminer/$textid Renders the application for the text identified by $textid. -=head2 index - =cut sub index :Path :Args(1) { my( $self, $c, $textid ) = @_; my $m = $c->model('Directory'); my $tradition = $m->tradition( $textid ); - my $stemma = $tradition->stemma; - # TODO Think about caching the stemma in a session - $c->stash->{svg} = $stemma->as_svg; - $c->stash->{text_title} = $tradition->name; - $c->stash->{template} = 'stexaminer.tt'; - # TODO Run the analysis as AJAX from the loaded page. - my $t = run_analysis( $tradition ); - $c->stash->{variants} = $t->{'variants'}; - $c->stash->{total} = $t->{'variant_count'}; - $c->stash->{genealogical} = $t->{'genealogical_count'}; - $c->stash->{conflict} = $t->{'conflict_count'}; + if( $tradition->stemma_count ) { + my $stemma = $tradition->stemma(0); + $c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } ); + $c->stash->{graphdot} = $stemma->editable({ linesep => ' ' }); + $c->stash->{text_title} = $tradition->name; + $c->stash->{template} = 'stexaminer.tt'; + # TODO Run the analysis as AJAX from the loaded page. + my $t = run_analysis( $tradition, 'exclude_type1' => 1 ); + # Stringify the reading groups + foreach my $loc ( @{$t->{'variants'}} ) { + my $mst = wit_stringify( $loc->{'missing'} ); + $loc->{'missing'} = $mst; + foreach my $rhash ( @{$loc->{'readings'}} ) { + my $gst = wit_stringify( $rhash->{'group'} ); + $rhash->{'group'} = $gst; + my $roots = join( ', ', @{$rhash->{'independent_occurrence'}} ); + $rhash->{'independent_occurrence'} = $roots; + unless( $rhash->{'text'} ) { + $rhash->{'text'} = $rhash->{'readingid'}; + } + } + } + # Values for TT rendering + $c->stash->{variants} = $t->{'variants'}; + $c->stash->{total} = $t->{'variant_count'}; + $c->stash->{genealogical} = $t->{'genealogical_count'}; + $c->stash->{conflict} = $t->{'conflict_count'}; + # Also make a JSON stash of the data for the statistics tables + $c->stash->{reading_statistics} = to_json( $t->{'variants'} ); + } else { + $c->stash->{error} = 'Tradition ' . $tradition->name + . 'has no stemma for analysis.'; + } +} + +=head2 graphsvg + + POST stexaminer/graphsvg + dot: + layerwits: [ request->param('dot'); + my @layerwits = $c->request->param('layerwits[]'); + open my $stemma_fh, '<', \$dot; + binmode( $stemma_fh, ':encoding(UTF-8)' ); + my $emptycoll = Text::Tradition::Collation->new(); + my $tempstemma = Text::Tradition::Stemma->new( + collation => $emptycoll, 'dot' => $stemma_fh ); + my $svgopts = { size => [ 600, 350 ] }; + if( @layerwits ) { + $svgopts->{'layerwits'} = \@layerwits; + } + $c->stash->{'result'} = $tempstemma->as_svg( $svgopts ); + $c->forward('View::SVG'); } =head2 end