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'); |
| 46 | #is($meta->{S_text_type}, 'Autobiographie', 'Correct Text Type'); |
| 47 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 48 | # is($meta->{S_text_type_ref}, '', 'Correct Text Type Ref'); |
| 49 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 50 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 51 | ok(!$meta->{D_creation_date}, 'Creation Date'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 52 | |
| 53 | ok(!$meta->{pages}, 'Pages'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 54 | ok(!$meta->{A_file_edition_statement}, 'File Ed Statement'); |
| 55 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 56 | ok(!$meta->{A_reference}, 'Reference'); |
| 57 | is($meta->{S_language}, 'ro', 'Language'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 58 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 59 | #is($meta->{T_corpus_title}, 'Goethes Werke', 'Correct Corpus title'); |
| 60 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 61 | #is($meta->{T_corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author'); |
| 62 | #is($meta->{A_corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 63 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 64 | #is($meta->{T_doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 65 | # 'Correct Doc title'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 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 | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 69 | |
| 70 | # Tokenization |
| 71 | use_ok('KorAP::XML::Tokenizer'); |
| 72 | |
| 73 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/); |
| 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 | ## Base |
| 89 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'); |
| 90 | ok($tokens->add('DRuKoLa', 'Morpho'), 'Add Drukola'); |
| 91 | |
| 92 | $output = $tokens->to_data; |
| 93 | |
| 94 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs drukola drukola/morpho', 'Foundries'); |
| 95 | |
| 96 | is($output->{data}->{layerInfos}, 'dereko/s=spans drukola/l=tokens drukola/m=tokens drukola/p=tokens', 'layerInfos'); |
| 97 | |
| 98 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 99 | |
| 100 | like($token, qr!drukola/l:la!, 'data'); |
| 101 | like($token, qr!drukola/m:msd:Sp!, 'data'); |
| 102 | like($token, qr!drukola/p:ADPOSITION!, 'data'); |
| 103 | |
| 104 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 105 | |
| 106 | like($token, qr!i:vorba!, 'data'); |
| 107 | like($token, qr!drukola/l:vorbă!, 'data'); |
| 108 | like($token, qr!drukola/m:case:Ncfsry!, 'data'); |
| 109 | like($token, qr!drukola/m:definiteness:yes!, 'data'); |
| 110 | like($token, qr!drukola/m:gender:feminine!, 'data'); |
| 111 | like($token, qr!drukola/p:NOUN!, 'data'); |
| 112 | |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 113 | |
| 114 | # New |
| 115 | # BBU2/BLOG/83709_a_82384 |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 116 | $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','BBU2','Blog','83701_a_82376'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 117 | |
| 118 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 119 | ok($doc->parse, 'Parse document'); |
| 120 | |
| 121 | $meta = $doc->meta; |
| 122 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 123 | ok(!exists $meta->{T_doc_title}, 'No doc title'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 124 | ok(!exists $meta->{translator}, 'No translator'); |
| 125 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 126 | ok(!exists $meta->{K_text_class}, 'No translator'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 127 | |
| 128 | |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 129 | |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 130 | $path = catdir(dirname(__FILE__), 'corpus','CoRoLa','Corola-Journal','-','247_a_537'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 131 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 132 | ok($doc->parse, 'Parse document'); |
| 133 | |
| 134 | $meta = $doc->meta; |
| 135 | is($meta->text_sigle, 'Corola-Journal/-/247_a_537', 'Text Sigle'); |
| 136 | is($meta->doc_sigle, 'Corola-Journal/-', 'Doc Sigle'); |
| 137 | is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 138 | is($meta->{K_text_class}->[0], 'Sport', 'Text class'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 139 | |
| 140 | |
Akron | 414ec95 | 2020-08-03 15:48:43 +0200 | [diff] [blame] | 141 | $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] | 142 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 143 | ok($doc->parse, 'Parse document'); |
| 144 | |
| 145 | $meta = $doc->meta; |
| 146 | is($meta->text_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI/326_a_562', 'Text Sigle'); |
| 147 | is($meta->doc_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI', 'Doc Sigle'); |
| 148 | is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 149 | is($meta->{T_title}, 'APOGEUL ARHITECTURĂ ȘI DESIGN', 'Title'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 150 | |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 151 | done_testing; |
| 152 | __END__ |