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