|  | #!/usr/bin/env perl | 
|  | use strict; | 
|  | use warnings; | 
|  | use lib 'lib'; | 
|  | use KorAP::Def; | 
|  | use KorAP::DefList; | 
|  | use Getopt::Long; | 
|  |  | 
|  | binmode(STDERR, ':encoding(UTF-8)'); | 
|  |  | 
|  | # 2020-05-20 | 
|  | #   Preliminary support for C2 def-files. | 
|  | # 2020-05-29 | 
|  | #   Introduce optimizable object system. | 
|  | # 2024-07-17 | 
|  | #   Add KorAP::Def. | 
|  | # 2024-12-16 | 
|  | #   Fix doc trimming | 
|  | #   Fix country codes. | 
|  |  | 
|  | our $VERSION = 0.4; | 
|  | our @ARGV; | 
|  |  | 
|  | my $cmd = shift @ARGV; | 
|  |  | 
|  |  | 
|  | my ($input, $output, $copysrc); | 
|  |  | 
|  | GetOptions ( | 
|  | "input|i=s" => \$input, | 
|  | "output|o=s" => \$output, | 
|  | "copy-src|c=s" => \$copysrc, | 
|  | ) | 
|  | or die("Error in command line arguments\n"); | 
|  |  | 
|  | if (!$cmd || ($cmd ne 'def' && $cmd ne 'list' && $cmd ne 'script')) { | 
|  | print <<'HELP'; | 
|  | Convert a list of C2 VC definitions, a single definition or a script file into | 
|  | KoralQuery VCs. | 
|  |  | 
|  | $ perl cosmasvc2koralquery def my_vc.txt | gzip -vc > my_vc.jsonld.gz | 
|  | $ cat my_vc.txt | perl cosmasvc2koralquery def - | gzip -vc > my_vc.jsonld.gz | 
|  |  | 
|  | Command: def | 
|  |  | 
|  | Convert a def file or a list of sigles to a KoralQuery VC. | 
|  |  | 
|  | Takes the list or def from STDIN and exports to STDOUT. | 
|  |  | 
|  | Command: list | 
|  |  | 
|  | Convert a list with copy or regex instructions to KoralQuery VCs. | 
|  |  | 
|  | --output: The output directory | 
|  | --copy-src: The directory for def files to copy | 
|  |  | 
|  | Command: script | 
|  |  | 
|  | Convert a script file with LOAD() instructions to KoralQuery VCs. | 
|  |  | 
|  | --output: The output directory | 
|  |  | 
|  | HELP | 
|  | exit 1; | 
|  | }; | 
|  |  | 
|  |  | 
|  | # Process a list | 
|  | if ($cmd eq 'list') { | 
|  | KorAP::DefList->new( | 
|  | file => ($input || $ARGV[0]), | 
|  | copy => ($copysrc || '.'), | 
|  | output => ($output || '.') | 
|  | )->parse; | 
|  | exit(0); | 
|  | }; | 
|  |  | 
|  | # Process a list | 
|  | if ($cmd eq 'script') { | 
|  | KorAP::ScriptLoad->new( | 
|  | file => ($input || $ARGV[0]), | 
|  | output => ($output || '.') | 
|  | )->parse; | 
|  | exit(0); | 
|  | }; | 
|  |  | 
|  |  | 
|  | # Parse a single def | 
|  | my $def_parser; | 
|  | if ($ARGV[0] eq '-') { | 
|  | $def_parser = KorAP::Def->new(\*STDIN); | 
|  | } | 
|  | elsif ($input) { | 
|  | $def_parser = KorAP::Def->new($input); | 
|  | } | 
|  | else { | 
|  | $def_parser = KorAP::Def->new($ARGV[0]); | 
|  | }; | 
|  |  | 
|  | $def_parser->parse; | 
|  |  | 
|  | # Stringify current (extended?) virtual corpus | 
|  | print $def_parser->to_string; |