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