blob: e3edd5f4b9ffb27c7c02611f161802b64127424f [file] [log] [blame]
Akron3f875be2020-05-11 14:57:19 +02001#!/usr/bin/env perl
Akron3587f362020-05-20 17:50:38 +02002use strict;
3use warnings;
Akron71cf2f52024-07-17 08:54:15 +02004use KorAP::Def;
Akrona3f74f52024-07-17 17:18:17 +02005use KorAP::DefList;
Akron34a4f582020-05-27 12:18:57 +02006use lib 'lib';
Akrona3f74f52024-07-17 17:18:17 +02007use Getopt::Long;
Akron3f875be2020-05-11 14:57:19 +02008
Akron99d2d082024-07-18 16:17:08 +02009binmode(STDERR, ':encoding(UTF-8)');
10
Akron340a9cb2020-05-20 12:55:22 +020011# 2020-05-20
12# Preliminary support for C2 def-files.
Akron34a4f582020-05-27 12:18:57 +020013# 2020-05-29
14# Introduce optimizable object system.
Akron71cf2f52024-07-17 08:54:15 +020015# 2024-07-17
16# Add KorAP::Def.
Akron340a9cb2020-05-20 12:55:22 +020017
Akron431d9572024-07-18 13:21:02 +020018our $VERSION = 0.3;
Akron26b59702020-05-19 12:14:41 +020019our @ARGV;
20
Akrona3f74f52024-07-17 17:18:17 +020021my $cmd = shift @ARGV;
Akron3f875be2020-05-11 14:57:19 +020022
Akrona3f74f52024-07-17 17:18:17 +020023
Akronb31321e2024-07-18 11:17:46 +020024my ($input, $output, $copysrc);
Akrona3f74f52024-07-17 17:18:17 +020025
26GetOptions (
Akronb31321e2024-07-18 11:17:46 +020027 "input|i=s" => \$input,
28 "output|o=s" => \$output,
29 "copy-src|c=s" => \$copysrc,
Akrona3f74f52024-07-17 17:18:17 +020030)
31or die("Error in command line arguments\n");
32
33if ($cmd ne 'def' && $cmd ne 'list') {
34 print <<'HELP';
35Convert a list of C2 VC definitions or a single definition into
36KoralQuery VCs.
37
38 $ perl cosmasvc2koralquery def my_vc.txt | gzip -vc > my_vc.jsonld.gz
39 $ cat my_vc.txt | perl cosmasvc2koralquery def - | gzip -vc > my_vc.jsonld.gz
40
Akronb31321e2024-07-18 11:17:46 +020041Command: def
42
43 Convert a def file or a list of sigles to a KoralQuery VC.
44
45 Takes the list or def from STDIN and exports to STDOUT.
46
47Command: list
48
49 Convert a list with copy or regex instructions to KoralQuery VCs.
50
51 --output: The output directory
52 --copy-src: The directory for def files to copy
Akron3f875be2020-05-11 14:57:19 +020053
54HELP
Akrona3f74f52024-07-17 17:18:17 +020055exit 1;
Akron3f875be2020-05-11 14:57:19 +020056};
57
Akrona3f74f52024-07-17 17:18:17 +020058
59# Process a list
60if ($cmd eq 'list') {
Akronb31321e2024-07-18 11:17:46 +020061 KorAP::DefList->new(
62 file => ($input || $ARGV[0]),
63 copy => ($copysrc || '.'),
64 output => ($output || '.')
65 )->parse;
Akrona3f74f52024-07-17 17:18:17 +020066 exit(0);
67};
68
69# Parse a single def
Akron71cf2f52024-07-17 08:54:15 +020070my $def_parser;
Akron26b59702020-05-19 12:14:41 +020071if ($ARGV[0] eq '-') {
Akron71cf2f52024-07-17 08:54:15 +020072 $def_parser = KorAP::Def->new(\*STDIN);
73}
Akrona3f74f52024-07-17 17:18:17 +020074elsif ($input) {
75 $def_parser = KorAP::Def->new($input);
76}
Akron71cf2f52024-07-17 08:54:15 +020077else {
78 $def_parser = KorAP::Def->new($ARGV[0]);
Akron3f875be2020-05-11 14:57:19 +020079};
80
Akron71cf2f52024-07-17 08:54:15 +020081$def_parser->parse;
Akron26b59702020-05-19 12:14:41 +020082
Akron1c070452020-05-25 11:28:30 +020083# Stringify current (extended?) virtual corpus
Akron71cf2f52024-07-17 08:54:15 +020084print $def_parser->to_string;