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'); |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 59 | is($meta->{A_reference}, 'ATZ - Automobiltechnische Zeitschrift, Januar 2007, Nr. 109(1), S. 10-15 - Theuerkauf, H.; Schmidt, M.: Ein neues Energiemanagement-Konzept für das elektrische Bordnetz (DOI:10.1007/BF03221854)', 'Reference'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 60 | is($meta->{S_language}, 'de', 'Language'); |
| 61 | |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 62 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 63 | |
| 64 | |
| 65 | is($meta->{T_corpus_title}, 'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus: ATZ - Automobiltechnische Zeitschrift, 2007', 'Correct Corpus title'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 66 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 67 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 68 | is($meta->{A_corpus_editor}, 'Prof. Dr. Christian Fandrych, Leipzig University; Jun.-Prof. Dr. Antje Heine', 'Correct Corpus editor'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 69 | |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 70 | is($meta->{T_doc_title}, 'ATZ - Automobiltechnische Zeitschrift, Januar 2007', 'Correct Doc title'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 71 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 72 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 73 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 74 | |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame] | 75 | # Gingko Metadata |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 76 | is($meta->{S_gingko_genre_main}, 'wissenschaftlich'); |
| 77 | is($meta->{S_gingko_genre_sub}, 'wissenschaftlich'); |
| 78 | is($meta->{T_gingko_source}, 'ATZ - Automobiltechnische Zeitschrift'); |
| 79 | is($meta->{S_gingko_source_short}, 'ATZ'); |
| 80 | is($meta->{S_gingko_lemma_corr}, 'no'); |
| 81 | is($meta->{T_gingko_collection}, 'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus'); |
| 82 | is($meta->{S_gingko_collection_short}, 'Gingko'); |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 83 | is($meta->{A_gingko_article_DOI}, 'data:application/x.korap-link;title=doi%3A10.1007%2FBF03221854,https%3A%2F%2Fdoi.org%2F10.1007%2FBF03221854', 'Gingko Article DOI'); |
| 84 | is($meta->{I_gingko_text_tokens}, '2191', 'Gingko Text Tokens'); |
| 85 | is($meta->{A_internal_link}, 'data:application/x.korap-link;title=IDS%20webpage%20on%20Gingko%20in%20the%20DeReKo%20archive,https%3A%2F%2Fwww.ids-mannheim.de%2Fdigspra%2Fkl%2Fprojekte%2Fkorpora%2Farchiv-1%2Fgingko%2F', 'Gingko Internal Link'); |
Akron | 2a4c4ce | 2022-02-07 19:51:00 +0100 | [diff] [blame] | 86 | is($meta->{A_external_link}, 'data:application/x.korap-link;title=Gingko-Webseite%20an%20der%20Universit%C3%A4t%20Leipzig,http%3A%2F%2Fwww.uni-leipzig.de%2Fgingko%2F', 'Gingko External Link'); |
Akron | 8c85e9f | 2022-01-03 16:27:10 +0100 | [diff] [blame] | 87 | |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 88 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 89 | # Tokenization |
| 90 | use_ok('KorAP::XML::Tokenizer'); |
| 91 | |
| 92 | my ($token_base_foundry, $token_base_layer) = (qw/Gingko Morpho/); |
| 93 | |
| 94 | # Get tokenization |
| 95 | my $tokens = KorAP::XML::Tokenizer->new( |
| 96 | path => $doc->path, |
| 97 | doc => $doc, |
| 98 | foundry => $token_base_foundry, |
| 99 | layer => $token_base_layer, |
| 100 | name => 'tokens' |
| 101 | ); |
| 102 | ok($tokens, 'Token Object is fine'); |
| 103 | ok($tokens->parse, 'Token parsing is fine'); |
| 104 | |
| 105 | my $output = decode_json( $tokens->to_json ); |
| 106 | |
| 107 | ## Base |
| 108 | ok($tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs')); |
| 109 | ok($tokens->add('Gingko', 'Morpho'), 'Add Gingko'); |
| 110 | |
| 111 | $output = $tokens->to_data; |
| 112 | |
| 113 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs gingko gingko/morpho', 'Foundries'); |
| 114 | |
| 115 | is($output->{data}->{layerInfos}, 'dereko/s=spans gingko/l=tokens gingko/p=tokens', 'layerInfos'); |
| 116 | |
| 117 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 118 | |
| 119 | # Unknown |
| 120 | unlike($token, qr!gingko/l!, 'data'); |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame] | 121 | like($token, qr!gingko/p:NN!, 'data'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 122 | |
| 123 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 124 | |
| 125 | like($token, qr!i:heutige!, 'data'); |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame] | 126 | like($token, qr!gingko/p:ADJA!, 'data'); |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 127 | like($token, qr!gingko/l:heutig!, 'data'); |
| 128 | |
Akron | 8ad06c4 | 2022-01-11 17:07:49 +0100 | [diff] [blame] | 129 | # Check Gingko meta in Koral |
Akron | 41e6c8b | 2021-10-14 20:22:18 +0200 | [diff] [blame] | 130 | my $koral = decode_json($tokens->to_json(0.4)); |
| 131 | |
| 132 | my $test = 0; |
| 133 | foreach (@{$koral->{fields}}) { |
| 134 | if ($_->{key} eq 'gingkoGenreMain') { |
| 135 | is($_->{'type'},'type:string'); |
| 136 | is($_->{'value'},'wissenschaftlich'); |
| 137 | $test++; |
| 138 | } |
| 139 | elsif ($_->{key} eq 'gingkoCollection') { |
| 140 | is($_->{'type'},'type:text'); |
| 141 | is($_->{'value'},'Gingko - Geschriebenes Ingenieurwissenschaftliches Korpus'); |
| 142 | $test++; |
| 143 | }; |
| 144 | }; |
| 145 | |
| 146 | is($test,2); |
| 147 | |
Akron | abb3690 | 2021-10-11 15:51:06 +0200 | [diff] [blame] | 148 | done_testing; |
| 149 | __END__ |
| 150 | |