blob: 04cc8c1a3585523e22880c855b5c04cf74dfc13a [file] [log] [blame]
Akron24ad3c02024-06-03 12:38:20 +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 KED-Files - especially regarding Xenodata
24
25my $path = catdir(dirname(__FILE__), 'corpus','KED','KLX','03212');
26
27ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
28ok($doc->parse, 'Parse document');
29
30is($doc->text_sigle, 'KED/KLX/03212', 'Correct text sigle');
31is($doc->doc_sigle, 'KED/KLX', 'Correct document sigle');
32is($doc->corpus_sigle, 'KED', 'Correct corpus sigle');
33
34my $meta = $doc->meta;
35is($meta->{T_title}, 'Flöhe', 'Title');
36is($meta->{S_pub_place}, 'klexikon.zum.de', 'PubPlace');
37is($meta->{D_pub_date}, '20230309', 'Creation Date');
38ok(!$meta->{T_sub_title}, 'SubTitle');
39ok(!$meta->{T_author}, 'No author');
40
41is($meta->{A_publisher}, 'klexikon.zum.de', 'Publisher');
42ok(!$meta->{A_editor}, 'Editor');
43ok(!$meta->{A_translator}, 'Translator');
44is($meta->{S_text_type}, 'Webtext:Lexikonartikel', 'Correct Text Type');
45is($meta->{S_text_type_art}, 'Lexikonartikel', 'Correct Text Type Art');
46is($meta->{S_text_type_ref}, 'Webtext', 'Correct Text Type Ref');
47ok(!$meta->{S_text_column}, 'Correct Text Column');
48ok(!$meta->{S_text_domain}, 'Correct Text Domain');
49is($meta->{D_creation_date}, '20230309', '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}, '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
57is($meta->{T_corpus_title}, 'Korpus Einfaches Deutsch', 'Correct Corpus title');
58ok(!$meta->{T_corpus_sub_title}, 'Correct Corpus Sub title');
59ok(!$meta->{T_corpus_author}, 'Correct Corpus author');
60is($meta->{A_corpus_editor},'Daniel Jach, Shanghai Normal University, China', 'Correct Corpus editor');
61
62is($meta->{T_doc_title}, 'Korpus Einfaches Deutsch: Klexikon (Online)', 'Correct Doc title');
63ok(!$meta->{T_doc_sub_title}, 'Correct Doc Sub title');
64ok(!$meta->{T_doc_author}, 'Correct Doc author');
65ok(!$meta->{A_doc_editor}, 'Correct Doc editor');
66
67is($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
69is($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
71is($meta->{'A_KED.topicLabel'}, 'Gesundheit und Krankheit', 'Xenodata');
72is($meta->{'A_KED.nToksSentMd'}, '11.0', 'Xenodata');
73is($meta->{'A_KED.nToks'}, '308', 'Xenodata');
74is($meta->{'A_KED.nPunct1kTks'}, '129.87', 'Xenodata');
75is($meta->{'A_KED.strtgyLabel'}, "Erkl\x{e4}ren", 'Xenodata');
76is($meta->{'A_KED.rcpntLabel'}, 'Kinder', 'Xenodata');
77is($meta->{'A_KED.nSent'}, '28', 'Xenodata');
78is($meta->{'A_KED.nTyps'}, '188', 'Xenodata');
79is($meta->{'A_KED.txttypLabel'}, 'Lexikonartikel', 'Xenodata');
80is($meta->{'S_KED.cover4Herder'}, '0.65', 'Xenodata');
81is($meta->{'S_KED.cover2Herder'}, '0.61', 'Xenodata');
82is($meta->{'S_KED.cover1Herder'}, '0.58', 'Xenodata');
83is($meta->{'S_KED.nPara'}, '5', 'Xenodata');
84is($meta->{'S_KED.cover3Herder'}, '0.62', 'Xenodata');
85is($meta->{'S_KED.cover5Herder'}, '0.67', 'Xenodata');
86is_deeply($meta->{'K_KED.strtgy'}, ['erklaeren','beschreiben'], 'Xenodata');
87is_deeply($meta->{'K_KED.topic'}, ['gesundheit_krankheit'], 'Xenodata');
88is_deeply($meta->{'K_KED.txttyp'}, ['lexikonartikel'], 'Xenodata');
89is_deeply($meta->{'K_KED.rcpnt'}, ['kinder'], 'Xenodata');
90
91is_deeply($meta->{'K_KED.corpusRcpnt'}, ['kinder'], 'Xenodata');
92is($meta->{'A_KED.corpusRcpntLabel'}, 'Kinder', 'Xenodata');
93
94is_deeply($meta->{'K_KED.docRcpnt'}, ['kinder'], 'Xenodata');
95is($meta->{'A_KED.docRcpntLabel'}, 'Kinder', 'Xenodata');
96
97# Tokenization
98use_ok('KorAP::XML::Tokenizer');
99
100my ($token_base_foundry, $token_base_layer) = (qw/tokens morpho/);
101
102# Get tokenization
103my $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);
110ok($tokens, 'Token Object is fine');
111ok($tokens->parse, 'Token parsing is fine');
112
113my $output = decode_json( $tokens->to_json );
114
115## Base
116$tokens->add('DeReKo', 'Structure', 'base_sentences_paragraphs');
117
118$output = $tokens->to_data;
119
120is($output->{data}->{foundries}, 'dereko dereko/structure dereko/structure/base_sentences_paragraphs', 'Foundries');
121
122is($output->{data}->{layerInfos}, 'dereko/s=spans', 'layerInfos');
123
124my $token = join('||', @{$output->{data}->{stream}->[7]});
125
126like($token, qr!i:mitteleuropa!, 'data');
127
128done_testing;
129__END__
130