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 | |
| 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 DRuKoLa-Files |
| 20 | |
| 21 | # New |
| 22 | # BBU/BLOG/83709_a_82384 |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 23 | my $path = catdir(dirname(__FILE__), '../corpus/CoRoLa/BBU/BLOG/83709_a_82384'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 24 | |
| 25 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 26 | ok($doc->parse, 'Parse document'); |
| 27 | |
| 28 | is($doc->text_sigle, 'BBU/BLOG/83709_a_82384', 'Correct text sigle'); |
| 29 | is($doc->doc_sigle, 'BBU/BLOG', 'Correct document sigle'); |
| 30 | is($doc->corpus_sigle, 'BBU', 'Correct corpus sigle'); |
| 31 | |
| 32 | my $meta = $doc->meta; |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 33 | is($meta->{T_title}, 'Schimbă vorba', 'Title'); |
| 34 | is($meta->{S_pub_place}, 'URL:http://www.bucurenci.ro', 'PubPlace'); |
| 35 | is($meta->{D_pub_date}, '20131005', 'Creation Date'); |
| 36 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 37 | is($meta->{T_author}, 'Dragoș Bucurenci', 'Author'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 38 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 39 | ok(!$meta->{A_publisher}, 'Publisher'); |
| 40 | ok(!$meta->{A_editor}, 'Editor'); |
| 41 | is($meta->{A_translator}, '[TRANSLATOR]', 'Translator'); |
| 42 | #is($meta->{S_text_type}, 'Autobiographie', 'Correct Text Type'); |
| 43 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 44 | # is($meta->{S_text_type_ref}, '', 'Correct Text Type Ref'); |
| 45 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 46 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 47 | ok(!$meta->{D_creation_date}, 'Creation Date'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 48 | |
| 49 | ok(!$meta->{pages}, 'Pages'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 50 | ok(!$meta->{A_file_edition_statement}, 'File Ed Statement'); |
| 51 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 52 | ok(!$meta->{A_reference}, 'Reference'); |
| 53 | is($meta->{S_language}, 'ro', 'Language'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 54 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 55 | #is($meta->{T_corpus_title}, 'Goethes Werke', 'Correct Corpus title'); |
| 56 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 57 | #is($meta->{T_corpus_author}, 'Goethe, Johann Wolfgang von', 'Correct Corpus author'); |
| 58 | #is($meta->{A_corpus_editor}, 'Trunz, Erich', 'Correct Corpus editor'); |
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_doc_title}, 'Goethe: Autobiographische Schriften II, (1817-1825, 1832)', |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 61 | # 'Correct Doc title'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 62 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 63 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 64 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 65 | |
| 66 | # Tokenization |
| 67 | use_ok('KorAP::XML::Tokenizer'); |
| 68 | |
| 69 | my ($token_base_foundry, $token_base_layer) = (qw/Base Tokens_conservative/); |
| 70 | |
| 71 | # Get tokenization |
| 72 | my $tokens = KorAP::XML::Tokenizer->new( |
| 73 | path => $doc->path, |
| 74 | doc => $doc, |
| 75 | foundry => $token_base_foundry, |
| 76 | layer => $token_base_layer, |
| 77 | name => 'tokens' |
| 78 | ); |
| 79 | ok($tokens, 'Token Object is fine'); |
| 80 | ok($tokens->parse, 'Token parsing is fine'); |
| 81 | |
| 82 | my $output = decode_json( $tokens->to_json ); |
| 83 | |
| 84 | ## Base |
| 85 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'); |
| 86 | ok($tokens->add('DRuKoLa', 'Morpho'), 'Add Drukola'); |
| 87 | |
| 88 | $output = $tokens->to_data; |
| 89 | |
| 90 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs drukola drukola/morpho', 'Foundries'); |
| 91 | |
| 92 | is($output->{data}->{layerInfos}, 'dereko/s=spans drukola/l=tokens drukola/m=tokens drukola/p=tokens', 'layerInfos'); |
| 93 | |
| 94 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 95 | |
| 96 | like($token, qr!drukola/l:la!, 'data'); |
| 97 | like($token, qr!drukola/m:msd:Sp!, 'data'); |
| 98 | like($token, qr!drukola/p:ADPOSITION!, 'data'); |
| 99 | |
| 100 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 101 | |
| 102 | like($token, qr!i:vorba!, 'data'); |
| 103 | like($token, qr!drukola/l:vorbă!, 'data'); |
| 104 | like($token, qr!drukola/m:case:Ncfsry!, 'data'); |
| 105 | like($token, qr!drukola/m:definiteness:yes!, 'data'); |
| 106 | like($token, qr!drukola/m:gender:feminine!, 'data'); |
| 107 | like($token, qr!drukola/p:NOUN!, 'data'); |
| 108 | |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 109 | |
| 110 | # New |
| 111 | # BBU2/BLOG/83709_a_82384 |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 112 | $path = catdir(dirname(__FILE__), '../corpus/CoRoLa/BBU2/Blog/83701_a_82376'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 113 | |
| 114 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 115 | ok($doc->parse, 'Parse document'); |
| 116 | |
| 117 | $meta = $doc->meta; |
| 118 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 119 | ok(!exists $meta->{T_doc_title}, 'No doc title'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 120 | ok(!exists $meta->{translator}, 'No translator'); |
| 121 | |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 122 | ok(!exists $meta->{K_text_class}, 'No translator'); |
Akron | a7d0e9f | 2017-02-03 14:36:21 +0100 | [diff] [blame] | 123 | |
| 124 | |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 125 | |
| 126 | $path = catdir(dirname(__FILE__), '../corpus/CoRoLa/Corola-Journal/-/247_a_537'); |
| 127 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 128 | ok($doc->parse, 'Parse document'); |
| 129 | |
| 130 | $meta = $doc->meta; |
| 131 | is($meta->text_sigle, 'Corola-Journal/-/247_a_537', 'Text Sigle'); |
| 132 | is($meta->doc_sigle, 'Corola-Journal/-', 'Doc Sigle'); |
| 133 | is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 134 | is($meta->{K_text_class}->[0], 'Sport', 'Text class'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 135 | |
| 136 | |
| 137 | $path = catdir(dirname(__FILE__), '../corpus/CoRoLa/Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI/326_a_562'); |
| 138 | ok($doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 139 | ok($doc->parse, 'Parse document'); |
| 140 | |
| 141 | $meta = $doc->meta; |
| 142 | is($meta->text_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI/326_a_562', 'Text Sigle'); |
| 143 | is($meta->doc_sigle, 'Corola-Journal/COLEGIUL NATIONAL „OCTAV BANCILA“ - IASI', 'Doc Sigle'); |
| 144 | is($meta->corpus_sigle, 'Corola-Journal', 'Corpus Sigle'); |
Akron | 5eb3aa0 | 2019-01-25 18:30:47 +0100 | [diff] [blame] | 145 | is($meta->{T_title}, 'APOGEUL ARHITECTURĂ ȘI DESIGN', 'Title'); |
Akron | 3887301 | 2017-02-06 20:27:37 +0100 | [diff] [blame] | 146 | |
Akron | c388150 | 2017-01-20 14:36:37 +0100 | [diff] [blame] | 147 | done_testing; |
| 148 | __END__ |