blob: 7c9a15e8e6b5e0278e6098921c41cfcf0643c78a [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
Akrone4c2e412016-01-28 15:10:50 +010015use_ok('KorAP::XML::Krill');
Nils Diewald7b847222014-04-23 11:14:00 +000016
Nils Diewaldfeccbb12015-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;
Akron31d788e2016-02-05 20:49:03 +010028# push(@layers, ['Base', 'Sentences']);
Nils Diewald7b847222014-04-23 11:14:00 +000029push(@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
Akron31d788e2016-02-05 20:49:03 +010040# push(@layers, ['DeReKo', 'Structure']);
Akron93d620e2016-02-05 19:40:05 +010041
Akron31d788e2016-02-05 20:49:03 +010042# push(@layers, ['Glemm', 'Morpho']);
Akron93d620e2016-02-05 19:40:05 +010043
Akron31d788e2016-02-05 20:49:03 +010044# push(@layers, ['Mate', 'Morpho']);
Akron93d620e2016-02-05 19:40:05 +010045push(@layers, ['Mate', 'Dependency']);
46
Akron31d788e2016-02-05 20:49:03 +010047# push(@layers, ['Malt', 'Dependency']);
Akron93d620e2016-02-05 19:40:05 +010048
Nils Diewald7b847222014-04-23 11:14:00 +000049# Connexor
50push(@layers, ['Connexor', 'Morpho']);
51push(@layers, ['Connexor', 'Syntax']);
52push(@layers, ['Connexor', 'Phrase']);
53push(@layers, ['Connexor', 'Sentences']);
54
Akron31d788e2016-02-05 20:49:03 +010055
56# TODO: OpenNLP
57
Nils Diewald7b847222014-04-23 11:14:00 +000058# TreeTagger
59push(@layers, ['TreeTagger', 'Morpho']);
60push(@layers, ['TreeTagger', 'Sentences']);
61
62# Mate
Akron31d788e2016-02-05 20:49:03 +010063#push(@layers, ['Mate', 'Morpho']);
64#push(@layers, ['Mate', 'Dependency']);
Nils Diewald7b847222014-04-23 11:14:00 +000065
66# XIP
67push(@layers, ['XIP', 'Morpho']);
68push(@layers, ['XIP', 'Constituency']);
Akrona6ea30a2016-03-02 13:27:29 +010069# push(@layers, ['XIP', 'Dependency']); # Will be skipped
Nils Diewald7b847222014-04-23 11:14:00 +000070push(@layers, ['XIP', 'Sentences']);
71
72
Akron9c0488f2016-01-28 14:17:15 +010073my $path = catdir(dirname(__FILE__), 'corpus/WPD/00001');
Akrone4c2e412016-01-28 15:10:50 +010074ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Nils Diewaldfeccbb12015-06-18 20:06:45 +000075like($doc->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000076
Akrone4c2e412016-01-28 15:10:50 +010077ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document');
Nils Diewaldfeccbb12015-06-18 20:06:45 +000078like($doc->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000079
80ok($doc->parse, 'Parse document');
81
82# Metdata
Akron35db6e32016-03-17 22:42:22 +010083my $meta = $doc->meta;
84is($meta->{title}, 'A', 'title');
85ok(!$meta->{sub_title}, 'subTitle');
Nils Diewald7b847222014-04-23 11:14:00 +000086
Nils Diewald840c9242014-10-28 19:51:26 +000087is($doc->text_sigle, 'WPD_AAA.00001', 'ID');
88is($doc->corpus_sigle, 'WPD', 'corpusID');
Akron35db6e32016-03-17 22:42:22 +010089
90is($meta->{pub_date}, '20050328', 'pubDate');
91is($meta->{pub_place}, 'URL:http://de.wikipedia.org', 'pubPlace');
92is($meta->{text_class}->[0], 'freizeit-unterhaltung', 'TextClass');
93is($meta->{text_class}->[1], 'reisen', 'TextClass');
94is($meta->{text_class}->[2], 'wissenschaft', 'TextClass');
95is($meta->{text_class}->[3], 'populaerwissenschaft', 'TextClass');
96ok(!$meta->{text_class}->[4], 'TextClass');
97is($meta->{author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'author');
Nils Diewald7b847222014-04-23 11:14:00 +000098
99# Get tokens
Akrone4c2e412016-01-28 15:10:50 +0100100use_ok('KorAP::XML::Tokenizer');
Nils Diewald7b847222014-04-23 11:14:00 +0000101# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +0100102ok(my $tokens = KorAP::XML::Tokenizer->new(
Nils Diewald7b847222014-04-23 11:14:00 +0000103 path => $doc->path,
104 doc => $doc,
105 foundry => 'OpenNLP',
106 layer => 'Tokens',
107 name => 'tokens'
108), 'New Tokenizer');
109ok($tokens->parse, 'Parse');
110
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000111like($tokens->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +0000112is($tokens->foundry, 'OpenNLP', 'Foundry');
Nils Diewald840c9242014-10-28 19:51:26 +0000113is($tokens->doc->text_sigle, 'WPD_AAA.00001', 'Doc id');
Nils Diewald7b847222014-04-23 11:14:00 +0000114is($tokens->should, 1068, 'Should');
115is($tokens->have, 923, 'Have');
116is($tokens->name, 'tokens', 'Name');
117is($tokens->layer, 'Tokens', 'Layer');
118
Akron0e924c42016-01-28 00:20:04 +0100119
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000120is_deeply(_t2h($tokens->stream->pos(118)->to_string),
Akron0e924c42016-01-28 00:20:04 +0100121 _t2h('[(763-768)s:Linie|i:linie|_118$<i>763<i>768]'),
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000122 'Token is correct');
Nils Diewald7b847222014-04-23 11:14:00 +0000123
124# Add Mate
125ok($tokens->add('Mate', 'Morpho'), 'Add Mate');
126
Akron0e924c42016-01-28 00:20:04 +0100127
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000128is_deeply(
129 _t2h($tokens->stream->pos(118)->to_string),
Akron0e924c42016-01-28 00:20:04 +0100130 _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 Diewaldfeccbb12015-06-18 20:06:45 +0000131 'with Mate');
Nils Diewald7b847222014-04-23 11:14:00 +0000132
133# Add sentences
134ok($tokens->add('Base', 'Sentences'), 'Add Sentences');
135
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000136is_deeply(
137 _t2h($tokens->stream->pos(0)->to_string),
Akron2d83a5a2016-02-26 00:21:16 +0100138 _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 Diewaldfeccbb12015-06-18 20:06:45 +0000139 'Startinfo'
140);
Nils Diewald7b847222014-04-23 11:14:00 +0000141
142foreach (@layers) {
143 ok($tokens->add(@$_), 'Add '. join(', ', @$_));
144};
145
Akron0e924c42016-01-28 00:20:04 +0100146my $s =
147 '[(0-1)s:A|i:a|_0$<i>0<i>1|'.
148 '-:tokens$<i>923|'.
149 'mate/p:XY|'.
150 '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2|'.
Akron2d83a5a2016-02-26 00:21:16 +0100151 '<>:base/s:t$<b>64<i>0<i>6083<i>922<b>0|'.
Akron0e924c42016-01-28 00:20:04 +0100152 '-:base/sentences$<i>96|'.
153 '<>:base/s:p$<b>64<i>0<i>224<i>34<b>1|'.
154 '-:base/paragraphs$<i>76|'.
155 'opennlp/p:NE|' .
156 '<>:opennlp/s:s$<b>64<i>0<i>74<i>13<b>0|'.
157 '-:opennlp/sentences$<i>50|'.
158 '<>:corenlp/s:s$<b>64<i>0<i>6<i>2<b>0|'.
159 '-:corenlp/sentences$<i>68|'.
160 'cnx/l:A|'.
161 'cnx/p:N|'.
162 'cnx/syn:@NH|'.
163 '<>:cnx/c:np$<b>64<i>0<i>1<i>1<b>0|'.
164 '<>:cnx/s:s$<b>64<i>0<i>74<i>13<b>0|'.
165 '-:cnx/sentences$<i>63|'.
166 'tt/l:A$<b>129<b>199|'.
167 'tt/p:NN$<b>129<b>199|'.
168 'tt/l:A$<b>129<b>54|'.
169 'tt/p:FM$<b>129<b>54|'.
170 '<>:tt/s:s$<b>64<i>0<i>6083<i>923<b>0|'.
171 '-:tt/sentences$<i>1|'.
Akron75ba57d2016-03-07 23:36:27 +0100172 '>:mate/d:PNC$<b>32<i>2|' . #<s>0<s>0|'.
Akron88000f92016-03-05 12:39:57 +0100173# 'mate/d:&&&$<b>128<s>1|'.
Akron0e924c42016-01-28 00:20:04 +0100174 'xip/p:SYMBOL|'.
175 'xip/l:A|'.
176 '<>:xip/c:TOP$<b>64<i>0<i>74<i>13<b>0|'.
177 '<>:xip/c:MC$<b>64<i>0<i>73<i>13<b>1|'.
178 '<>:xip/c:NP$<b>64<i>0<i>1<i>1<b>2|'.
179 '<>:xip/c:NPA$<b>64<i>0<i>1<i>1<b>3|'.
180 '<>:xip/c:NOUN$<b>64<i>0<i>1<i>1<b>4|'.
181 '<>:xip/c:SYMBOL$<b>64<i>0<i>1<i>1<b>5|'.
Akrona6ea30a2016-03-02 13:27:29 +0100182# '>:xip/d:SUBJ$<i>3|'.
183# '<:xip/d:COORD$<i>1|'.
Akron0e924c42016-01-28 00:20:04 +0100184 '<>:xip/s:s$<b>64<i>0<i>74<i>13<b>0|'.
185 '-:xip/sentences$<i>65]';
186
187{
188 local $SIG{__WARN__} = sub {};
189 is_deeply(
190 _t2h($tokens->stream->pos(0)->to_string),
191 _t2h($s),
192 'Startinfo');
193};
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000194
Nils Diewald7b847222014-04-23 11:14:00 +0000195
Akrone19aa142016-02-01 14:38:40 +0100196is($tokens->layer_info,
Akrona6ea30a2016-03-02 13:27:29 +0100197 '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');
198# xip/d=rels
Akrone19aa142016-02-01 14:38:40 +0100199
Akrona6ea30a2016-03-02 13:27:29 +0100200is($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');
201# xip/dependency
Nils Diewald7b847222014-04-23 11:14:00 +0000202done_testing;
Nils Diewald7b847222014-04-23 11:14:00 +0000203__END__