Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [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 | # This will check preliminary HNC-Files |
| 20 | |
| 21 | # HNC/DOC00001/00001 |
| 22 | my $path = catdir(dirname(__FILE__), '../corpus/HNC/DOC00001/00001'); |
| 23 | |
| 24 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 25 | ok($doc->parse, 'Parse document'); |
| 26 | |
| 27 | is($doc->text_sigle, 'HNC/DOC00001/00001', 'Correct text sigle'); |
| 28 | is($doc->doc_sigle, 'HNC/DOC00001', 'Correct document sigle'); |
| 29 | is($doc->corpus_sigle, 'HNC', 'Correct corpus sigle'); |
| 30 | |
| 31 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 32 | is($meta->{T_title}, 'GNU Free Documentation License', 'Title'); |
| 33 | is($meta->{S_pub_place}, 'H_PUBPLACE', 'PubPlace'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 34 | |
| 35 | # Defined on document level as |
| 36 | # idsHeader > fileDesc > publicationStmt > pubDate == 2005/08/16 |
| 37 | # idsHeader > fileDesc > biblFull > publicationStmt > pubDate == 2003/07/08-2014/05/03 |
| 38 | # idsHeader > fileDesc > biblFull > publicationStmt > sourceDesc > biblStruct > monogr > imprint > pubDate == 2003/07/08-2014/05/03 |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 39 | # is($meta->{D_pub_date}, '20030708', 'Publication date'); |
| 40 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 41 | is($meta->{T_author}, 'Addbot', 'Author'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 42 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 43 | is($meta->{A_publisher}, 'H_PUBLISHER', 'Publisher'); |
| 44 | ok(!$meta->{A_editor}, 'Editor'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 45 | ok(!$meta->{translator}, 'Translator'); |
| 46 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 47 | ok(!$meta->{S_text_type}, 'Correct Text Type'); |
| 48 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 49 | ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref'); |
| 50 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 51 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 52 | is($meta->{D_creation_date}, '20130302', 'Creation Date'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 53 | |
| 54 | ok(!$meta->{pages}, 'Pages'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 55 | ok(!$meta->{A_file_edition_statement}, 'File Ed Statement'); |
| 56 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 57 | ok(!$meta->{A_reference}, 'Reference'); |
| 58 | is($meta->{S_language}, 'hu', 'Language'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 59 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 60 | ok(!$meta->{T_corpus_title}, 'Correct Corpus title'); |
| 61 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 62 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 63 | ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 64 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 65 | is($meta->{T_doc_title}, 'MNSZ hivatalos korpusz: Wikipédia cikkek', 'Correct Doc title'); |
| 66 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 67 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 68 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
Akron | c893ac3 | 2018-07-18 17:59:02 +0200 | [diff] [blame] | 69 | |
| 70 | # Tokenization |
| 71 | use_ok('KorAP::XML::Tokenizer'); |
| 72 | |
| 73 | my ($token_base_foundry, $token_base_layer) = (qw/HNC Morpho/); |
| 74 | |
| 75 | # Get tokenization |
| 76 | my $tokens = KorAP::XML::Tokenizer->new( |
| 77 | path => $doc->path, |
| 78 | doc => $doc, |
| 79 | foundry => $token_base_foundry, |
| 80 | layer => $token_base_layer, |
| 81 | name => 'tokens' |
| 82 | ); |
| 83 | ok($tokens, 'Token Object is fine'); |
| 84 | ok($tokens->parse, 'Token parsing is fine'); |
| 85 | |
| 86 | my $output = decode_json( $tokens->to_json ); |
| 87 | |
| 88 | is($output->{data}->{stream}->[0]->[1], '<>:base/s:t$<b>64<i>0<i>4368<i>577<b>0', 't'); |
| 89 | is($output->{data}->{stream}->[0]->[3], 'i:addbot', 't'); |
| 90 | |
| 91 | |
| 92 | ## Base |
| 93 | ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'), 'DeReKo'); |
| 94 | ok($tokens->add('HNC', 'Morpho'), 'Add HNC Morphology'); |
| 95 | |
| 96 | $output = $tokens->to_data; |
| 97 | |
| 98 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs hnc hnc/morpho', 'Foundries'); |
| 99 | |
| 100 | is($output->{data}->{layerInfos}, 'dereko/s=spans hnc/l=tokens hnc/m=tokens hnc/p=tokens', 'layerInfos'); |
| 101 | |
| 102 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 103 | |
| 104 | like($token, qr!hnc/l:free!, 'data'); |
| 105 | like($token, qr!hnc/m:compound:n!, 'data'); |
| 106 | like($token, qr!hnc/m:hyphenated:n!, 'data'); |
| 107 | like($token, qr!hnc/m:mboundary:free!, 'data'); |
| 108 | like($token, qr!hnc/m:morphemes:ZERO::NOM!, 'data'); |
| 109 | like($token, qr!hnc/m:stem:free::FN!, 'data'); |
| 110 | like($token, qr!hnc/p:FN\.NOM!, 'data'); |
| 111 | like($token, qr!i:free!, 'data'); |
| 112 | like($token, qr!s:Free!, 'data'); |
| 113 | |
| 114 | $token = join('||', @{$output->{data}->{stream}->[30]}); |
| 115 | |
| 116 | like($token, qr!hnc/l:tervez!, 'data'); |
| 117 | like($token, qr!hnc/m:compound:n!, 'data'); |
| 118 | like($token, qr!hnc/m:hyphenated:n!, 'data'); |
| 119 | like($token, qr!hnc/m:mboundary:tervez\+ett!, 'data'); |
| 120 | like($token, qr!hnc/m:morphemes:ett::_MIB ZERO::NOM!, 'data'); |
| 121 | like($token, qr!hnc/m:stem:tervez::IGE!, 'data'); |
| 122 | like($token, qr!hnc/p:IGE\._MIB\.NOM!, 'data'); |
| 123 | like($token, qr!i:tervezett!, 'data'); |
| 124 | like($token, qr!s:tervezett!, 'data'); |
| 125 | |
| 126 | done_testing; |
| 127 | __END__ |