blob: 3f351d7831600ad09959b2d80b59cbb1ac5eb91c [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
17my @layers;
18# push(@layers, ['Base', 'Sentences']);
19push(@layers, ['Base', 'Paragraphs']);
20
21# OpenNLP
22push(@layers, ['OpenNLP', 'Morpho']);
23push(@layers, ['OpenNLP', 'Sentences']);
24
25# CoreNLP
26push(@layers, ['CoreNLP', 'NamedEntities', 'ne_dewac_175m_600']);
27push(@layers, ['CoreNLP', 'NamedEntities', 'ne_hgc_175m_600']);
28push(@layers, ['CoreNLP', 'Sentences']);
29
30# Connexor
31push(@layers, ['Connexor', 'Morpho']);
32push(@layers, ['Connexor', 'Syntax']);
33push(@layers, ['Connexor', 'Phrase']);
34push(@layers, ['Connexor', 'Sentences']);
35
36# TreeTagger
37push(@layers, ['TreeTagger', 'Morpho']);
38push(@layers, ['TreeTagger', 'Sentences']);
39
40# Mate
41# push(@layers, ['Mate', 'Morpho']);
42push(@layers, ['Mate', 'Dependency']);
43
44# XIP
45push(@layers, ['XIP', 'Morpho']);
46push(@layers, ['XIP', 'Constituency']);
47push(@layers, ['XIP', 'Dependency']);
48push(@layers, ['XIP', 'Sentences']);
49
50
Nils Diewald8e323ee2014-04-23 17:28:14 +000051my $path = catdir(dirname(__FILE__), 'WPD/00001');
Nils Diewald7b847222014-04-23 11:14:00 +000052ok(my $doc = KorAP::Document->new( path => $path . '/' ), 'Load Korap::Document');
53is($doc->path, $path . '/', 'Path');
54
55ok($doc = KorAP::Document->new( path => $path ), 'Load Korap::Document');
56is($doc->path, $path . '/', 'Path');
57
58ok($doc->parse, 'Parse document');
59
60# Metdata
61is($doc->title, 'A', 'title');
62ok(!$doc->sub_title, 'subTitle');
63
64is($doc->id, 'WPD_AAA.00001', 'ID');
65is($doc->corpus_id, 'WPD', 'corpusID');
66is($doc->pub_date, '20050328', 'pubDate');
Nils Diewald8e323ee2014-04-23 17:28:14 +000067is($doc->pub_place, 'URL:http://de.wikipedia.org', 'pubPlace');
Nils Diewald7b847222014-04-23 11:14:00 +000068is($doc->text_class->[0], 'freizeit-unterhaltung', 'TextClass');
69is($doc->text_class->[1], 'reisen', 'TextClass');
70is($doc->text_class->[2], 'wissenschaft', 'TextClass');
71is($doc->text_class->[3], 'populaerwissenschaft', 'TextClass');
72ok(!$doc->text_class->[4], 'TextClass');
73is($doc->author->[0], 'Ruru', 'author');
74is($doc->author->[1], 'Jens.Ol', 'author');
75is($doc->author->[2], 'Aglarech', 'author');
76ok(!$doc->author->[3], 'author');
77
78# Get tokens
79use_ok('KorAP::Tokenizer');
80# Get tokenization
81ok(my $tokens = KorAP::Tokenizer->new(
82 path => $doc->path,
83 doc => $doc,
84 foundry => 'OpenNLP',
85 layer => 'Tokens',
86 name => 'tokens'
87), 'New Tokenizer');
88ok($tokens->parse, 'Parse');
89
Nils Diewald8e323ee2014-04-23 17:28:14 +000090is($tokens->path, $path . '/', 'Path');
Nils Diewald7b847222014-04-23 11:14:00 +000091is($tokens->foundry, 'OpenNLP', 'Foundry');
92is($tokens->doc->id, 'WPD_AAA.00001', 'Doc id');
93is($tokens->should, 1068, 'Should');
94is($tokens->have, 923, 'Have');
95is($tokens->name, 'tokens', 'Name');
96is($tokens->layer, 'Tokens', 'Layer');
97
98is($tokens->stream->pos(118)->to_string, '[(763-768)s:Linie|i:linie|_118#763-768]', 'Token is correct');
99
100# Add Mate
101ok($tokens->add('Mate', 'Morpho'), 'Add Mate');
102
103is($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');
104
105# Add sentences
106ok($tokens->add('Base', 'Sentences'), 'Add Sentences');
107
Nils Diewald98767bb2014-04-25 20:31:19 +0000108is($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 +0000109
110foreach (@layers) {
111 ok($tokens->add(@$_), 'Add '. join(', ', @$_));
112};
113
Nils Diewald47c3ef32014-04-30 19:13:17 +0000114is($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/c:np#0-1$<i>1|<>: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/c:NP#0-1$<i>1<b>2|<>:xip/c:NPA#0-1$<i>1<b>3|<>:xip/c:NOUN#0-1$<i>1<b>4|<>:xip/c:SYMBOL#0-1$<i>1<b>5|>:xip/d:SUBJ$<i>3|<:xip/d:COORD$<i>1|<>:xip/s#0-74$<i>13|-:xip/sentences$<i>64]', 'Startinfo');
Nils Diewald7b847222014-04-23 11:14:00 +0000115
116
Nils Diewaldff6d0782014-06-10 18:26:36 +0000117#is($tokens->stream->pos(118)->to_string,
118# '[(763-768)s:Linie|i:linie|_118#763-768|'.
119# 'mate/l:linie|mate/p:NN|mate/m:case:acc|mate/m:number:sg|mate/m:gender:fem|' .
120# 'opennlp/p:NN|'.
121# 'cnx/l:linie|cnx/p:N|cnx/syn:@NH|'.
122# 'tt/l:Linie|tt/p:NN|'.
123# '<:mate/d:NK$<i>116|<:mate/d:NK$<i>117|>:mate/d:NK$<i>115|'.
124# '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');
125
126#[(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|
127# xip/p:NOUN|xip/l:Linie|<:xip/d:DETERM$<i>116|<:xip/d:NMOD$<i>117]
Nils Diewald7b847222014-04-23 11:14:00 +0000128
129is($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');
130
131is($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');
132
Nils Diewaldff6d0782014-06-10 18:26:36 +0000133
134# encode_json $tokens->stream->to_solr;
135
Nils Diewald7b847222014-04-23 11:14:00 +0000136done_testing;
137
Nils Diewaldff6d0782014-06-10 18:26:36 +0000138
139
140
141
Nils Diewald7b847222014-04-23 11:14:00 +0000142__END__