blob: 931f106f556e6f02857eb0f28d759ec3dfe29500 [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
50# diag Dumper $fields;
51
52_contains_not($fields, 'subTitle');
53
54
55sub _contains {
56 my ($fields, $key, $value, $type) = @_;
57
58 local $Test::Builder::Level = $Test::Builder::Level + 1;
59
60 my $tb = Test::More->builder;
61
62 foreach (@$fields) {
63 if ($_->{key} eq $key) {
64
65 my $cmp_value = $_->{value};
66 if ($_->{type} eq 'type:keywords' && ref($cmp_value) eq 'ARRAY') {
67 $cmp_value = join(' ', @{$cmp_value});
68 };
69
70 if ($cmp_value eq $value) {
71 if ($_->{type} eq 'type:' . $type) {
72 $tb->ok(1, 'Contains ' . $key);
73 }
74 else {
75 $tb->ok(0, 'Contains ' . $key . ' but type ' . $_->{type} . ' != ' . $type);
76 };
77 }
78 else {
79 $tb->ok(0, 'Contains ' . $key . ' but value ' . $cmp_value . ' != ' . $value);
80 };
81 return;
82 }
83 };
84
85 $tb->ok(0, 'Contains ' . $key);
86};
87
88sub _contains_not {
89 my ($fields, $key) = @_;
90
91 local $Test::Builder::Level = $Test::Builder::Level + 1;
92
93 my $tb = Test::More->builder;
94
95 foreach (@$fields) {
96 if ($_->{key} eq $key) {
97 $tb->ok(0, 'Contains not ' . $key);
98 return;
99 }
100 };
101
102 $tb->ok(1, 'Contains not ' . $key);
103};
104
105done_testing;
106__END__