Support C2 VC names in vc conversion tool
Change-Id: I4c6c7b7389a9779b30de6469b9cdd54d38edef11
diff --git a/list2vc.pl b/list2vc.pl
index 95259cc..d68e22d 100755
--- a/list2vc.pl
+++ b/list2vc.pl
@@ -1,7 +1,55 @@
#!/usr/bin/env perl
+package KorAP::VirtualCorpus;
+use strict;
+use warnings;
+
+# Get or set name of the VC
+sub name {
+ my $self = shift;
+ unless (@_) {
+ return $self->{name};
+ };
+ $self->{name} = shift;
+ return $self;
+};
+
+
+# Quote utility function
+sub quote {
+ shift;
+ my $str = shift;
+ $str =~ s/(["\\])/\\$1/g;
+ return qq{"$str"};
+};
+
+
+# Escaped quote utility function
+sub equote {
+ shift;
+ my $str = shift;
+ $str =~ s/(["\\])/\\$1/g;
+ $str =~ s/(["\\])/\\$1/g;
+ return '\\"' . $str . '\\"';
+};
+
+
+# Stringify globally
+sub to_string {
+ my $self = shift;
+ ## Create collection object
+ my $json = '{';
+ $json .= '"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",';
+ $json .= '"collection":{';
+ $json .= $self->_to_fragment;
+ return $json .= '}}';
+};
+
+
package KorAP::VirtualCorpus::Group;
use strict;
use warnings;
+use base 'KorAP::VirtualCorpus';
+
# Construct a new VC group
sub new {
@@ -21,19 +69,17 @@
};
-# Stringify
-sub to_string {
+# Stringify fragment
+sub _to_fragment {
my $self = shift;
- ## Create collection object
- my $json = '{';
- $json .= '"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",';
- $json .= '"collection":{';
+ my $json = '';
unless (keys %{$self->{fields}}) {
return $json . '}}';
};
$json .= '"@type":"koral:docGroup",';
+ $json .= '"comment":"Name: ' . $self->equote($self->name) . '",' if $self->name;
$json .= '"operation":"operation:' . $self->{op} . '",';
$json .= '"operands":[';
@@ -54,8 +100,7 @@
# Remove the last comma
chop $json;
- $json .= ']}}';
- return $json;
+ return $json . ']';
};
@@ -203,6 +248,25 @@
warn 'Unknown extension value ' . $value;
};
}
+
+ # Set VC name
+ elsif ($key eq 'name') {
+ # "Name des virt. Korpus, der angezeigt wird.
+ # Wird auch intern zur Korpusbildung referenziert, z.B. für <and>,
+ # <add>, <sub>"
+
+ # No global name defined yet
+ unless ($$vc->name) {
+ $vc_ext->name($value);
+ $vc_int->name($value);
+ next;
+ };
+ }
+
+ # Unknown
+ else {
+ # warn $key . ' is an unknown field';
+ };
};
close($fh);
diff --git a/t/data/list3.def b/t/data/list3.def
index b6543a6..783cf23 100644
--- a/t/data/list3.def
+++ b/t/data/list3.def
@@ -1,4 +1,4 @@
-<name>VAS-N91 (Stand 2013, korr. 2017)</name>
+<name>VAS-N91 (Stand "2013", korr. 2017)</name>
<frozen></frozen>
diff --git a/t/list2vc-def.t b/t/list2vc-def.t
index d38d9ee..508c8f9 100644
--- a/t/list2vc-def.t
+++ b/t/list2vc-def.t
@@ -50,6 +50,8 @@
is($json->{'collection'}->{'@type'}, 'koral:docGroup', 'type');
is($json->{'collection'}->{'operation'}, 'operation:or', 'operation');
+is($json->{'collection'}->{'comment'}, 'Name: "VAS-N91 (Stand \"2013\", korr. 2017)"', 'type');
+
$op1 = $json->{'collection'}->{'operands'}->[0];
is($op1->{'@type'}, 'koral:doc', 'type');