Akron | 24ad3c0 | 2024-06-03 12:38:20 +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 KED-Files - especially regarding Xenodata |
| 24 | |
| 25 | my $path = catdir(dirname(__FILE__), 'corpus','KED','KLX','03212'); |
| 26 | |
| 27 | ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document'); |
| 28 | ok($doc->parse, 'Parse document'); |
| 29 | |
| 30 | is($doc->text_sigle, 'KED/KLX/03212', 'Correct text sigle'); |
| 31 | is($doc->doc_sigle, 'KED/KLX', 'Correct document sigle'); |
| 32 | is($doc->corpus_sigle, 'KED', 'Correct corpus sigle'); |
| 33 | |
| 34 | my $meta = $doc->meta; |
| 35 | is($meta->{T_title}, 'Flöhe', 'Title'); |
| 36 | is($meta->{S_pub_place}, 'klexikon.zum.de', 'PubPlace'); |
| 37 | is($meta->{D_pub_date}, '20230309', 'Creation Date'); |
| 38 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 39 | ok(!$meta->{T_author}, 'No author'); |
| 40 | |
| 41 | is($meta->{A_publisher}, 'klexikon.zum.de', 'Publisher'); |
| 42 | ok(!$meta->{A_editor}, 'Editor'); |
| 43 | ok(!$meta->{A_translator}, 'Translator'); |
| 44 | is($meta->{S_text_type}, 'Webtext:Lexikonartikel', 'Correct Text Type'); |
| 45 | is($meta->{S_text_type_art}, 'Lexikonartikel', 'Correct Text Type Art'); |
| 46 | is($meta->{S_text_type_ref}, 'Webtext', 'Correct Text Type Ref'); |
| 47 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 48 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 49 | is($meta->{D_creation_date}, '20230309', 'Creation Date'); |
| 50 | |
| 51 | ok(!$meta->{pages}, 'Pages'); |
| 52 | ok(!$meta->{A_file_edition_statement}, 'File Ed Statement'); |
| 53 | ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement'); |
| 54 | is($meta->{A_reference}, 'Flöhe, In: Klexikon (Online) - URL:https://web.archive.org/web/20230309105908/https://klexikon.zum.de/wiki/Fl%C3%B6he, 2023', 'Reference'); |
| 55 | # is($meta->{S_language}, 'de', 'Language'); |
| 56 | |
| 57 | is($meta->{T_corpus_title}, 'Korpus Einfaches Deutsch', 'Correct Corpus title'); |
| 58 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 59 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 60 | is($meta->{A_corpus_editor},'Daniel Jach, Shanghai Normal University, China', 'Correct Corpus editor'); |
| 61 | |
| 62 | is($meta->{T_doc_title}, 'Korpus Einfaches Deutsch: Klexikon (Online)', 'Correct Doc title'); |
| 63 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 64 | ok(!$meta->{T_doc_author}, 'Correct Doc author'); |
| 65 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
| 66 | |
| 67 | is($meta->{'A_text_external_link'}, 'data:application/x.korap-link;title=link%20to%20source,https%3A%2F%2Fweb.archive.org%2Fweb%2F20230309105908%2Fhttps%3A%2F%2Fklexikon.zum.de%2Fwiki%2FFl%25C3%25B6he','External link'); |
| 68 | |
| 69 | is($meta->{'A_corpus_external_link'}, 'data:application/x.korap-link;title=link%20to%20KED%20website,https%3A%2F%2Fdaniel-jach.github.io%2Fsimple-german%2Fsimple-german.html','external link'); |
| 70 | |
| 71 | is($meta->{'A_KED.topicLabel'}, 'Gesundheit und Krankheit', 'Xenodata'); |
| 72 | is($meta->{'A_KED.nToksSentMd'}, '11.0', 'Xenodata'); |
| 73 | is($meta->{'A_KED.nToks'}, '308', 'Xenodata'); |
| 74 | is($meta->{'A_KED.nPunct1kTks'}, '129.87', 'Xenodata'); |
| 75 | is($meta->{'A_KED.strtgyLabel'}, "Erkl\x{e4}ren", 'Xenodata'); |
| 76 | is($meta->{'A_KED.rcpntLabel'}, 'Kinder', 'Xenodata'); |
| 77 | is($meta->{'A_KED.nSent'}, '28', 'Xenodata'); |
| 78 | is($meta->{'A_KED.nTyps'}, '188', 'Xenodata'); |
| 79 | is($meta->{'A_KED.txttypLabel'}, 'Lexikonartikel', 'Xenodata'); |
| 80 | is($meta->{'S_KED.cover4Herder'}, '0.65', 'Xenodata'); |
| 81 | is($meta->{'S_KED.cover2Herder'}, '0.61', 'Xenodata'); |
| 82 | is($meta->{'S_KED.cover1Herder'}, '0.58', 'Xenodata'); |
| 83 | is($meta->{'S_KED.nPara'}, '5', 'Xenodata'); |
| 84 | is($meta->{'S_KED.cover3Herder'}, '0.62', 'Xenodata'); |
| 85 | is($meta->{'S_KED.cover5Herder'}, '0.67', 'Xenodata'); |
| 86 | is_deeply($meta->{'K_KED.strtgy'}, ['erklaeren','beschreiben'], 'Xenodata'); |
| 87 | is_deeply($meta->{'K_KED.topic'}, ['gesundheit_krankheit'], 'Xenodata'); |
| 88 | is_deeply($meta->{'K_KED.txttyp'}, ['lexikonartikel'], 'Xenodata'); |
| 89 | is_deeply($meta->{'K_KED.rcpnt'}, ['kinder'], 'Xenodata'); |
| 90 | |
| 91 | is_deeply($meta->{'K_KED.corpusRcpnt'}, ['kinder'], 'Xenodata'); |
| 92 | is($meta->{'A_KED.corpusRcpntLabel'}, 'Kinder', 'Xenodata'); |
| 93 | |
| 94 | is_deeply($meta->{'K_KED.docRcpnt'}, ['kinder'], 'Xenodata'); |
| 95 | is($meta->{'A_KED.docRcpntLabel'}, 'Kinder', 'Xenodata'); |
| 96 | |
| 97 | # Tokenization |
| 98 | use_ok('KorAP::XML::Tokenizer'); |
| 99 | |
| 100 | my ($token_base_foundry, $token_base_layer) = (qw/tokens morpho/); |
| 101 | |
| 102 | # Get tokenization |
| 103 | my $tokens = KorAP::XML::Tokenizer->new( |
| 104 | path => $doc->path, |
| 105 | doc => $doc, |
| 106 | foundry => $token_base_foundry, |
| 107 | layer => $token_base_layer, |
| 108 | name => 'tokens' |
| 109 | ); |
| 110 | ok($tokens, 'Token Object is fine'); |
| 111 | ok($tokens->parse, 'Token parsing is fine'); |
| 112 | |
| 113 | my $output = decode_json( $tokens->to_json ); |
| 114 | |
| 115 | ## Base |
| 116 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'); |
| 117 | |
| 118 | $output = $tokens->to_data; |
| 119 | |
| 120 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs', 'Foundries'); |
| 121 | |
| 122 | is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos'); |
| 123 | |
| 124 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 125 | |
| 126 | like($token, qr!i:mitteleuropa!, 'data'); |
| 127 | |
| 128 | done_testing; |
| 129 | __END__ |
| 130 | |