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