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 | e4c2e41 | 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 | feccbb1 | 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; |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame^] | 28 | push(@layers, ['Base', 'Sentences']); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 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']); |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame^] | 38 | push(@layers, ['CoreNLP', 'NamedEntities']); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 39 | push(@layers, ['CoreNLP', 'Sentences']); |
| 40 | |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame^] | 41 | push(@layers, ['DeReKo', 'Structure']); |
| 42 | |
| 43 | push(@layers, ['Glemm', 'Morpho']); |
| 44 | |
| 45 | push(@layers, ['Mate', 'Morpho']); |
| 46 | push(@layers, ['Mate', 'Dependency']); |
| 47 | |
| 48 | push(@layers, ['Malt', 'Dependency']); |
| 49 | |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 50 | # Connexor |
| 51 | push(@layers, ['Connexor', 'Morpho']); |
| 52 | push(@layers, ['Connexor', 'Syntax']); |
| 53 | push(@layers, ['Connexor', 'Phrase']); |
| 54 | push(@layers, ['Connexor', 'Sentences']); |
| 55 | |
| 56 | # TreeTagger |
| 57 | push(@layers, ['TreeTagger', 'Morpho']); |
| 58 | push(@layers, ['TreeTagger', 'Sentences']); |
| 59 | |
| 60 | # Mate |
Akron | 93d620e | 2016-02-05 19:40:05 +0100 | [diff] [blame^] | 61 | push(@layers, ['Mate', 'Morpho']); |
Akron | e19aa14 | 2016-02-01 14:38:40 +0100 | [diff] [blame] | 62 | push(@layers, ['Mate', 'Dependency']); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 63 | |
| 64 | # XIP |
| 65 | push(@layers, ['XIP', 'Morpho']); |
| 66 | push(@layers, ['XIP', 'Constituency']); |
| 67 | push(@layers, ['XIP', 'Dependency']); |
| 68 | push(@layers, ['XIP', 'Sentences']); |
| 69 | |
| 70 | |
Akron | 9c0488f | 2016-01-28 14:17:15 +0100 | [diff] [blame] | 71 | my $path = catdir(dirname(__FILE__), 'corpus/WPD/00001'); |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 72 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 73 | like($doc->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 74 | |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 75 | ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document'); |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 76 | like($doc->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 77 | |
| 78 | ok($doc->parse, 'Parse document'); |
| 79 | |
| 80 | # Metdata |
| 81 | is($doc->title, 'A', 'title'); |
| 82 | ok(!$doc->sub_title, 'subTitle'); |
| 83 | |
Nils Diewald | 840c924 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 84 | is($doc->text_sigle, 'WPD_AAA.00001', 'ID'); |
| 85 | is($doc->corpus_sigle, 'WPD', 'corpusID'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 86 | is($doc->pub_date, '20050328', 'pubDate'); |
Nils Diewald | 8e323ee | 2014-04-23 17:28:14 +0000 | [diff] [blame] | 87 | is($doc->pub_place, 'URL:http://de.wikipedia.org', 'pubPlace'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 88 | is($doc->text_class->[0], 'freizeit-unterhaltung', 'TextClass'); |
| 89 | is($doc->text_class->[1], 'reisen', 'TextClass'); |
| 90 | is($doc->text_class->[2], 'wissenschaft', 'TextClass'); |
| 91 | is($doc->text_class->[3], 'populaerwissenschaft', 'TextClass'); |
| 92 | ok(!$doc->text_class->[4], 'TextClass'); |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 93 | is($doc->author, 'Ruru; Jens.Ol; Aglarech; u.a.', 'author'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 94 | |
| 95 | # Get tokens |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 96 | use_ok('KorAP::XML::Tokenizer'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 97 | # Get tokenization |
Akron | e4c2e41 | 2016-01-28 15:10:50 +0100 | [diff] [blame] | 98 | ok(my $tokens = KorAP::XML::Tokenizer->new( |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 99 | path => $doc->path, |
| 100 | doc => $doc, |
| 101 | foundry => 'OpenNLP', |
| 102 | layer => 'Tokens', |
| 103 | name => 'tokens' |
| 104 | ), 'New Tokenizer'); |
| 105 | ok($tokens->parse, 'Parse'); |
| 106 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 107 | like($tokens->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 108 | is($tokens->foundry, 'OpenNLP', 'Foundry'); |
Nils Diewald | 840c924 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 109 | is($tokens->doc->text_sigle, 'WPD_AAA.00001', 'Doc id'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 110 | is($tokens->should, 1068, 'Should'); |
| 111 | is($tokens->have, 923, 'Have'); |
| 112 | is($tokens->name, 'tokens', 'Name'); |
| 113 | is($tokens->layer, 'Tokens', 'Layer'); |
| 114 | |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 115 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 116 | is_deeply(_t2h($tokens->stream->pos(118)->to_string), |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 117 | _t2h('[(763-768)s:Linie|i:linie|_118$<i>763<i>768]'), |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 118 | 'Token is correct'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 119 | |
| 120 | # Add Mate |
| 121 | ok($tokens->add('Mate', 'Morpho'), 'Add Mate'); |
| 122 | |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 123 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 124 | is_deeply( |
| 125 | _t2h($tokens->stream->pos(118)->to_string), |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 126 | _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 | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 127 | 'with Mate'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 128 | |
| 129 | # Add sentences |
| 130 | ok($tokens->add('Base', 'Sentences'), 'Add Sentences'); |
| 131 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 132 | is_deeply( |
| 133 | _t2h($tokens->stream->pos(0)->to_string), |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 134 | _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 | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 135 | 'Startinfo' |
| 136 | ); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 137 | |
| 138 | foreach (@layers) { |
| 139 | ok($tokens->add(@$_), 'Add '. join(', ', @$_)); |
| 140 | }; |
| 141 | |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 142 | my $s = |
| 143 | '[(0-1)s:A|i:a|_0$<i>0<i>1|'. |
| 144 | '-:tokens$<i>923|'. |
| 145 | 'mate/p:XY|'. |
| 146 | '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2|'. |
| 147 | '<>:base/s:t$<b>64<i>0<i>6083<i>923<b>0|'. |
| 148 | '-:base/sentences$<i>96|'. |
| 149 | '<>:base/s:p$<b>64<i>0<i>224<i>34<b>1|'. |
| 150 | '-:base/paragraphs$<i>76|'. |
| 151 | 'opennlp/p:NE|' . |
| 152 | '<>:opennlp/s:s$<b>64<i>0<i>74<i>13<b>0|'. |
| 153 | '-:opennlp/sentences$<i>50|'. |
| 154 | '<>:corenlp/s:s$<b>64<i>0<i>6<i>2<b>0|'. |
| 155 | '-:corenlp/sentences$<i>68|'. |
| 156 | 'cnx/l:A|'. |
| 157 | 'cnx/p:N|'. |
| 158 | 'cnx/syn:@NH|'. |
| 159 | '<>:cnx/c:np$<b>64<i>0<i>1<i>1<b>0|'. |
| 160 | '<>:cnx/s:s$<b>64<i>0<i>74<i>13<b>0|'. |
| 161 | '-:cnx/sentences$<i>63|'. |
| 162 | 'tt/l:A$<b>129<b>199|'. |
| 163 | 'tt/p:NN$<b>129<b>199|'. |
| 164 | 'tt/l:A$<b>129<b>54|'. |
| 165 | 'tt/p:FM$<b>129<b>54|'. |
| 166 | '<>:tt/s:s$<b>64<i>0<i>6083<i>923<b>0|'. |
| 167 | '-:tt/sentences$<i>1|'. |
Akron | e19aa14 | 2016-02-01 14:38:40 +0100 | [diff] [blame] | 168 | '>:mate/d:PNC$<b>32<i>2<s>1<s>1|'. |
| 169 | 'mate/d:NODE$<b>128<s>1|'. |
Akron | 0e924c4 | 2016-01-28 00:20:04 +0100 | [diff] [blame] | 170 | 'xip/p:SYMBOL|'. |
| 171 | 'xip/l:A|'. |
| 172 | '<>:xip/c:TOP$<b>64<i>0<i>74<i>13<b>0|'. |
| 173 | '<>:xip/c:MC$<b>64<i>0<i>73<i>13<b>1|'. |
| 174 | '<>:xip/c:NP$<b>64<i>0<i>1<i>1<b>2|'. |
| 175 | '<>:xip/c:NPA$<b>64<i>0<i>1<i>1<b>3|'. |
| 176 | '<>:xip/c:NOUN$<b>64<i>0<i>1<i>1<b>4|'. |
| 177 | '<>:xip/c:SYMBOL$<b>64<i>0<i>1<i>1<b>5|'. |
| 178 | '>:xip/d:SUBJ$<i>3|'. |
| 179 | '<:xip/d:COORD$<i>1|'. |
| 180 | '<>:xip/s:s$<b>64<i>0<i>74<i>13<b>0|'. |
| 181 | '-:xip/sentences$<i>65]'; |
| 182 | |
| 183 | { |
| 184 | local $SIG{__WARN__} = sub {}; |
| 185 | is_deeply( |
| 186 | _t2h($tokens->stream->pos(0)->to_string), |
| 187 | _t2h($s), |
| 188 | 'Startinfo'); |
| 189 | }; |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 190 | |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 191 | |
Akron | e19aa14 | 2016-02-01 14:38:40 +0100 | [diff] [blame] | 192 | is($tokens->layer_info, |
| 193 | '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/d=rels 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'); |
| 194 | |
| 195 | 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/dependency mate/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho treetagger/sentences xip xip/constituency xip/dependency xip/morpho xip/sentences', 'Support'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 196 | |
| 197 | done_testing; |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 198 | __END__ |