blob: 89fd638be0bb5061cfdbd51c5293cc91e81a7e71 [file] [log] [blame]
Nils Diewald7b847222014-04-23 11:14:00 +00001#!/usr/bin/env perl
2use strict;
3use warnings;
4use utf8;
5use Test::More;
6use Benchmark ':hireswallclock';
7use lib 'lib', '../lib';
8
9use_ok('KorAP::Document');
10
11my @layers;
12# push(@layers, ['Base', 'Sentences']);
13push(@layers, ['Base', 'Paragraphs']);
14
15# OpenNLP
16push(@layers, ['OpenNLP', 'Morpho']);
17push(@layers, ['OpenNLP', 'Sentences']);
18
19# CoreNLP
20push(@layers, ['CoreNLP', 'NamedEntities', 'ne_dewac_175m_600']);
21push(@layers, ['CoreNLP', 'NamedEntities', 'ne_hgc_175m_600']);
22push(@layers, ['CoreNLP', 'Sentences']);
23
24# Connexor
25push(@layers, ['Connexor', 'Morpho']);
26push(@layers, ['Connexor', 'Syntax']);
27push(@layers, ['Connexor', 'Phrase']);
28push(@layers, ['Connexor', 'Sentences']);
29
30# TreeTagger
31push(@layers, ['TreeTagger', 'Morpho']);
32push(@layers, ['TreeTagger', 'Sentences']);
33
34# Mate
35# push(@layers, ['Mate', 'Morpho']);
36push(@layers, ['Mate', 'Dependency']);
37
38# XIP
39push(@layers, ['XIP', 'Morpho']);
40push(@layers, ['XIP', 'Constituency']);
41push(@layers, ['XIP', 'Dependency']);
42push(@layers, ['XIP', 'Sentences']);
43
44
45my $path = 'WPD/00001';
46ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
47is($doc->path, $path . '/', 'Path');
48
49ok($doc = KorAP::Document->new( path => $path ), 'Load Korap::Document');
50is($doc->path, $path . '/', 'Path');
51
52ok($doc->parse, 'Parse document');
53
54# Metdata
55is($doc->title, 'A', 'title');
56ok(!$doc->sub_title, 'subTitle');
57
58is($doc->id, 'WPD_AAA.00001', 'ID');
59is($doc->corpus_id, 'WPD', 'corpusID');
60is($doc->pub_date, '20050328', 'pubDate');
61ok(!$doc->pub_place, 'pubPlace');
62is($doc->text_class->[0], 'freizeit-unterhaltung', 'TextClass');
63is($doc->text_class->[1], 'reisen', 'TextClass');
64is($doc->text_class->[2], 'wissenschaft', 'TextClass');
65is($doc->text_class->[3], 'populaerwissenschaft', 'TextClass');
66ok(!$doc->text_class->[4], 'TextClass');
67is($doc->author->[0], 'Ruru', 'author');
68is($doc->author->[1], 'Jens.Ol', 'author');
69is($doc->author->[2], 'Aglarech', 'author');
70ok(!$doc->author->[3], 'author');
71
72# Get tokens
73use_ok('KorAP::Tokenizer');
74# Get tokenization
75ok(my $tokens = KorAP::Tokenizer->new(
76 path => $doc->path,
77 doc => $doc,
78 foundry => 'OpenNLP',
79 layer => 'Tokens',
80 name => 'tokens'
81), 'New Tokenizer');
82ok($tokens->parse, 'Parse');
83
84is($tokens->path, 'WPD/00001/', 'Path');
85is($tokens->foundry, 'OpenNLP', 'Foundry');
86is($tokens->doc->id, 'WPD_AAA.00001', 'Doc id');
87is($tokens->should, 1068, 'Should');
88is($tokens->have, 923, 'Have');
89is($tokens->name, 'tokens', 'Name');
90is($tokens->layer, 'Tokens', 'Layer');
91
92is($tokens->stream->pos(118)->to_string, '[(763-768)s:Linie|i:linie|_118#763-768]', 'Token is correct');
93
94# Add Mate
95ok($tokens->add('Mate', 'Morpho'), 'Add Mate');
96
97is($tokens->stream->pos(118)->to_string, '[(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]', 'with Mate');
98
99# Add sentences
100ok($tokens->add('Base', 'Sentences'), 'Add Sentences');
101
102is($tokens->stream->pos(0)->to_string, '[(0-1)s:A|i:a|_0#0-1|-:tokens$<i>923|mate/p:XY|<>:base/s#0-74$<i>13|<>:base/t#0-6083$<i>923|-:sentences$<i>96]', 'Startinfo');
103
104foreach (@layers) {
105 ok($tokens->add(@$_), 'Add '. join(', ', @$_));
106};
107
108is($tokens->stream->pos(0)->to_string, '[(0-1)s:A|i:a|_0#0-1|-:tokens$<i>923|mate/p:XY|<>:base/s#0-74$<i>13|<>:base/t#0-6083$<i>923|-:sentences$<i>96|<>:base/para#0-224$<i>34|-:paragraphs$<i>76|opennlp/p:NE|<>:opennlp/s#0-74$<i>13|<>:corenlp/s#0-6$<i>2|cnx/l:A|cnx/p:N|cnx/syn:@NH|<>:cnx/s#0-74$<i>13|tt/l:A|tt/p:NN|tt/l:A|tt/p:FM|<>:tt/s#0-6083$<i>923|>: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/d:SUBJ$<i>3|<:xip/d:COORD$<i>1|<>:xip/s#0-74$<i>13]', 'Startinfo');
109
110
111is($tokens->stream->pos(118)->to_string,
112 '[(763-768)s:Linie|i:linie|_118#763-768|'.
113 'mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem|' .
114 'opennlp/p:NN|'.
115 'cnx/l:linie|cnx/p:N|cnx/syn:@NH|'.
116 'tt/l:Linie|tt/p:NN|'.
117 '<:mate/d:NK$<i>116|<:mate/d:NK$<i>117|>:mate/d:NK$<i>115|'.
118 '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');
119
120is($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');
121
122is($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');
123
124done_testing;
125
126__END__