Introduce object mechanism to VCs in vc conversion tool
Change-Id: If5d06a0b9b08b9c39700a0eb471a0edfb0d5daf5
diff --git a/t/list2vc-def.t b/t/list2vc-def.t
index baaefda..a3b60e7 100644
--- a/t/list2vc-def.t
+++ b/t/list2vc-def.t
@@ -44,38 +44,41 @@
my $list3 = catfile(dirname(__FILE__), 'data', 'list3.def');
+
# Check JSON
# Only return extended area
$json = decode_json(join('', `$script $list3`));
-is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
-is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
+is($json->{'collection'}->{'@type'}, 'koral:doc', 'type');
+
+
is($json->{'collection'}->{'comment'}, 'name:"VAS-N91 (Stand \"2013\", korr. 2017)"', 'type');
-$op1 = $json->{'collection'}->{'operands'}->[0];
+$op1 = $json->{'collection'};
is($op1->{'@type'}, 'koral:doc', 'type');
is($op1->{'key'}, 'textSigle', 'key');
is($op1->{'match'}, 'match:eq', 'match');
is($op1->{'value'}->[0], "A00/APR/23232", 'value');
is($op1->{'value'}->[1], "A00/APR/23233", 'value');
-
my $list4 = catfile(dirname(__FILE__), 'data', 'list4.def');
# Only contains intended area
$json = decode_json(join('', `$script $list4`));
is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
-is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
+is($json->{'collection'}->{'comment'}, 'name:"VAS N91"', 'name');
like($json->{'collection'}->{'comment'}, qr!^name:"VAS N91"!, 'name');
-like($json->{'collection'}->{'comment'}, qr!embed:\[name:"Berliner Zeitung",redabs:143237\]!, 'embed');
-like($json->{'collection'}->{'comment'}, qr!embed:\[name:"Frankfurter Allgemeine",redabs:301166\]!, 'embed');
-$op1 = $json->{'collection'}->{'operands'}->[0];
-is($op1->{'@type'}, 'koral:doc', 'type');
-is($op1->{'key'}, 'corpusSigle', 'key');
-is($op1->{'match'}, 'match:eq', 'match');
-is($op1->{'value'}->[0], "F97", 'value');
-is($op1->{'value'}->[1], "F99", 'value');
+
+my $bz = $json->{'collection'}->{operands}->[0]->{operands}->[0];
+is($bz->{operation}, 'operation:and', 'Intersection');
+is(scalar @{$bz->{operands}}, 3, 'Flatten operands');
+
+my $faz = $json->{'collection'}->{operands}->[0]->{operands}->[1];
+is($faz->{'@type'}, 'koral:doc', 'DocVec');
+is($faz->{value}->[0], 'F97', 'Value');
+is($faz->{value}->[1], 'F99', 'Value');
done_testing;
+__END__
diff --git a/t/list2vc-obj.t b/t/list2vc-obj.t
new file mode 100644
index 0000000..d4bbd80
--- /dev/null
+++ b/t/list2vc-obj.t
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Data::Dumper;
+use Mojo::JSON 'decode_json';
+
+require_ok 'KorAP::VirtualCorpus::Group';
+
+my $vc = KorAP::VirtualCorpus::Group->new;
+$vc->union_field('author', 'Goethe');
+$vc->union_field('author', 'Schiller');
+$vc->joint_field('author', 'Fontane');
+
+
+my $json = decode_json $vc->to_koral->to_string;
+
+is($json->{collection}->{operation}, 'operation:and');
+is($json->{collection}->{operands}->[0]->{'@type'}, 'koral:doc');
+is($json->{collection}->{operands}->[0]->{'value'}->[0], 'Goethe');
+is($json->{collection}->{operands}->[0]->{'value'}->[1], 'Schiller');
+
+done_testing;