blob: 17bece0b78f11107d295dbff4db997368357c1cb [file] [log] [blame]
Akron340a9cb2020-05-20 12:55:22 +02001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use File::Basename;
6use File::Spec::Functions;
Akron1c070452020-05-25 11:28:30 +02007use Data::Dumper;
Akron99d2d082024-07-18 16:17:08 +02008use utf8;
Akron340a9cb2020-05-20 12:55:22 +02009
10use Test::Output;
11use Mojo::JSON 'decode_json';
Akron99d2d082024-07-18 16:17:08 +020012use Mojo::Util qw'decode encode';
Akron340a9cb2020-05-20 12:55:22 +020013
Akrondd0aa3a2024-04-10 11:03:38 +020014my $script = catfile(dirname(__FILE__), '..', 'script', 'cosmasvc2koralquery');
Akron340a9cb2020-05-20 12:55:22 +020015my $list1 = catfile(dirname(__FILE__), 'data', 'list2.def');
16
17# Check STDOUT
18stdout_like(
19 sub {
Akrona3f74f52024-07-17 17:18:17 +020020 system($script, 'def', $list1);
Akron340a9cb2020-05-20 12:55:22 +020021 },
22 qr!^\{\"\@context\".+?\}$!,
23 "check stdout"
24);
25
26# Check JSON
Akrona3f74f52024-07-17 17:18:17 +020027my $json = decode_json(join('', `$script def $list1`));
Akron340a9cb2020-05-20 12:55:22 +020028
29is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
30is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
31
32my $op1 = $json->{'collection'}->{'operands'}->[0];
33is($op1->{'@type'}, 'koral:doc', 'type');
34is($op1->{'key'}, 'docSigle', 'key');
35is($op1->{'match'}, 'match:eq', 'match');
36is($op1->{'value'}->[0], "BRZ05/SEP", 'value');
37is($op1->{'value'}->[1], ,"BRZ05/OKT", 'value');
38is($op1->{'value'}->[-1], ,"BRZ08/FEB", 'value');
Akron68746a12020-05-20 15:19:55 +020039
40my $op2 = $json->{'collection'}->{'operands'}->[1];
41is($op2->{'@type'}, 'koral:doc', 'type');
42is($op2->{'key'}, 'textSigle', 'key');
43is($op2->{'match'}, 'match:eq', 'match');
44is($op2->{'value'}->[0], "B19/AUG/01665", 'value');
45is($op2->{'value'}->[1], ,"B19/AUG/01666", 'value');
46
Akron1c070452020-05-25 11:28:30 +020047my $list3 = catfile(dirname(__FILE__), 'data', 'list3.def');
Akron323881c2020-05-20 17:15:42 +020048
Akron34a4f582020-05-27 12:18:57 +020049
Akron323881c2020-05-20 17:15:42 +020050# Check JSON
51# Only return extended area
Akrona3f74f52024-07-17 17:18:17 +020052$json = decode_json(join('', `$script def $list3`));
Akron323881c2020-05-20 17:15:42 +020053
Akron34a4f582020-05-27 12:18:57 +020054is($json->{'collection'}->{'@type'}, 'koral:doc', 'type');
55
56
Akron286b46e2020-05-25 17:07:48 +020057is($json->{'collection'}->{'comment'}, 'name:"VAS-N91 (Stand \"2013\", korr. 2017)"', 'type');
Akron323881c2020-05-20 17:15:42 +020058
Akron34a4f582020-05-27 12:18:57 +020059$op1 = $json->{'collection'};
Akron323881c2020-05-20 17:15:42 +020060is($op1->{'@type'}, 'koral:doc', 'type');
61is($op1->{'key'}, 'textSigle', 'key');
62is($op1->{'match'}, 'match:eq', 'match');
63is($op1->{'value'}->[0], "A00/APR/23232", 'value');
Akron286b46e2020-05-25 17:07:48 +020064is($op1->{'value'}->[1], "A00/APR/23233", 'value');
Akron323881c2020-05-20 17:15:42 +020065
Akron1c070452020-05-25 11:28:30 +020066my $list4 = catfile(dirname(__FILE__), 'data', 'list4.def');
67
68# Only contains intended area
Akrona3f74f52024-07-17 17:18:17 +020069$json = decode_json(join('', `$script def $list4`));
Akron1c070452020-05-25 11:28:30 +020070
71is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
Akron34a4f582020-05-27 12:18:57 +020072is($json->{'collection'}->{'comment'}, 'name:"VAS N91"', 'name');
Akron286b46e2020-05-25 17:07:48 +020073like($json->{'collection'}->{'comment'}, qr!^name:"VAS N91"!, 'name');
Akron1c070452020-05-25 11:28:30 +020074
Akron34a4f582020-05-27 12:18:57 +020075
76my $bz = $json->{'collection'}->{operands}->[0]->{operands}->[0];
77is($bz->{operation}, 'operation:and', 'Intersection');
78is(scalar @{$bz->{operands}}, 3, 'Flatten operands');
79
80my $faz = $json->{'collection'}->{operands}->[0]->{operands}->[1];
81is($faz->{'@type'}, 'koral:doc', 'DocVec');
82is($faz->{value}->[0], 'F97', 'Value');
83is($faz->{value}->[1], 'F99', 'Value');
Akron1c070452020-05-25 11:28:30 +020084
Akron431d9572024-07-18 13:21:02 +020085my $list_long = catfile(dirname(__FILE__), 'data', 'corp-w-short.def');
86$json = decode_json(join('', `$script def $list_long`))->{collection};
87is($json->{'@type'}, 'koral:doc', 'DocVec');
88is($json->{key}, 'textSigle', 'Key');
89is($json->{value}->[0], 'A97/APR/00001', 'Value');
90is($json->{value}->[1], 'A97/APR/00002', 'Value');
91is($json->{value}->[-1], 'A97/APR/01001', 'Value');
92
Akron99d2d082024-07-18 16:17:08 +020093my $corpa = catfile(dirname(__FILE__), 'data', 'corp-a.def');
94$json = decode_json(encode('utf-8',join('', `$script def $corpa`)));
95
96is($json->{'collection'}->{'@type'}, 'koral:doc', 'type');
97is($json->{'collection'}->{'key'}, 'pubPlaceKey', 'type');
98is($json->{'collection'}->{'value'}, 'A', 'type');
99is($json->{'collection'}->{'comment'}, 'name:"Korpora aus Österreich"', 'type');
100
101
Akron340a9cb2020-05-20 12:55:22 +0200102done_testing;
Akron34a4f582020-05-27 12:18:57 +0200103__END__