Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
| 7 | use Benchmark qw/:hireswallclock/; |
| 8 | |
| 9 | my $t = Benchmark->new; |
| 10 | |
| 11 | use utf8; |
| 12 | use lib 'lib', '../lib'; |
| 13 | |
| 14 | use File::Basename 'dirname'; |
| 15 | use File::Spec::Functions 'catdir'; |
| 16 | |
| 17 | use_ok('KorAP::XML::Krill'); |
| 18 | |
| 19 | # GOE/AGA/03828 |
| 20 | my $path = catdir(dirname(__FILE__), '../corpus/WPD/00001'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 21 | |
| 22 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 23 | ok($doc->parse, 'Parse document'); |
| 24 | |
Akron | 1cd5b87 | 2016-03-22 00:23:46 +0100 | [diff] [blame] | 25 | is($doc->text_sigle, 'WPD/AAA/00001', 'Correct text sigle'); |
| 26 | is($doc->doc_sigle, 'WPD/AAA', 'Correct document sigle'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 27 | is($doc->corpus_sigle, 'WPD', 'Correct corpus sigle'); |
| 28 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 29 | my $meta = $doc->meta; |
| 30 | is($meta->{title}, 'A', 'Title'); |
| 31 | is($meta->{pub_place}, 'URL:http://de.wikipedia.org', 'PubPlace'); |
| 32 | is($meta->{pub_date}, '20050328', 'Creation Date'); |
| 33 | ok(!$meta->{sub_title}, 'SubTitle'); |
| 34 | is($meta->{author}, 'Ruru; Jens.Ol; Aglarech; u.a.', 'Author'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 35 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 36 | ok(!$meta->{doc_title}, 'Correct Doc title'); |
| 37 | ok(!$meta->{doc_sub_title}, 'Correct Doc Sub title'); |
| 38 | ok(!$meta->{doc_author}, 'Correct Doc author'); |
| 39 | ok(!$meta->{doc_editor}, 'Correct Doc editor'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 40 | |
Akron | 35db6e3 | 2016-03-17 22:42:22 +0100 | [diff] [blame] | 41 | ok(!$meta->{corpus_title}, 'Correct Corpus title'); |
| 42 | ok(!$meta->{corpus_sub_title}, 'Correct Corpus Sub title'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 43 | |
| 44 | # Tokenization |
| 45 | use_ok('KorAP::XML::Tokenizer'); |
| 46 | |
| 47 | my ($token_base_foundry, $token_base_layer) = (qw/OpenNLP Tokens/); |
| 48 | |
| 49 | # Get tokenization |
| 50 | my $tokens = KorAP::XML::Tokenizer->new( |
| 51 | path => $doc->path, |
| 52 | doc => $doc, |
| 53 | foundry => $token_base_foundry, |
| 54 | layer => $token_base_layer, |
| 55 | name => 'tokens' |
| 56 | ); |
| 57 | ok($tokens, 'Token Object is fine'); |
| 58 | ok($tokens->parse, 'Token parsing is fine'); |
| 59 | |
| 60 | my $output = $tokens->to_data; |
| 61 | |
| 62 | is(substr($output->{data}->{text}, 0, 100), 'A bzw. a ist der erste Buchstabe des lateinischen Alphabets und ein Vokal. Der Buchstabe A hat in de', 'Primary Data'); |
| 63 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 64 | is($output->{data}->{tokenSource}, 'opennlp#tokens', 'tokenSource'); |
| 65 | |
| 66 | is($output->{version}, '0.03', 'version'); |
| 67 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 68 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 69 | is($output->{data}->{stream}->[0]->[4], 's:A', 'data'); |
| 70 | |
| 71 | $tokens->add('Mate', 'Dependency'); |
| 72 | |
| 73 | my $stream = $tokens->to_data->{data}->{stream}; |
| 74 | |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 75 | # This is not a goot relation example |
| 76 | is($stream->[77]->[0], |
| 77 | '<:mate/d:--$<b>34<i>498<i>499<i>78<i>78', |
| 78 | 'element to term'); |
Akron | 75ba57d | 2016-03-07 23:36:27 +0100 | [diff] [blame] | 79 | is($stream->[78]->[0], '>:mate/d:--$<b>33<i>498<i>499<i>77<i>78', 'term to element'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 80 | |
Akron | af0ae3f | 2016-07-14 16:21:50 +0200 | [diff] [blame] | 81 | $tokens->add('Base', 'Sentences'); |
| 82 | |
| 83 | $stream = $tokens->to_data->{data}->{stream}; |
| 84 | |
| 85 | is($stream->[0]->[2], '<>:base/s:s$<b>64<i>0<i>74<i>13<b>2', 'Text starts with sentence'); |
Akron | d3a0bad | 2016-02-26 14:07:58 +0100 | [diff] [blame] | 86 | |
| 87 | done_testing; |
| 88 | __END__ |
| 89 | |
| 90 | |
| 91 | |
| 92 | |