Akron | 4e1712c | 2019-02-04 22:29:37 +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 | |
| 13 | use File::Basename 'dirname'; |
| 14 | use File::Spec::Functions 'catdir'; |
| 15 | |
| 16 | use_ok('KorAP::XML::Krill'); |
| 17 | |
| 18 | my $path = catdir(dirname(__FILE__), '../corpus/WPE15/G00/11973'); |
| 19 | |
| 20 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 21 | ok($doc->parse, 'Parse document'); |
| 22 | |
| 23 | is($doc->text_sigle, 'WPE15/G00/11973', 'Correct text sigle'); |
| 24 | is($doc->doc_sigle, 'WPE15/G00', 'Correct document sigle'); |
| 25 | is($doc->corpus_sigle, 'WPE15', 'Correct corpus sigle'); |
| 26 | |
| 27 | my $meta = $doc->meta; |
| 28 | is($meta->{T_title}, 'Generation X', 'Title'); |
| 29 | is($meta->{S_pub_place}, 'URL:http://en.wikipedia.org', 'PubPlace'); |
| 30 | is($meta->{D_pub_date}, '20150808', 'Creation Date'); |
| 31 | ok(!$meta->{T_sub_title}, 'Title'); |
| 32 | is($meta->{T_author}, 'Bnosnhoj, u.a.', 'Author'); |
| 33 | is($meta->{T_doc_title}, 'Wikipedia, Artikel mit Anfangsbuchstabe G, Teil 00', 'Correct Doc title'); |
| 34 | |
| 35 | is($meta->{A_reference}, 'Generation X, In: Wikipedia - URL:http://en.wikipedia.org/wiki/Generation_X: Wikipedia, 2015', 'Reference'); |
| 36 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 37 | is($meta->{A_externalLink}, 'data:application/x.korap-link;title=Wikipedia,http://en.wikipedia.org/wiki/Generation_X', 'link'); |
| 38 | |
Akron | 4e1712c | 2019-02-04 22:29:37 +0100 | [diff] [blame] | 39 | is($meta->{'S_availability'}, 'CC-BY-SA', 'Availability'); |
| 40 | is($meta->{'S_language'}, 'en', 'Language'); |
| 41 | |
| 42 | # Tokenization |
| 43 | use_ok('KorAP::XML::Tokenizer'); |
| 44 | |
| 45 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens/); |
| 46 | |
| 47 | # Get tokenization |
| 48 | my $tokens = KorAP::XML::Tokenizer->new( |
| 49 | path => $doc->path, |
| 50 | doc => $doc, |
| 51 | foundry => $token_base_foundry, |
| 52 | layer => $token_base_layer, |
| 53 | name => 'tokens' |
| 54 | ); |
| 55 | ok($tokens, 'Token Object is fine'); |
| 56 | ok($tokens->parse, 'Token parsing is fine'); |
| 57 | |
| 58 | my $output = $tokens->to_data; |
| 59 | |
| 60 | is(substr($output->{data}->{text}, 0, 100), ' Generation X, commonly abbreviated to Gen X, is the generation born after the Western Post–', 'Primary Data'); |
| 61 | is($output->{data}->{name}, 'tokens', 'tokenName'); |
| 62 | is($output->{data}->{tokenSource}, 'base#tokens', 'tokenSource'); |
| 63 | |
| 64 | is($output->{version}, '0.03', 'version'); |
| 65 | is($output->{data}->{foundries}, '', 'Foundries'); |
| 66 | is($output->{data}->{layerInfos}, '', 'layerInfos'); |
| 67 | is($output->{data}->{stream}->[0]->[4], 's:Generation', 'data'); |
| 68 | is($output->{data}->{stream}->[3]->[2], 's:abbreviated', 'data'); |
| 69 | |
| 70 | $tokens->add('Malt', 'Dependency'); |
| 71 | |
| 72 | my $stream = $tokens->to_data->{data}->{stream}; |
| 73 | |
| 74 | # This is not a goot relation example |
| 75 | is($stream->[77]->[0], |
| 76 | '>:malt/d:pobj$<b>32<i>75', |
| 77 | 'Relation'); |
| 78 | is($stream->[100]->[0], '>:malt/d:dep$<b>32<i>101', 'relation'); |
| 79 | |
| 80 | $tokens->add('DeReKo', 'Structure', 'base-sentences-paragraphs-pagebreaks'); |
| 81 | |
| 82 | $stream = $tokens->to_data->{data}->{stream}; |
| 83 | |
| 84 | is($stream->[0]->[8], '<>:base/s:s$<b>64<i>8<i>123<i>19<b>2', 'Text starts with sentence'); |
| 85 | |
| 86 | $tokens->add('TreeTagger', 'Morpho'); |
| 87 | |
| 88 | $stream = $tokens->to_data->{data}->{stream}; |
| 89 | |
| 90 | is($stream->[20]->[4], 'tt/l:historian', 'Treetagger'); |
| 91 | is($stream->[20]->[5], 'tt/p:NNS', 'Treetagger'); |
| 92 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 93 | |
| 94 | my $koral = decode_json($tokens->to_json(0.4)); |
| 95 | |
Akron | 0d68a4b | 2019-11-13 15:42:11 +0100 | [diff] [blame] | 96 | my $link = $koral->{fields}->[6]; |
| 97 | |
Akron | 6bf3cc9 | 2019-02-07 12:11:20 +0100 | [diff] [blame] | 98 | is($link->{'@type'}, 'koral:field', 'attachement'); |
| 99 | is($link->{type}, 'type:attachement', 'attachement'); |
| 100 | is($link->{key}, 'externalLink', 'attachement'); |
| 101 | is($link->{value}, 'data:application/x.korap-link;title=Wikipedia,http://en.wikipedia.org/wiki/Generation_X', 'attachement'); |
| 102 | |
Akron | 4e1712c | 2019-02-04 22:29:37 +0100 | [diff] [blame] | 103 | done_testing; |
| 104 | __END__ |