blob: 1de378dee8b98f5b2ca32e2f8100bc493f4bb76b [file] [log] [blame]
Akron5eb3aa02019-01-25 18:30:47 +01001use strict;
2use warnings;
3use utf8;
4use Test::More;
5use Benchmark ':hireswallclock';
6use Mojo::DOM;
7use Mojo::File;
8use Mojo::ByteStream 'b';
9use Data::Dumper;
10
11use File::Basename 'dirname';
12use File::Spec::Functions 'catdir';
13
14use_ok('KorAP::XML::Krill');
15
16# WPD/00001
17my $path = catdir(dirname(__FILE__), 'corpus/WPD/00001');
18ok(my $doc = KorAP::XML::Krill->new( path => $path . '/' ), 'Load Korap::Document');
19like($doc->path, qr!\Q$path\E/!, 'Path');
20
21ok($doc = KorAP::XML::Krill->new( path => $path ), 'Load Korap::Document');
22like($doc->path, qr!\Q$path\E/$!, 'Path');
23
24ok($doc->parse, 'Parse document');
25
26my $meta = $doc->meta;
27
28my $fields = $meta->to_koral_fields;
29
30# TODO: Check for foundries, tokenSource, layerInfos!
31
32_contains($fields, 'title', 'A', 'text');
33_contains($fields, 'textSigle', 'WPD/AAA/00001', 'string');
34_contains($fields, 'docSigle', 'WPD/AAA', 'string');
35_contains($fields, 'corpusSigle', 'WPD', 'string');
36_contains($fields, 'pubDate', '2005-03-28', 'date');
37_contains($fields, 'pubPlace', 'URL:http://de.wikipedia.org', 'string');
38_contains($fields, 'textClass', 'freizeit-unterhaltung reisen wissenschaft populaerwissenschaft', 'keywords');
39_contains($fields, 'author', 'Ruru; Jens.Ol; Aglarech; u.a.', 'text');
40
41_contains($fields, 'editor', 'data:,wikipedia.org', 'attachement');
42_contains($fields, 'publisher', 'data:,Wikipedia', 'attachement');
43_contains($fields, 'creationDate', '2005', 'date');
44_contains_not($fields, 'textType');
45_contains_not($fields, 'textTypeArt');
46_contains_not($fields, 'textTypeRef');
47_contains_not($fields, 'textDomain');
48_contains_not($fields, 'keywords');
49
Akron5eb3aa02019-01-25 18:30:47 +010050_contains_not($fields, 'subTitle');
51
52
53sub _contains {
54 my ($fields, $key, $value, $type) = @_;
55
56 local $Test::Builder::Level = $Test::Builder::Level + 1;
57
58 my $tb = Test::More->builder;
59
60 foreach (@$fields) {
61 if ($_->{key} eq $key) {
62
63 my $cmp_value = $_->{value};
64 if ($_->{type} eq 'type:keywords' && ref($cmp_value) eq 'ARRAY') {
65 $cmp_value = join(' ', @{$cmp_value});
66 };
67
68 if ($cmp_value eq $value) {
69 if ($_->{type} eq 'type:' . $type) {
70 $tb->ok(1, 'Contains ' . $key);
71 }
72 else {
73 $tb->ok(0, 'Contains ' . $key . ' but type ' . $_->{type} . ' != ' . $type);
74 };
75 }
76 else {
77 $tb->ok(0, 'Contains ' . $key . ' but value ' . $cmp_value . ' != ' . $value);
78 };
79 return;
80 }
81 };
82
83 $tb->ok(0, 'Contains ' . $key);
84};
85
86sub _contains_not {
87 my ($fields, $key) = @_;
88
89 local $Test::Builder::Level = $Test::Builder::Level + 1;
90
91 my $tb = Test::More->builder;
92
93 foreach (@$fields) {
94 if ($_->{key} eq $key) {
95 $tb->ok(0, 'Contains not ' . $key);
96 return;
97 }
98 };
99
100 $tb->ok(1, 'Contains not ' . $key);
101};
102
103done_testing;
104__END__