blob: 6742e30a78a8cff26c2144955aaca23e658a5788 [file] [log] [blame]
Nils Diewald7b847222014-04-23 11:14:00 +00001#!/usr/bin/env perl
Nils Diewald8e323ee2014-04-23 17:28:14 +00002# source ~/perl5/perlbrew/etc/bashrc
3# perlbrew switch perl-blead@korap
Nils Diewald7b847222014-04-23 11:14:00 +00004use strict;
5use warnings;
6use utf8;
7use Test::More;
Nils Diewaldff6d0782014-06-10 18:26:36 +00008use JSON::XS;
Nils Diewald7b847222014-04-23 11:14:00 +00009use Benchmark ':hireswallclock';
10use lib 'lib', '../lib';
11
Nils Diewald8e323ee2014-04-23 17:28:14 +000012use File::Basename 'dirname';
13use File::Spec::Functions 'catdir';
14
Nils Diewald7b847222014-04-23 11:14:00 +000015use_ok('KorAP::Document');
16
Nils Diewald19205712015-06-18 20:06:45 +000017sub _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 Diewald7b847222014-04-23 11:14:00 +000027my @layers;
28# push(@layers, ['Base', 'Sentences']);
29push(@layers, ['Base', 'Paragraphs']);
30
31# OpenNLP
32push(@layers, ['OpenNLP', 'Morpho']);
33push(@layers, ['OpenNLP', 'Sentences']);
34
35# CoreNLP
36push(@layers, ['CoreNLP', 'NamedEntities', 'ne_dewac_175m_600']);
37push(@layers, ['CoreNLP', 'NamedEntities', 'ne_hgc_175m_600']);
38push(@layers, ['CoreNLP', 'Sentences']);
39
40# Connexor
41push(@layers, ['Connexor', 'Morpho']);
42push(@layers, ['Connexor', 'Syntax']);
43push(@layers, ['Connexor', 'Phrase']);
44push(@layers, ['Connexor', 'Sentences']);
45
46# TreeTagger
47push(@layers, ['TreeTagger', 'Morpho']);
48push(@layers, ['TreeTagger', 'Sentences']);
49
50# Mate
51# push(@layers, ['Mate', 'Morpho']);
52push(@layers, ['Mate', 'Dependency']);
53
54# XIP
55push(@layers, ['XIP', 'Morpho']);
56push(@layers, ['XIP', 'Constituency']);
57push(@layers, ['XIP', 'Dependency']);
58push(@layers, ['XIP', 'Sentences']);
59
60
Nils Diewald8e323ee2014-04-23 17:28:14 +000061my $path = catdir(dirname(__FILE__), 'WPD/00001');
Nils Diewald7b847222014-04-23 11:14:00 +000062ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
Nils Diewald19205712015-06-18 20:06:45 +000063like($doc->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000064
65ok($doc = KorAP::Document->new( path => $path ), 'Load Korap::Document');
Nils Diewald19205712015-06-18 20:06:45 +000066like($doc->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000067
68ok($doc->parse, 'Parse document');
69
70# Metdata
71is($doc->title, 'A', 'title');
72ok(!$doc->sub_title, 'subTitle');
73
Nils Diewald7ec51532014-10-28 19:51:26 +000074is($doc->text_sigle, 'WPD_AAA.00001', 'ID');
75is($doc->corpus_sigle, 'WPD', 'corpusID');
Nils Diewald7b847222014-04-23 11:14:00 +000076is($doc->pub_date, '20050328', 'pubDate');
Nils Diewald8e323ee2014-04-23 17:28:14 +000077is($doc->pub_place, 'URL:http://de.wikipedia.org', 'pubPlace');
Nils Diewald7b847222014-04-23 11:14:00 +000078is($doc->text_class->[0], 'freizeit-unterhaltung', 'TextClass');
79is($doc->text_class->[1], 'reisen', 'TextClass');
80is($doc->text_class->[2], 'wissenschaft', 'TextClass');
81is($doc->text_class->[3], 'populaerwissenschaft', 'TextClass');
82ok(!$doc->text_class->[4], 'TextClass');
Nils Diewald19205712015-06-18 20:06:45 +000083is($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 Diewald7b847222014-04-23 11:14:00 +000088
89# Get tokens
90use_ok('KorAP::Tokenizer');
91# Get tokenization
92ok(my $tokens = KorAP::Tokenizer->new(
93 path => $doc->path,
94 doc => $doc,
95 foundry => 'OpenNLP',
96 layer => 'Tokens',
97 name => 'tokens'
98), 'New Tokenizer');
99ok($tokens->parse, 'Parse');
100
Nils Diewald19205712015-06-18 20:06:45 +0000101like($tokens->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +0000102is($tokens->foundry, 'OpenNLP', 'Foundry');
Nils Diewald7ec51532014-10-28 19:51:26 +0000103is($tokens->doc->text_sigle, 'WPD_AAA.00001', 'Doc id');
Nils Diewald7b847222014-04-23 11:14:00 +0000104is($tokens->should, 1068, 'Should');
105is($tokens->have, 923, 'Have');
106is($tokens->name, 'tokens', 'Name');
107is($tokens->layer, 'Tokens', 'Layer');
108
Akrona686fa32016-01-28 00:20:04 +0100109
Nils Diewald19205712015-06-18 20:06:45 +0000110is_deeply(_t2h($tokens->stream->pos(118)->to_string),
Akrona686fa32016-01-28 00:20:04 +0100111 _t2h('[(763-768)s:Linie|i:linie|_118$<i>763<i>768]'),
Nils Diewald19205712015-06-18 20:06:45 +0000112 'Token is correct');
Nils Diewald7b847222014-04-23 11:14:00 +0000113
114# Add Mate
115ok($tokens->add('Mate', 'Morpho'), 'Add Mate');
116
Akrona686fa32016-01-28 00:20:04 +0100117
Nils Diewald19205712015-06-18 20:06:45 +0000118is_deeply(
119 _t2h($tokens->stream->pos(118)->to_string),
Akrona686fa32016-01-28 00:20:04 +0100120 _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 Diewald19205712015-06-18 20:06:45 +0000121 'with Mate');
Nils Diewald7b847222014-04-23 11:14:00 +0000122
123# Add sentences
124ok($tokens->add('Base', 'Sentences'), 'Add Sentences');
125
Nils Diewald19205712015-06-18 20:06:45 +0000126is_deeply(
127 _t2h($tokens->stream->pos(0)->to_string),
Akrona686fa32016-01-28 00:20:04 +0100128 _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 Diewald19205712015-06-18 20:06:45 +0000129 'Startinfo'
130);
Nils Diewald7b847222014-04-23 11:14:00 +0000131
132foreach (@layers) {
133 ok($tokens->add(@$_), 'Add '. join(', ', @$_));
134};
135
Akrona686fa32016-01-28 00:20:04 +0100136my $s =
137 '[(0-1)s:A|i:a|_0$<i>0<i>1|'.
138 '-:tokens$<i>923|'.
139 'mate/p:XY|'.
140 '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2|'.
141 '<>:base/s:t$<b>64<i>0<i>6083<i>923<b>0|'.
142 '-:base/sentences$<i>96|'.
143 '<>:base/s:p$<b>64<i>0<i>224<i>34<b>1|'.
144 '-:base/paragraphs$<i>76|'.
145 'opennlp/p:NE|' .
146 '<>:opennlp/s:s$<b>64<i>0<i>74<i>13<b>0|'.
147 '-:opennlp/sentences$<i>50|'.
148 '<>:corenlp/s:s$<b>64<i>0<i>6<i>2<b>0|'.
149 '-:corenlp/sentences$<i>68|'.
150 'cnx/l:A|'.
151 'cnx/p:N|'.
152 'cnx/syn:@NH|'.
153 '<>:cnx/c:np$<b>64<i>0<i>1<i>1<b>0|'.
154 '<>:cnx/s:s$<b>64<i>0<i>74<i>13<b>0|'.
155 '-:cnx/sentences$<i>63|'.
156 'tt/l:A$<b>129<b>199|'.
157 'tt/p:NN$<b>129<b>199|'.
158 'tt/l:A$<b>129<b>54|'.
159 'tt/p:FM$<b>129<b>54|'.
160 '<>:tt/s:s$<b>64<i>0<i>6083<i>923<b>0|'.
161 '-:tt/sentences$<i>1|'.
162 '>:mate/d:PNC$<i>2|'.
163 'xip/p:SYMBOL|'.
164 'xip/l:A|'.
165 '<>:xip/c:TOP$<b>64<i>0<i>74<i>13<b>0|'.
166 '<>:xip/c:MC$<b>64<i>0<i>73<i>13<b>1|'.
167 '<>:xip/c:NP$<b>64<i>0<i>1<i>1<b>2|'.
168 '<>:xip/c:NPA$<b>64<i>0<i>1<i>1<b>3|'.
169 '<>:xip/c:NOUN$<b>64<i>0<i>1<i>1<b>4|'.
170 '<>:xip/c:SYMBOL$<b>64<i>0<i>1<i>1<b>5|'.
171 '>:xip/d:SUBJ$<i>3|'.
172 '<:xip/d:COORD$<i>1|'.
173 '<>:xip/s:s$<b>64<i>0<i>74<i>13<b>0|'.
174 '-:xip/sentences$<i>65]';
175
176{
177 local $SIG{__WARN__} = sub {};
178 is_deeply(
179 _t2h($tokens->stream->pos(0)->to_string),
180 _t2h($s),
181 'Startinfo');
182};
Nils Diewald19205712015-06-18 20:06:45 +0000183
184done_testing;
185__END__
Nils Diewald7b847222014-04-23 11:14:00 +0000186
187
Nils Diewaldff6d0782014-06-10 18:26:36 +0000188#is($tokens->stream->pos(118)->to_string,
189# '[(763-768)s:Linie|i:linie|_118#763-768|'.
190# 'mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem|' .
191# 'opennlp/p:NN|'.
192# 'cnx/l:linie|cnx/p:N|cnx/syn:@NH|'.
193# 'tt/l:Linie|tt/p:NN|'.
194# '<:mate/d:NK$<i>116|<:mate/d:NK$<i>117|>:mate/d:NK$<i>115|'.
195# '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');
196
197#[(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|
198# xip/p:NOUN|xip/l:Linie|<:xip/d:DETERM$<i>116|<:xip/d:NMOD$<i>117]
Nils Diewald7b847222014-04-23 11:14:00 +0000199
200is($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');
201
202is($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');
203
Nils Diewaldff6d0782014-06-10 18:26:36 +0000204
Nils Diewald7ec51532014-10-28 19:51:26 +0000205
206
Nils Diewaldff6d0782014-06-10 18:26:36 +0000207# encode_json $tokens->stream->to_solr;
208
Nils Diewald7b847222014-04-23 11:14:00 +0000209done_testing;
210
Nils Diewaldff6d0782014-06-10 18:26:36 +0000211
212
213
214
Nils Diewald7b847222014-04-23 11:14:00 +0000215__END__