blob: 33706a469de117cf4235bd8135aa209cf98a7e10 [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;
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
Akron9c0488f2016-01-28 14:17:15 +010061my $path = catdir(dirname(__FILE__), 'corpus/WPD/00001');
Akrone4c2e412016-01-28 15:10:50 +010062ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
Nils Diewaldfeccbb12015-06-18 20:06:45 +000063like($doc->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000064
Akrone4c2e412016-01-28 15:10:50 +010065ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document');
Nils Diewaldfeccbb12015-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 Diewald840c9242014-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 Diewaldfeccbb12015-06-18 20:06:45 +000083is($doc->author, 'Ruru; Jens.Ol; Aglarech; u.a.', 'author');
Nils Diewald7b847222014-04-23 11:14:00 +000084
85# Get tokens
Akrone4c2e412016-01-28 15:10:50 +010086use_ok('KorAP::XML::Tokenizer');
Nils Diewald7b847222014-04-23 11:14:00 +000087# Get tokenization
Akrone4c2e412016-01-28 15:10:50 +010088ok(my $tokens = KorAP::XML::Tokenizer->new(
Nils Diewald7b847222014-04-23 11:14:00 +000089 path => $doc->path,
90 doc => $doc,
91 foundry => 'OpenNLP',
92 layer => 'Tokens',
93 name => 'tokens'
94), 'New Tokenizer');
95ok($tokens->parse, 'Parse');
96
Nils Diewaldfeccbb12015-06-18 20:06:45 +000097like($tokens->path, qr!$path/$!, 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000098is($tokens->foundry, 'OpenNLP', 'Foundry');
Nils Diewald840c9242014-10-28 19:51:26 +000099is($tokens->doc->text_sigle, 'WPD_AAA.00001', 'Doc id');
Nils Diewald7b847222014-04-23 11:14:00 +0000100is($tokens->should, 1068, 'Should');
101is($tokens->have, 923, 'Have');
102is($tokens->name, 'tokens', 'Name');
103is($tokens->layer, 'Tokens', 'Layer');
104
Akron0e924c42016-01-28 00:20:04 +0100105
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000106is_deeply(_t2h($tokens->stream->pos(118)->to_string),
Akron0e924c42016-01-28 00:20:04 +0100107 _t2h('[(763-768)s:Linie|i:linie|_118$<i>763<i>768]'),
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000108 'Token is correct');
Nils Diewald7b847222014-04-23 11:14:00 +0000109
110# Add Mate
111ok($tokens->add('Mate', 'Morpho'), 'Add Mate');
112
Akron0e924c42016-01-28 00:20:04 +0100113
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000114is_deeply(
115 _t2h($tokens->stream->pos(118)->to_string),
Akron0e924c42016-01-28 00:20:04 +0100116 _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 +0000117 'with Mate');
Nils Diewald7b847222014-04-23 11:14:00 +0000118
119# Add sentences
120ok($tokens->add('Base', 'Sentences'), 'Add Sentences');
121
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000122is_deeply(
123 _t2h($tokens->stream->pos(0)->to_string),
Akron0e924c42016-01-28 00:20:04 +0100124 _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 Diewaldfeccbb12015-06-18 20:06:45 +0000125 'Startinfo'
126);
Nils Diewald7b847222014-04-23 11:14:00 +0000127
128foreach (@layers) {
129 ok($tokens->add(@$_), 'Add '. join(', ', @$_));
130};
131
Akron0e924c42016-01-28 00:20:04 +0100132my $s =
133 '[(0-1)s:A|i:a|_0$<i>0<i>1|'.
134 '-:tokens$<i>923|'.
135 'mate/p:XY|'.
136 '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2|'.
137 '<>:base/s:t$<b>64<i>0<i>6083<i>923<b>0|'.
138 '-:base/sentences$<i>96|'.
139 '<>:base/s:p$<b>64<i>0<i>224<i>34<b>1|'.
140 '-:base/paragraphs$<i>76|'.
141 'opennlp/p:NE|' .
142 '<>:opennlp/s:s$<b>64<i>0<i>74<i>13<b>0|'.
143 '-:opennlp/sentences$<i>50|'.
144 '<>:corenlp/s:s$<b>64<i>0<i>6<i>2<b>0|'.
145 '-:corenlp/sentences$<i>68|'.
146 'cnx/l:A|'.
147 'cnx/p:N|'.
148 'cnx/syn:@NH|'.
149 '<>:cnx/c:np$<b>64<i>0<i>1<i>1<b>0|'.
150 '<>:cnx/s:s$<b>64<i>0<i>74<i>13<b>0|'.
151 '-:cnx/sentences$<i>63|'.
152 'tt/l:A$<b>129<b>199|'.
153 'tt/p:NN$<b>129<b>199|'.
154 'tt/l:A$<b>129<b>54|'.
155 'tt/p:FM$<b>129<b>54|'.
156 '<>:tt/s:s$<b>64<i>0<i>6083<i>923<b>0|'.
157 '-:tt/sentences$<i>1|'.
158 '>:mate/d:PNC$<i>2|'.
159 'xip/p:SYMBOL|'.
160 'xip/l:A|'.
161 '<>:xip/c:TOP$<b>64<i>0<i>74<i>13<b>0|'.
162 '<>:xip/c:MC$<b>64<i>0<i>73<i>13<b>1|'.
163 '<>:xip/c:NP$<b>64<i>0<i>1<i>1<b>2|'.
164 '<>:xip/c:NPA$<b>64<i>0<i>1<i>1<b>3|'.
165 '<>:xip/c:NOUN$<b>64<i>0<i>1<i>1<b>4|'.
166 '<>:xip/c:SYMBOL$<b>64<i>0<i>1<i>1<b>5|'.
167 '>:xip/d:SUBJ$<i>3|'.
168 '<:xip/d:COORD$<i>1|'.
169 '<>:xip/s:s$<b>64<i>0<i>74<i>13<b>0|'.
170 '-:xip/sentences$<i>65]';
171
172{
173 local $SIG{__WARN__} = sub {};
174 is_deeply(
175 _t2h($tokens->stream->pos(0)->to_string),
176 _t2h($s),
177 'Startinfo');
178};
Nils Diewaldfeccbb12015-06-18 20:06:45 +0000179
Akron9c0488f2016-01-28 14:17:15 +0100180is($tokens->layer_info,
181 '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');
Nils Diewald7b847222014-04-23 11:14:00 +0000182
183is($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');
184
185done_testing;
Nils Diewald7b847222014-04-23 11:14:00 +0000186__END__