Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More; |
| 4 | use Data::Dumper; |
| 5 | use JSON::XS; |
| 6 | |
| 7 | if ($ENV{SKIP_REAL}) { |
| 8 | plan skip_all => 'Skip real tests'; |
| 9 | }; |
| 10 | |
| 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 Gingko-Files |
| 24 | |
| 25 | # New |
| 26 | # ATZ07/JAN/00001 |
| 27 | my $path = catdir(dirname(__FILE__), 'corpus','Gingko', 'ATZ07','JAN','00001'); |
| 28 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 29 | ok(my $doc = KorAP::XML::Krill->new( |
| 30 | path => $path . '/', |
| 31 | meta_type => 'Gingko' |
| 32 | ), 'Load Korap::Document'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 33 | ok($doc->parse, 'Parse document'); |
| 34 | |
| 35 | is($doc->text_sigle, 'ATZ07/JAN/00001', 'Correct text sigle'); |
| 36 | is($doc->doc_sigle, 'ATZ07/JAN', 'Correct document sigle'); |
| 37 | is($doc->corpus_sigle, 'ATZ07', 'Correct corpus sigle'); |
| 38 | |
| 39 | my $meta = $doc->meta; |
| 40 | is($meta->{T_title}, 'Ein neues Energiemanagement-Konzept für das elektrische Bordnetz', 'Title'); |
| 41 | is($meta->{S_pub_place}, 'Wiesbaden', 'PubPlace'); |
| 42 | is($meta->{D_pub_date}, '20070000', 'Creation Date'); |
| 43 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 44 | is($meta->{T_author}, 'Theuerkauf, Heinz; Schmidt, Matthias', 'Author'); |
| 45 | |
| 46 | is($meta->{A_publisher}, 'Springer Fachmedien GmbH', 'Publisher'); |
| 47 | ok(!$meta->{A_editor}, 'Editor'); |
| 48 | ok(!$meta->{A_translator}, 'Translator'); |
| 49 | is($meta->{S_text_type}, 'Zeitschrift: Fachzeitschrift', 'Correct Text Type'); |
| 50 | is($meta->{S_text_type_art}, 'Fachartikel', 'Correct Text Type Art'); |
| 51 | is($meta->{S_text_type_ref}, 'Fachzeitschrift', 'Correct Text Type Ref'); |
| 52 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 53 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 54 | ok(!$meta->{D_creation_date}, 'Creation Date'); |
| 55 | |
| 56 | ok(!$meta->{pages}, 'Pages'); |
| 57 | ok(!$meta->{A_file_edition_statement}, 'File Ed Statement'); |
| 58 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 59 | is($meta->{A_reference}, 'ATZ - Automobiltechnische Zeitschrift, Januar 2007, Nr.109, S. 10-15 - Theuerkauf, H.; Schmidt, M.: Ein neues Energiemanagement-Konzept für das elektrische Bordnetz', 'Reference'); |
| 60 | is($meta->{S_language}, 'de', 'Language'); |
| 61 | |
| 62 | is($meta->{T_corpus_title}, 'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus', 'Correct Corpus title'); |
| 63 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 64 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 65 | is($meta->{A_corpus_editor}, 'Christian Fandrych', 'Correct Corpus editor'); |
| 66 | |
| 67 | is($meta->{T_doc_title}, 'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus', 'Correct Doc title'); |
| 68 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 69 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 70 | is($meta->{A_doc_editor}, 'Prof. Dr. Christian Fandrych, Leipzig University', 'Correct Doc editor'); |
| 71 | |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame^] | 72 | # Gingko Metadata |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 73 | is($meta->{S_gingko_genre_main}, 'wissenschaftlich'); |
| 74 | is($meta->{S_gingko_genre_sub}, 'wissenschaftlich'); |
| 75 | is($meta->{T_gingko_source}, 'ATZ - Automobiltechnische Zeitschrift'); |
| 76 | is($meta->{S_gingko_source_short}, 'ATZ'); |
| 77 | is($meta->{S_gingko_lemma_corr}, 'no'); |
| 78 | is($meta->{T_gingko_collection}, 'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus'); |
| 79 | is($meta->{S_gingko_collection_short}, 'Gingko'); |
| 80 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 81 | # Tokenization |
| 82 | use_ok('KorAP::XML::Tokenizer'); |
| 83 | |
| 84 | my ($token_base_foundry, $token_base_layer) = (qw/Gingko Morpho/); |
| 85 | |
| 86 | # Get tokenization |
| 87 | my $tokens = KorAP::XML::Tokenizer->new( |
| 88 | path => $doc->path, |
| 89 | doc => $doc, |
| 90 | foundry => $token_base_foundry, |
| 91 | layer => $token_base_layer, |
| 92 | name => 'tokens' |
| 93 | ); |
| 94 | ok($tokens, 'Token Object is fine'); |
| 95 | ok($tokens->parse, 'Token parsing is fine'); |
| 96 | |
| 97 | my $output = decode_json( $tokens->to_json ); |
| 98 | |
| 99 | ## Base |
| 100 | ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs')); |
| 101 | ok($tokens->add('Gingko', 'Morpho'), 'Add Gingko'); |
| 102 | |
| 103 | $output = $tokens->to_data; |
| 104 | |
| 105 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs gingko gingko/morpho', 'Foundries'); |
| 106 | |
| 107 | is($output->{data}->{layerInfos}, 'dereko/s=spans gingko/l=tokens gingko/p=tokens', 'layerInfos'); |
| 108 | |
| 109 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 110 | |
| 111 | # Unknown |
| 112 | unlike($token, qr!gingko/l!, 'data'); |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame^] | 113 | like($token, qr!gingko/p:NN!, 'data'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 114 | |
| 115 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 116 | |
| 117 | like($token, qr!i:heutige!, 'data'); |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame^] | 118 | like($token, qr!gingko/p:ADJA!, 'data'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 119 | like($token, qr!gingko/l:heutig!, 'data'); |
| 120 | |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame^] | 121 | # Check Gingko meta in Koral |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 122 | my $koral = decode_json($tokens->to_json(0.4)); |
| 123 | |
| 124 | my $test = 0; |
| 125 | foreach (@{$koral->{fields}}) { |
| 126 | if ($_->{key} eq 'gingkoGenreMain') { |
| 127 | is($_->{'type'},'type:string'); |
| 128 | is($_->{'value'},'wissenschaftlich'); |
| 129 | $test++; |
| 130 | } |
| 131 | elsif ($_->{key} eq 'gingkoCollection') { |
| 132 | is($_->{'type'},'type:text'); |
| 133 | is($_->{'value'},'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus'); |
| 134 | $test++; |
| 135 | }; |
| 136 | }; |
| 137 | |
| 138 | is($test,2); |
| 139 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 140 | done_testing; |
| 141 | __END__ |
| 142 | |