Akron | 2cfe9bd | 2024-05-02 16:28:52 +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 KoKoKom-Files |
| 24 | |
| 25 | my $path = catdir(dirname(__FILE__), 'corpus','KTC','001','000001'); |
| 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, 'KTC/001/000001', 'Correct text sigle'); |
| 31 | is($doc->doc_sigle, 'KTC/001', 'Correct document sigle'); |
| 32 | is($doc->corpus_sigle, 'KTC', 'Correct corpus sigle'); |
| 33 | |
| 34 | my $meta = $doc->meta; |
| 35 | is($meta->{T_title}, 'ohne Titel', 'Title'); |
| 36 | is($meta->{S_pub_place}, 'San Bruno, California / Berlin', 'PubPlace'); |
| 37 | is($meta->{D_pub_date}, '20221127', 'Creation Date'); |
| 38 | ok(!$meta->{T_sub_title}, 'SubTitle'); |
| 39 | is($meta->{T_author}, 'maiLab', 'Author'); |
| 40 | |
| 41 | is($meta->{A_publisher}, 'Youtube / ARD', 'Publisher'); |
| 42 | ok(!$meta->{A_editor}, 'Editor'); |
| 43 | ok(!$meta->{A_translator}, 'Translator'); |
| 44 | ok(!$meta->{S_text_type}, 'Correct Text Type'); |
| 45 | ok(!$meta->{S_text_type_art}, 'Correct Text Type Art'); |
| 46 | ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref'); |
| 47 | ok(!$meta->{S_text_column}, 'Correct Text Column'); |
| 48 | ok(!$meta->{S_text_domain}, 'Correct Text Domain'); |
| 49 | ok(!$meta->{D_creation_date}, '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}, 'KTC/001.000001, Transkript, 27.11.2022. maiLab: in: KTC/001., - Youtube / ARD', 'Reference'); |
| 55 | # is($meta->{S_language}, 'de', 'Language'); |
| 56 | |
| 57 | is($meta->{T_corpus_title}, 'KoKoKom Transkriptkorpus', 'Correct Corpus title'); |
| 58 | ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title'); |
| 59 | ok(!$meta->{T_corpus_author}, 'Correct Corpus author'); |
| 60 | ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor'); |
| 61 | |
| 62 | is($meta->{T_doc_title}, 'ohne Titel', 'Correct Doc title'); |
| 63 | ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title'); |
| 64 | is($meta->{T_doc_author},'maiLab', 'Correct Doc author'); |
| 65 | ok(!$meta->{A_doc_editor}, 'Correct Doc editor'); |
| 66 | |
| 67 | # Tokenization |
| 68 | use_ok('KorAP::XML::Tokenizer'); |
| 69 | |
| 70 | my ($token_base_foundry, $token_base_layer) = (qw/Base tokens/); |
| 71 | |
| 72 | # Get tokenization |
| 73 | my $tokens = KorAP::XML::Tokenizer->new( |
| 74 | path => $doc->path, |
| 75 | doc => $doc, |
| 76 | foundry => $token_base_foundry, |
| 77 | layer => $token_base_layer, |
| 78 | name => 'tokens' |
| 79 | ); |
| 80 | ok($tokens, 'Token Object is fine'); |
| 81 | ok($tokens->parse, 'Token parsing is fine'); |
| 82 | |
| 83 | my $output = decode_json( $tokens->to_json ); |
| 84 | |
| 85 | ## Base |
| 86 | $tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs'); |
| 87 | |
| 88 | $output = $tokens->to_data; |
| 89 | |
| 90 | is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs', 'Foundries'); |
| 91 | |
| 92 | is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos'); |
| 93 | |
| 94 | my $token = join('||', @{$output->{data}->{stream}->[7]}); |
| 95 | |
| 96 | like($token, qr!i:man!, 'data'); |
| 97 | |
| 98 | $token = join('||', @{$output->{data}->{stream}->[9]}); |
| 99 | |
| 100 | like($token, qr!i:รถffentliche!, 'data'); |
| 101 | |
| 102 | $token = join('||', @{$output->{data}->{stream}->[0]}); |
| 103 | |
| 104 | like($token, qr!\<\>:dereko/s:u\$<b>64<i>0<i>125<i>17<b>3<s>2!, 'data'); |
| 105 | like($token, qr!\@:dereko\/s:who:Mai Thi Nguyen-Kim\$<b>17<s>2<i>17!, 'data'); |
| 106 | like($token, qr!\@:dereko\/s:start:0:00\$<b>17<s>2<i>17!, 'data'); |
| 107 | like($token, qr!\@:dereko\/s:end:01:20\$<b>17<s>2<i>17!, 'data'); |
| 108 | |
| 109 | like($token, qr!\~:base\/s:marker\$<i>0<i>0<x>who:Mai Thi Nguyen-Kim!, 'data'); |
| 110 | like($token, qr!\~:base\/s:marker\$<i>0<i>0<x>start:0:00!, 'data'); |
| 111 | like($token, qr!\~:base\/s:marker\$<i>0<i>0<x>end:01:20!, 'data'); |
| 112 | |
Akron | 2cfe9bd | 2024-05-02 16:28:52 +0200 | [diff] [blame] | 113 | done_testing; |
| 114 | __END__ |
| 115 | |