Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
Akron | fab17d3 | 2020-07-31 14:38:29 +0200 | [diff] [blame] | 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 11 | use Benchmark qw/:hireswallclock/; |
| 12 | |
| 13 | my $t = Benchmark->new; |
| 14 | |
| 15 | use utf8; |
| 16 | use lib 'lib', '../lib'; |
| 17 | |
| 18 | use File::Basename 'dirname'; |
| 19 | use File::Spec::Functions 'catdir'; |
| 20 | |
| 21 | use_ok('KorAP::XML::Krill'); |
| 22 | |
| 23 | # This will Check DRuKoLa-Files |
| 24 | |
| 25 | # New |
| 26 | # BBU/BLOG/83709_a_82384 |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 27 | my $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU','BLOG','83709_a_82384'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 28 | |
| 29 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 30 | ok($doc->parse, 'Parse document'); |
| 31 | |
| 32 | is($doc->text_sigle, 'BBU/BLOG/83709_a_82384', 'Correct text sigle'); |
| 33 | is($doc->doc_sigle, 'BBU/BLOG', 'Correct document sigle'); |
| 34 | is($doc->corpus_sigle, 'BBU', 'Correct corpus sigle'); |
| 35 | |
| 36 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 37 | is($meta->{T_title}, 'Schimbă vorba', 'Title'); |
| 38 | is($meta->{S_pub_place}, 'URL:http://www.bucurenci.ro', 'PubPlace'); |
| 39 | is($meta->{D_pub_date}, '20131005', 'Creation Date'); |
| 40 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 41 | is($meta->{T_author}, 'Dragoș Bucurenci', 'Author'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 42 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 43 | ok(!$meta->{A_publisher}, 'Publisher'); |
| 44 | ok(!$meta->{A_editor}, 'Editor'); |
| 45 | is($meta->{A_translator}, '[TRANSLATOR]', 'Translator'); |
Akron | af18edb | 2024-07-26 12:11:48 +0200 | [diff] [blame^] | 46 | ok(!$meta->{T_translator}, 'Translator'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 47 | #is($meta->{S_text_type}, 'Autobiographie', 'Correct Text Type'); |
| 48 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 49 | # is($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 | ok(!$meta->{D_creation_date}, 'Creation Date'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [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}, 'ro', 'Language'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 59 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 60 | #is($meta->{T_corpus_title}, 'Goethes Werke', 'Correct Corpus title'); |
| 61 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 62 | #is($meta->{T_corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author'); |
| 63 | #is($meta->{A_corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 64 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 65 | #is($meta->{T_doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 66 | # 'Correct Doc title'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 67 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 68 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 69 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 70 | |
| 71 | # Tokenization |
| 72 | use_ok('KorAP::XML::Tokenizer'); |
| 73 | |
| 74 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/); |
| 75 | |
| 76 | # Get tokenization |
| 77 | my $tokens = KorAP::XML::Tokenizer->new( |
| 78 | path => $doc->path, |
| 79 | doc => $doc, |
| 80 | foundry => $token_base_foundry, |
| 81 | layer => $token_base_layer, |
| 82 | name => 'tokens' |
| 83 | ); |
| 84 | ok($tokens, 'Token Object is fine'); |
| 85 | ok($tokens->parse, 'Token parsing is fine'); |
| 86 | |
| 87 | my $output = decode_json( $tokens->to_json ); |
| 88 | |
| 89 | ## Base |
| 90 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'); |
| 91 | ok($tokens->add('DRuKoLa', 'Morpho'), 'Add Drukola'); |
| 92 | |
| 93 | $output = $tokens->to_data; |
| 94 | |
| 95 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs drukola drukola/morpho', 'Foundries'); |
| 96 | |
| 97 | is($output->{data}->{layerInfos}, 'dereko/s=spans drukola/l=tokens drukola/m=tokens drukola/p=tokens', 'layerInfos'); |
| 98 | |
| 99 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 100 | |
| 101 | like($token, qr!drukola/l:la!, 'data'); |
| 102 | like($token, qr!drukola/m:msd:Sp!, 'data'); |
| 103 | like($token, qr!drukola/p:ADPOSITION!, 'data'); |
| 104 | |
| 105 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 106 | |
| 107 | like($token, qr!i:vorba!, 'data'); |
| 108 | like($token, qr!drukola/l:vorbă!, 'data'); |
| 109 | like($token, qr!drukola/m:case:Ncfsry!, 'data'); |
| 110 | like($token, qr!drukola/m:definiteness:yes!, 'data'); |
| 111 | like($token, qr!drukola/m:gender:feminine!, 'data'); |
| 112 | like($token, qr!drukola/p:NOUN!, 'data'); |
| 113 | |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 114 | |
| 115 | # New |
| 116 | # BBU2/BLOG/83709_a_82384 |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 117 | $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU2','Blog','83701_a_82376'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 118 | |
| 119 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 120 | ok($doc->parse, 'Parse document'); |
| 121 | |
| 122 | $meta = $doc->meta; |
| 123 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 124 | ok(!exists $meta->{T_doc_title}, 'No doc title'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 125 | ok(!exists $meta->{translator}, 'No translator'); |
| 126 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 127 | ok(!exists $meta->{K_text_class}, 'No translator'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 128 | |
| 129 | |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 130 | |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 131 | $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','Corola-Journal','-','247_a_537'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 132 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 133 | ok($doc->parse, 'Parse document'); |
| 134 | |
| 135 | $meta = $doc->meta; |
| 136 | is($meta->text_sigle, 'Corola-Journal/-/247_a_537', 'Text Sigle'); |
| 137 | is($meta->doc_sigle, 'Corola-Journal/-', 'Doc Sigle'); |
| 138 | is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 139 | is($meta->{K_text_class}->[0], 'Sport', 'Text class'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 140 | |
| 141 | |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 142 | $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','Corola-Journal','COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI','326_a_562'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 143 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 144 | ok($doc->parse, 'Parse document'); |
| 145 | |
| 146 | $meta = $doc->meta; |
| 147 | is($meta->text_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI/326_a_562', 'Text Sigle'); |
| 148 | is($meta->doc_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI', 'Doc Sigle'); |
| 149 | is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 150 | is($meta->{T_title}, 'APOGEUL ARHITECTURĂ ȘI DESIGN', 'Title'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 151 | |
Akron | af18edb | 2024-07-26 12:11:48 +0200 | [diff] [blame^] | 152 | |
| 153 | |
| 154 | # Old translator behaviour: |
| 155 | our %ENV; |
| 156 | $ENV{K2K_TRANSLATOR_TEXT} = 1; |
| 157 | $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU','BLOG','83709_a_82384'); |
| 158 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 159 | ok($doc->parse, 'Parse document'); |
| 160 | |
| 161 | is($doc->text_sigle, 'BBU/BLOG/83709_a_82384', 'Correct text sigle'); |
| 162 | $meta = $doc->meta; |
| 163 | is($meta->{T_translator}, '[TRANSLATOR]', 'Translator'); |
| 164 | ok(!$meta->{A_translator}, 'Translator'); |
| 165 | |
| 166 | |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 167 | done_testing; |
| 168 | __END__ |