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