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 | |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 15 | use_ok('KorAP::Document'); |
| 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; |
| 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']); |
| 52 | push(@layers, ['Mate', 'Dependency']); |
| 53 | |
| 54 | # XIP |
| 55 | push(@layers, ['XIP', 'Morpho']); |
| 56 | push(@layers, ['XIP', 'Constituency']); |
| 57 | push(@layers, ['XIP', 'Dependency']); |
| 58 | push(@layers, ['XIP', 'Sentences']); |
| 59 | |
| 60 | |
Nils Diewald | 8e323ee | 2014-04-23 17:28:14 +0000 | [diff] [blame] | 61 | my $path = catdir(dirname(__FILE__), 'WPD/00001'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 62 | ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document'); |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 63 | like($doc->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 64 | |
| 65 | ok($doc = KorAP::Document->new( path => $path ), 'Load Korap::Document'); |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 66 | like($doc->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 67 | |
| 68 | ok($doc->parse, 'Parse document'); |
| 69 | |
| 70 | # Metdata |
| 71 | is($doc->title, 'A', 'title'); |
| 72 | ok(!$doc->sub_title, 'subTitle'); |
| 73 | |
Nils Diewald | 840c924 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 74 | is($doc->text_sigle, 'WPD_AAA.00001', 'ID'); |
| 75 | is($doc->corpus_sigle, 'WPD', 'corpusID'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 76 | is($doc->pub_date, '20050328', 'pubDate'); |
Nils Diewald | 8e323ee | 2014-04-23 17:28:14 +0000 | [diff] [blame] | 77 | is($doc->pub_place, 'URL:http://de.wikipedia.org', 'pubPlace'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 78 | is($doc->text_class->[0], 'freizeit-unterhaltung', 'TextClass'); |
| 79 | is($doc->text_class->[1], 'reisen', 'TextClass'); |
| 80 | is($doc->text_class->[2], 'wissenschaft', 'TextClass'); |
| 81 | is($doc->text_class->[3], 'populaerwissenschaft', 'TextClass'); |
| 82 | ok(!$doc->text_class->[4], 'TextClass'); |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 83 | is($doc->author, 'Ruru; Jens.Ol; Aglarech; u.a.', 'author'); |
| 84 | #is($doc->author->[0], 'Ruru', 'author'); |
| 85 | #is($doc->author->[1], 'Jens.Ol', 'author'); |
| 86 | #is($doc->author->[2], 'Aglarech', 'author'); |
| 87 | #ok(!$doc->author->[3], 'author'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 88 | |
| 89 | # Get tokens |
| 90 | use_ok('KorAP::Tokenizer'); |
| 91 | # Get tokenization |
| 92 | ok(my $tokens = KorAP::Tokenizer->new( |
| 93 | path => $doc->path, |
| 94 | doc => $doc, |
| 95 | foundry => 'OpenNLP', |
| 96 | layer => 'Tokens', |
| 97 | name => 'tokens' |
| 98 | ), 'New Tokenizer'); |
| 99 | ok($tokens->parse, 'Parse'); |
| 100 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 101 | like($tokens->path, qr!$path/$!, 'Path'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 102 | is($tokens->foundry, 'OpenNLP', 'Foundry'); |
Nils Diewald | 840c924 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 103 | is($tokens->doc->text_sigle, 'WPD_AAA.00001', 'Doc id'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 104 | is($tokens->should, 1068, 'Should'); |
| 105 | is($tokens->have, 923, 'Have'); |
| 106 | is($tokens->name, 'tokens', 'Name'); |
| 107 | is($tokens->layer, 'Tokens', 'Layer'); |
| 108 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 109 | is_deeply(_t2h($tokens->stream->pos(118)->to_string), |
| 110 | _t2h('[(763-768)s:Linie|i:linie|_118#763-768]'), |
| 111 | 'Token is correct'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 112 | |
| 113 | # Add Mate |
| 114 | ok($tokens->add('Mate', 'Morpho'), 'Add Mate'); |
| 115 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 116 | is_deeply( |
| 117 | _t2h($tokens->stream->pos(118)->to_string), |
| 118 | _t2h('[(763-768)s:Linie|i:linie|_118#763-768|mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem]'), |
| 119 | 'with Mate'); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 120 | |
| 121 | # Add sentences |
| 122 | ok($tokens->add('Base', 'Sentences'), 'Add Sentences'); |
| 123 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 124 | is_deeply( |
| 125 | _t2h($tokens->stream->pos(0)->to_string), |
| 126 | _t2h('[(0-1)s:A|i:a|_0#0-1|-:tokens$<i>923|mate/p:XY|<>:base/s:s#0-74$<i>13<b>2|<>:base/s:t#0-6083$<i>923<b>0|-:base/sentences$<i>96]'), |
| 127 | 'Startinfo' |
| 128 | ); |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 129 | |
| 130 | foreach (@layers) { |
| 131 | ok($tokens->add(@$_), 'Add '. join(', ', @$_)); |
| 132 | }; |
| 133 | |
Nils Diewald | feccbb1 | 2015-06-18 20:06:45 +0000 | [diff] [blame] | 134 | is( |
| 135 | _t2h($tokens->stream->pos(0)->to_string), |
| 136 | _t2h('[(0-1)s:A|i:a|_0#0-1|-:tokens$<i>923|mate/p:XY|<>:base/s:s#0-74$<i>13|<>:base/s:t#0-6083$<i>923|-:base/sentences$<i>96|<>:base/s:p#0-224$<i>34|-:base/paragraphs$<i>76|opennlp/p:NE|<>:opennlp/s:s#0-74$<i>13|-:opennlp/sentences$<i>50|<>:corenlp/s:s#0-6$<i>2|-:corenlp/sentences$<i>65|cnx/l:A|cnx/p:N|cnx/syn:@NH|<>:cnx/c:np#0-1$<i>1|<>:cnx/s:s#0-74$<i>13|-:cnx/sentences$<i>62|tt/l:A|tt/p:NN|tt/l:A|tt/p:FM|<>:tt/s:s#0-6083$<i>923|-:tt/sentences$<i>1|>:mate/d:PNC$<i>2|xip/p:SYMBOL|xip/l:A|<>:xip/c:TOP#0-74$<i>13|<>:xip/c:MC#0-73$<i>13<b>1|<>:xip/c:NP#0-1$<i>1<b>2|<>:xip/c:NPA#0-1$<i>1<b>3|<>:xip/c:NOUN#0-1$<i>1<b>4|<>:xip/c:SYMBOL#0-1$<i>1<b>5|>:xip/d:SUBJ$<i>3|<:xip/d:COORD$<i>1|<>:xip/s:s#0-74$<i>13|-:xip/sentences$<i>64]'), |
| 137 | 'Startinfo'); |
| 138 | |
| 139 | done_testing; |
| 140 | __END__ |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 141 | |
| 142 | |
Nils Diewald | ff6d078 | 2014-06-10 18:26:36 +0000 | [diff] [blame] | 143 | #is($tokens->stream->pos(118)->to_string, |
| 144 | # '[(763-768)s:Linie|i:linie|_118#763-768|'. |
| 145 | # 'mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem|' . |
| 146 | # 'opennlp/p:NN|'. |
| 147 | # 'cnx/l:linie|cnx/p:N|cnx/syn:@NH|'. |
| 148 | # 'tt/l:Linie|tt/p:NN|'. |
| 149 | # '<:mate/d:NK$<i>116|<:mate/d:NK$<i>117|>:mate/d:NK$<i>115|'. |
| 150 | # 'xip/p:NOUN|xip/l:Linie|<>:xip/c:NOUN#763-768$<i>119|<:xip/d:DETERM$<i>116|<:xip/d:NMOD$<i>117]', 'with All'); |
| 151 | |
| 152 | #[(763-768)s:Linie|i:linie|_118#763-768|mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem|opennlp/p:NN|cnx/l:linie|cnx/p:N|cnx/syn:@NH|tt/l:Linie|tt/p:NN|<:mate/d:NK$<i>116|<:mate/d:NK$<i>117|>:mate/d:NK$<i>115| |
| 153 | # xip/p:NOUN|xip/l:Linie|<:xip/d:DETERM$<i>116|<:xip/d:NMOD$<i>117] |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 154 | |
| 155 | is($tokens->layer_info, 'cnx/c=const cnx/l=lemma cnx/m=msd cnx/p=pos mate/d=dep mate/l=lemma mate/m=msd mate/p=pos opennlp/p=pos tt/l=lemma tt/p=pos xip/c=const xip/d=dep xip/l=lemma xip/p=pos', 'Layer info'); |
| 156 | |
| 157 | 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'); |
| 158 | |
Nils Diewald | ff6d078 | 2014-06-10 18:26:36 +0000 | [diff] [blame] | 159 | |
Nils Diewald | 840c924 | 2014-10-28 19:51:26 +0000 | [diff] [blame] | 160 | |
| 161 | |
Nils Diewald | ff6d078 | 2014-06-10 18:26:36 +0000 | [diff] [blame] | 162 | # encode_json $tokens->stream->to_solr; |
| 163 | |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 164 | done_testing; |
| 165 | |
Nils Diewald | ff6d078 | 2014-06-10 18:26:36 +0000 | [diff] [blame] | 166 | |
| 167 | |
| 168 | |
| 169 | |
Nils Diewald | 7b84722 | 2014-04-23 11:14:00 +0000 | [diff] [blame] | 170 | __END__ |