split off stemma analysis modules from base Tradition layer
[scpubgit/stemmatology.git] / analysis / t / text_tradition_analysis.t
CommitLineData
7f52eac8 1#!/usr/bin/perl -w
2
3use strict;
4use Test::More 'no_plan';
5$| = 1;
6
7
8
9# =begin testing
10{
11use Text::Tradition;
12use Text::Tradition::Analysis qw/ run_analysis analyze_variant_location /;
13
14my $datafile = 't/data/florilegium_tei_ps.xml';
15my $tradition = Text::Tradition->new( 'input' => 'TEI',
16 'name' => 'test0',
17 'file' => $datafile );
951ddfe8 18$tradition->enable_stemmata;
7f52eac8 19my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
20is( ref( $s ), 'Text::Tradition::Stemma', "Added stemma to tradition" );
21
f00cefe8 22my %expected_genealogical = (
a44aaf2a 23 1 => 0,
f00cefe8 24 2 => 1,
a44aaf2a 25 3 => 0,
26 5 => 0,
27 7 => 0,
28 8 => 0,
29 10 => 0,
f00cefe8 30 13 => 1,
a44aaf2a 31 33 => 0,
32 34 => 0,
33 37 => 0,
34 60 => 0,
f00cefe8 35 81 => 1,
a44aaf2a 36 84 => 0,
37 87 => 0,
38 101 => 0,
39 102 => 0,
f00cefe8 40 122 => 1,
a44aaf2a 41 157 => 0,
f00cefe8 42 166 => 1,
43 169 => 1,
a44aaf2a 44 200 => 0,
f00cefe8 45 216 => 1,
46 217 => 1,
47 219 => 1,
48 241 => 1,
49 242 => 1,
50 243 => 1,
51);
52
7e17346f 53my $data = run_analysis( $tradition, calcdsn => 'dbi:SQLite:dbname=t/data/analysis.db' );
7234b01d 54my $c = $tradition->collation;
f00cefe8 55foreach my $row ( @{$data->{'variants'}} ) {
a44aaf2a 56 # Account for rows that used to be "not useful"
57 unless( exists $expected_genealogical{$row->{'id'}} ) {
58 $expected_genealogical{$row->{'id'}} = 1;
59 }
18f48b82 60 my $gen_bool = $row->{'genealogical'} ? 1 : 0;
61 is( $gen_bool, $expected_genealogical{$row->{'id'}},
f00cefe8 62 "Got correct genealogical flag for row " . $row->{'id'} );
7234b01d 63 # Check that we have the right row with the right groups
64 my $rank = $row->{'id'};
65 foreach my $rdghash ( @{$row->{'readings'}} ) {
66 # Skip 'readings' that aren't really
67 next unless $c->reading( $rdghash->{'readingid'} );
68 # Check the rank
69 is( $c->reading( $rdghash->{'readingid'} )->rank, $rank,
70 "Got correct reading rank" );
71 # Check the witnesses
72 my @realwits = sort $c->reading_witnesses( $rdghash->{'readingid'} );
73 my @sgrp = sort @{$rdghash->{'group'}};
74 is_deeply( \@sgrp, \@realwits, "Reading analyzed with correct groups" );
75 }
f00cefe8 76}
a44aaf2a 77is( $data->{'variant_count'}, 58, "Got right total variant number" );
b4cb2d60 78# TODO Make something meaningful of conflict count, maybe test other bits
7f52eac8 79}
80
81
82
83
841;