Support old siglen in lists as well
Change-Id: I3411ba14697c6fdc3763d4d7613c3e629f50c673
diff --git a/lib/KorAP/Def.pm b/lib/KorAP/Def.pm
index 1f8413e..c9dfeb9 100644
--- a/lib/KorAP/Def.pm
+++ b/lib/KorAP/Def.pm
@@ -120,7 +120,7 @@
}
# Get text sigles
- elsif ($line =~ m!^(?:\w+\/){2}\w+$!) {
+ elsif ($line =~ m!^\w+\/\w+[\/\.]\w+$!) {
$key = 'text';
$value = $line;
}
diff --git a/t/data/list1b.txt b/t/data/list1b.txt
new file mode 100644
index 0000000..80b3ea7
--- /dev/null
+++ b/t/data/list1b.txt
@@ -0,0 +1,7 @@
+A02
+A01/B02.c04
+A03
+
+B04/X02
+B04/X03
+A01/B02.c05
diff --git a/t/list2vc.t b/t/list2vc.t
index 1dc3c4c..5d60594 100644
--- a/t/list2vc.t
+++ b/t/list2vc.t
@@ -9,6 +9,7 @@
my $script = catfile(dirname(__FILE__), '..', 'script', 'cosmasvc2koralquery');
my $list1 = catfile(dirname(__FILE__), 'data', 'list1.txt');
+my $list1b = catfile(dirname(__FILE__), 'data', 'list1b.txt');
# Check STDOUT
stdout_like(
@@ -44,6 +45,31 @@
is_deeply($op3->{'value'}, ["A01/B02/c04","A01/B02/c05"], 'value');
+# Check old sigles format
+$json = decode_json(join('', `$script def $list1b`));
+
+is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
+is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
+
+$op1 = $json->{'collection'}->{'operands'}->[0];
+is($op1->{'@type'}, 'koral:doc', 'type');
+is($op1->{'key'}, 'corpusSigle', 'key');
+is($op1->{'match'}, 'match:eq', 'match');
+is_deeply($op1->{'value'}, ["A02","A03"], 'value');
+
+$op2 = $json->{'collection'}->{'operands'}->[1];
+is($op2->{'@type'}, 'koral:doc', 'type');
+is($op2->{'key'}, 'docSigle', 'key');
+is($op2->{'match'}, 'match:eq', 'match');
+is_deeply($op2->{'value'}, ["B04/X02","B04/X03"], 'value');
+
+$op3 = $json->{'collection'}->{'operands'}->[2];
+is($op3->{'@type'}, 'koral:doc', 'type');
+is($op3->{'key'}, 'textSigle', 'key');
+is($op3->{'match'}, 'match:eq', 'match');
+is_deeply($op3->{'value'}, ["A01/B02/c04","A01/B02/c05"], 'value');
+
+
# Check STDIN
my $json2 = decode_json(join('', `cat $list1 | $script def -`));
is_deeply($json, $json2);