blob: 5e06089c97dd53859a1016740e74f881c298b33f [file] [log] [blame]
Akron2cfe9bd2024-05-02 16:28:52 +02001use strict;
2use warnings;
3use Test::More;
4use Data::Dumper;
5use JSON::XS;
6
7if ($ENV{SKIP_REAL}) {
8 plan skip_all => 'Skip real tests';
9};
10
11use Benchmark qw/:hireswallclock/;
12
13my $t = Benchmark->new;
14
15use utf8;
16use lib 'lib', '../lib';
17
18use File::Basename 'dirname';
19use File::Spec::Functions 'catdir';
20
21use_ok('KorAP::XML::Krill');
22
23# This will Check KoKoKom-Files
24
25my $path = catdir(dirname(__FILE__), 'corpus','KTC','001','000001');
26
27ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
28ok($doc->parse, 'Parse document');
29
30is($doc->text_sigle, 'KTC/001/000001', 'Correct text sigle');
31is($doc->doc_sigle, 'KTC/001', 'Correct document sigle');
32is($doc->corpus_sigle, 'KTC', 'Correct corpus sigle');
33
34my $meta = $doc->meta;
35is($meta->{T_title}, 'ohne Titel', 'Title');
36is($meta->{S_pub_place}, 'San Bruno, California / Berlin', 'PubPlace');
37is($meta->{D_pub_date}, '20221127', 'Creation Date');
38ok(!$meta->{T_sub_title}, 'SubTitle');
39is($meta->{T_author}, 'maiLab', 'Author');
40
41is($meta->{A_publisher}, 'Youtube / ARD', 'Publisher');
42ok(!$meta->{A_editor}, 'Editor');
43ok(!$meta->{A_translator}, 'Translator');
44ok(!$meta->{S_text_type}, 'Correct Text Type');
45ok(!$meta->{S_text_type_art}, 'Correct Text Type Art');
46ok(!$meta->{S_text_type_ref}, 'Correct Text Type Ref');
47ok(!$meta->{S_text_column}, 'Correct Text Column');
48ok(!$meta->{S_text_domain}, 'Correct Text Domain');
49ok(!$meta->{D_creation_date}, 'Creation Date');
50
51ok(!$meta->{pages}, 'Pages');
52ok(!$meta->{A_file_edition_statement}, 'File Ed Statement');
53ok(!$meta->{A_bibl_edition_statement}, 'Bibl Ed Statement');
54is($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
57is($meta->{T_corpus_title}, 'KoKoKom Transkriptkorpus', 'Correct Corpus title');
58ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
59ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
60ok(!$meta->{A_corpus_editor}, 'Correct Corpus editor');
61
62is($meta->{T_doc_title}, 'ohne Titel', 'Correct Doc title');
63ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
64is($meta->{T_doc_author},'maiLab', 'Correct Doc author');
65ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
66
67# Tokenization
68use_ok('KorAP::XML::Tokenizer');
69
70my ($token_base_foundry, $token_base_layer) = (qw/Base tokens/);
71
72# Get tokenization
73my $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);
80ok($tokens, 'Token Object is fine');
81ok($tokens->parse, 'Token parsing is fine');
82
83my $output = decode_json( $tokens->to_json );
84
85## Base
86$tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs');
87
88$output = $tokens->to_data;
89
90is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs', 'Foundries');
91
92is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
93
94my $token = join('||', @{$output->{data}->{stream}->[7]});
95
96like($token, qr!i:man!, 'data');
97
98$token = join('||', @{$output->{data}->{stream}->[9]});
99
100like($token, qr!i:รถffentliche!, 'data');
101
102$token = join('||', @{$output->{data}->{stream}->[0]});
103
104like($token, qr!\<\>:dereko/s:u\$<b>64<i>0<i>125<i>17<b>3<s>2!, 'data');
105like($token, qr!\@:dereko\/s:who:Mai Thi Nguyen-Kim\$<b>17<s>2<i>17!, 'data');
106like($token, qr!\@:dereko\/s:start:0:00\$<b>17<s>2<i>17!, 'data');
107like($token, qr!\@:dereko\/s:end:01:20\$<b>17<s>2<i>17!, 'data');
108
109like($token, qr!\~:base\/s:marker\$<i>0<i>0<x>who:Mai Thi Nguyen-Kim!, 'data');
110like($token, qr!\~:base\/s:marker\$<i>0<i>0<x>start:0:00!, 'data');
111like($token, qr!\~:base\/s:marker\$<i>0<i>0<x>end:01:20!, 'data');
112
113diag $tokens->to_json;
114
115done_testing;
116__END__
117