Commit | Line | Data |
5271a011 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use Test::More 'no_plan'; |
5 | $| = 1; |
6 | |
7 | |
8 | |
9 | # =begin testing |
10 | { |
11 | use Text::Tradition; |
12 | use_ok( 'Text::Tradition::Language::Latin' ); |
13 | |
307d8db9 |
14 | my $trad = Text::Tradition->new( |
15 | 'language' => 'Latin', |
16 | 'file' => 't/data/legendfrag.xml', |
17 | 'input' => 'Self' ); |
18 | |
f8862b58 |
19 | eval "use Lingua::Morph::Perseus"; |
5271a011 |
20 | my $err = $@; |
5271a011 |
21 | SKIP: { |
f8862b58 |
22 | skip "Package Lingua::Morph::Perseus not found" if $err; |
5271a011 |
23 | |
5271a011 |
24 | $trad->lemmatize(); |
25 | my $ambig = 0; |
26 | foreach my $r ( $trad->collation->readings ) { |
27 | next if $r->is_meta; |
28 | ok( $r->has_lexemes, "Reading $r has one or more lexemes" ); |
29 | my @lex = $r->lexemes; |
30 | my $lexstr = join( '', map { $_->string } @lex ); |
31 | my $textstr = $r->text; |
32 | $textstr =~ s/\s+//g; |
33 | is( $textstr, $lexstr, "Lexemes for reading $r match the reading" ); |
34 | foreach my $l ( @lex ) { |
fe77efe0 |
35 | next unless $l->matches; |
5271a011 |
36 | next if $l->is_disambiguated; |
37 | printf( "Ambiguous lexeme %s for reading %s:\n\t%s\n", $l->string, $r->id, |
38 | join( "\n\t", map { $_->lemma . ': ' . $_->morphology->to_string } $l->matching_forms ) ); |
39 | $ambig++; |
40 | } |
41 | } |
f8862b58 |
42 | is( $ambig, 4, "Found 4 ambiguous forms as expected" ); |
5271a011 |
43 | } |
307d8db9 |
44 | |
45 | # Try exporting some witnesses |
46 | my $e_v = 'in suetia uenerabilis pontifex beatus henricus in anglia oriundus'; |
47 | my $struct_v = $trad->witness('V')->export_as_json; |
48 | my $g_v = join( ' ', map { $_->{'n'} } @{$struct_v->{'tokens'}} ); |
49 | is( $g_v, $e_v, "Got expected regularization of witness V" ); |
50 | my $e_n = 'in suetia beatus henricus uenerabilis pontifex de anglia oriundus'; |
51 | my $struct_n = $trad->witness('N')->export_as_json; |
52 | my $g_n = join( ' ', map { $_->{'n'} } @{$struct_n->{'tokens'}} ); |
53 | is( $g_n, $e_n, "Got expected regularization of witness N" ); |
5271a011 |
54 | } |
55 | |
56 | |
57 | |
58 | |
59 | 1; |