Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Nils Diewald | 8e323ee | 2014-04-23 17:28:14 +0000 | [diff] [blame] | 2 | # source ~/perl5/perlbrew/etc/bashrc |
| 3 | # perlbrew switch perl-blead@korap |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 4 | use strict; |
| 5 | use warnings; |
| 6 | use utf8; |
| 7 | use Test::More; |
Nils Diewald | ff6d078 | 2014-06-10 18:26:36 +0000 | [diff] [blame] | 8 | use JSON::XS; |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 9 | use Benchmark ':hireswallclock'; |
| 10 | use lib 'lib', '../lib'; |
| 11 | |
Nils Diewald | 8e323ee | 2014-04-23 17:28:14 +0000 | [diff] [blame] | 12 | use File::Basename 'dirname'; |
| 13 | use File::Spec::Functions 'catdir'; |
| 14 | |
Akron | 8fa76bc | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 15 | use_ok('KorAP::XML::Krill'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 16 | |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 17 | sub _t2h { |
| 18 | my $string = shift; |
| 19 | $string =~ s/^\[\(\d+?-\d+?\)(.+?)\]$/$1/; |
| 20 | my %hash = (); |
| 21 | foreach (split(qr!\|!, $string)) { |
| 22 | $hash{$_} = 1; |
| 23 | }; |
| 24 | return \%hash; |
| 25 | }; |
| 26 | |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 27 | my @layers; |
| 28 | # push(@layers, ['Base', 'Sentences']); |
| 29 | push(@layers, ['Base', 'Paragraphs']); |
| 30 | |
| 31 | # OpenNLP |
| 32 | push(@layers, ['OpenNLP', 'Morpho']); |
| 33 | push(@layers, ['OpenNLP', 'Sentences']); |
| 34 | |
| 35 | # CoreNLP |
| 36 | push(@layers, ['CoreNLP', 'NamedEntities', 'ne_dewac_175m_600']); |
| 37 | push(@layers, ['CoreNLP', 'NamedEntities', 'ne_hgc_175m_600']); |
| 38 | push(@layers, ['CoreNLP', 'Sentences']); |
| 39 | |
| 40 | # Connexor |
| 41 | push(@layers, ['Connexor', 'Morpho']); |
| 42 | push(@layers, ['Connexor', 'Syntax']); |
| 43 | push(@layers, ['Connexor', 'Phrase']); |
| 44 | push(@layers, ['Connexor', 'Sentences']); |
| 45 | |
| 46 | # TreeTagger |
| 47 | push(@layers, ['TreeTagger', 'Morpho']); |
| 48 | push(@layers, ['TreeTagger', 'Sentences']); |
| 49 | |
| 50 | # Mate |
| 51 | # push(@layers, ['Mate', 'Morpho']); |
Akron | 627a80a | 2016-01-29 19:38:18 +0100 | [diff] [blame^] | 52 | # push(@layers, ['Mate', 'Dependency']); |
| 53 | diag 'Check for mate/d'; |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 54 | |
| 55 | # XIP |
| 56 | push(@layers, ['XIP', 'Morpho']); |
| 57 | push(@layers, ['XIP', 'Constituency']); |
| 58 | push(@layers, ['XIP', 'Dependency']); |
| 59 | push(@layers, ['XIP', 'Sentences']); |
| 60 | |
| 61 | |
Akron | 29fc6b7 | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 62 | my $path = catdir(dirname(__FILE__), 'corpus/WPD/00001'); |
Akron | 8fa76bc | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 63 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 64 | like($doc->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 65 | |
Akron | 8fa76bc | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 66 | ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document'); |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 67 | like($doc->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 68 | |
| 69 | ok($doc->parse, 'Parse document'); |
| 70 | |
| 71 | # Metdata |
| 72 | is($doc->title, 'A', 'title'); |
| 73 | ok(!$doc->sub_title, 'subTitle'); |
| 74 | |
Nils Diewald | 7ec5153 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 75 | is($doc->text_sigle, 'WPD_AAA.00001', 'ID'); |
| 76 | is($doc->corpus_sigle, 'WPD', 'corpusID'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 77 | is($doc->pub_date, '20050328', 'pubDate'); |
Nils Diewald | 8e323ee | 2014-04-23 17:28:14 +0000 | [diff] [blame] | 78 | is($doc->pub_place, 'URL:http://de.wikipedia.org', 'pubPlace'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 79 | is($doc->text_class->[0], 'freizeit-unterhaltung', 'TextClass'); |
| 80 | is($doc->text_class->[1], 'reisen', 'TextClass'); |
| 81 | is($doc->text_class->[2], 'wissenschaft', 'TextClass'); |
| 82 | is($doc->text_class->[3], 'populaerwissenschaft', 'TextClass'); |
| 83 | ok(!$doc->text_class->[4], 'TextClass'); |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 84 | is($doc->author, 'Ruru; Jens.Ol; Aglarech; u.a.', 'author'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 85 | |
| 86 | # Get tokens |
Akron | 8fa76bc | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 87 | use_ok('KorAP::XML::Tokenizer'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 88 | # Get tokenization |
Akron | 8fa76bc | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 89 | ok(my $tokens = KorAP::XML::Tokenizer->new( |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 90 | path => $doc->path, |
| 91 | doc => $doc, |
| 92 | foundry => 'OpenNLP', |
| 93 | layer => 'Tokens', |
| 94 | name => 'tokens' |
| 95 | ), 'New Tokenizer'); |
| 96 | ok($tokens->parse, 'Parse'); |
| 97 | |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 98 | like($tokens->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 99 | is($tokens->foundry, 'OpenNLP', 'Foundry'); |
Nils Diewald | 7ec5153 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 100 | is($tokens->doc->text_sigle, 'WPD_AAA.00001', 'Doc id'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 101 | is($tokens->should, 1068, 'Should'); |
| 102 | is($tokens->have, 923, 'Have'); |
| 103 | is($tokens->name, 'tokens', 'Name'); |
| 104 | is($tokens->layer, 'Tokens', 'Layer'); |
| 105 | |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 106 | |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 107 | is_deeply(_t2h($tokens->stream->pos(118)->to_string), |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 108 | _t2h('[(763-768)s:Linie|i:linie|_118$<i>763<i>768]'), |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 109 | 'Token is correct'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 110 | |
| 111 | # Add Mate |
| 112 | ok($tokens->add('Mate', 'Morpho'), 'Add Mate'); |
| 113 | |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 114 | |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 115 | is_deeply( |
| 116 | _t2h($tokens->stream->pos(118)->to_string), |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 117 | _t2h('[(763-768)s:Linie|i:linie|_118$<i>763<i>768|mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem]'), |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 118 | 'with Mate'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 119 | |
| 120 | # Add sentences |
| 121 | ok($tokens->add('Base', 'Sentences'), 'Add Sentences'); |
| 122 | |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 123 | is_deeply( |
| 124 | _t2h($tokens->stream->pos(0)->to_string), |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 125 | _t2h('[(0-1)s:A|i:a|_0$<i>0<i>1|-:tokens$<i>923|mate/p:XY|<>:base/s:s$<b>64<i>0<i>74<i>13<b>2|<>:base/s:t$<b>64<i>0<i>6083<i>923<b>0|-:base/sentences$<i>96]'), |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 126 | 'Startinfo' |
| 127 | ); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 128 | |
| 129 | foreach (@layers) { |
| 130 | ok($tokens->add(@$_), 'Add '. join(', ', @$_)); |
| 131 | }; |
| 132 | |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 133 | my $s = |
| 134 | '[(0-1)s:A|i:a|_0$<i>0<i>1|'. |
| 135 | '-:tokens$<i>923|'. |
| 136 | 'mate/p:XY|'. |
| 137 | '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2|'. |
| 138 | '<>:base/s:t$<b>64<i>0<i>6083<i>923<b>0|'. |
| 139 | '-:base/sentences$<i>96|'. |
| 140 | '<>:base/s:p$<b>64<i>0<i>224<i>34<b>1|'. |
| 141 | '-:base/paragraphs$<i>76|'. |
| 142 | 'opennlp/p:NE|' . |
| 143 | '<>:opennlp/s:s$<b>64<i>0<i>74<i>13<b>0|'. |
| 144 | '-:opennlp/sentences$<i>50|'. |
| 145 | '<>:corenlp/s:s$<b>64<i>0<i>6<i>2<b>0|'. |
| 146 | '-:corenlp/sentences$<i>68|'. |
| 147 | 'cnx/l:A|'. |
| 148 | 'cnx/p:N|'. |
| 149 | 'cnx/syn:@NH|'. |
| 150 | '<>:cnx/c:np$<b>64<i>0<i>1<i>1<b>0|'. |
| 151 | '<>:cnx/s:s$<b>64<i>0<i>74<i>13<b>0|'. |
| 152 | '-:cnx/sentences$<i>63|'. |
| 153 | 'tt/l:A$<b>129<b>199|'. |
| 154 | 'tt/p:NN$<b>129<b>199|'. |
| 155 | 'tt/l:A$<b>129<b>54|'. |
| 156 | 'tt/p:FM$<b>129<b>54|'. |
| 157 | '<>:tt/s:s$<b>64<i>0<i>6083<i>923<b>0|'. |
| 158 | '-:tt/sentences$<i>1|'. |
Akron | 627a80a | 2016-01-29 19:38:18 +0100 | [diff] [blame^] | 159 | # '>:mate/d:PNC$<i>2|'. |
Akron | a686fa3 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 160 | 'xip/p:SYMBOL|'. |
| 161 | 'xip/l:A|'. |
| 162 | '<>:xip/c:TOP$<b>64<i>0<i>74<i>13<b>0|'. |
| 163 | '<>:xip/c:MC$<b>64<i>0<i>73<i>13<b>1|'. |
| 164 | '<>:xip/c:NP$<b>64<i>0<i>1<i>1<b>2|'. |
| 165 | '<>:xip/c:NPA$<b>64<i>0<i>1<i>1<b>3|'. |
| 166 | '<>:xip/c:NOUN$<b>64<i>0<i>1<i>1<b>4|'. |
| 167 | '<>:xip/c:SYMBOL$<b>64<i>0<i>1<i>1<b>5|'. |
| 168 | '>:xip/d:SUBJ$<i>3|'. |
| 169 | '<:xip/d:COORD$<i>1|'. |
| 170 | '<>:xip/s:s$<b>64<i>0<i>74<i>13<b>0|'. |
| 171 | '-:xip/sentences$<i>65]'; |
| 172 | |
| 173 | { |
| 174 | local $SIG{__WARN__} = sub {}; |
| 175 | is_deeply( |
| 176 | _t2h($tokens->stream->pos(0)->to_string), |
| 177 | _t2h($s), |
| 178 | 'Startinfo'); |
| 179 | }; |
Nils Diewald | 1920571 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 180 | |
Akron | 29fc6b7 | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 181 | is($tokens->layer_info, |
Akron | 627a80a | 2016-01-29 19:38:18 +0100 | [diff] [blame^] | 182 | 'base/s=spans cnx/c=spans cnx/l=tokens cnx/m=tokens cnx/p=tokens cnx/s=spans cnx/syn=tokens corenlp/ne=tokens corenlp/s=spans mate/l=tokens mate/m=tokens mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans xip/c=spans xip/d=rels xip/l=tokens xip/p=tokens xip/s=spans', 'Layer info'); # mate/d=rels |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 183 | |
Akron | 627a80a | 2016-01-29 19:38:18 +0100 | [diff] [blame^] | 184 | is($tokens->support, 'base base/paragraphs base/sentences connexor connexor/morpho connexor/phrase connexor/sentences connexor/syntax corenlp corenlp/namedentities corenlp/namedentities corenlp/namedentities/ne_dewac_175m_600 corenlp/namedentities/ne_hgc_175m_600 corenlp/sentences mate mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/dependency xip/morpho xip/sentences', 'Support'); # mate/dependency |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 185 | |
| 186 | done_testing; |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 187 | __END__ |