blob: 4c3e5b01009a0e849c0942b4adcb45e511474b42 [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
Akron340a9cb2020-05-20 12:55:22 +02009# 2020-05-20
10# Preliminary support for C2 def-files.
Akron34a4f582020-05-27 12:18:57 +020011# 2020-05-29
12# Introduce optimizable object system.
Akron71cf2f52024-07-17 08:54:15 +020013# 2024-07-17
14# Add KorAP::Def.
Akron340a9cb2020-05-20 12:55:22 +020015
Akron431d9572024-07-18 13:21:02 +020016our $VERSION = 0.3;
Akron26b59702020-05-19 12:14:41 +020017our @ARGV;
18
Akrona3f74f52024-07-17 17:18:17 +020019my $cmd = shift @ARGV;
Akron3f875be2020-05-11 14:57:19 +020020
Akrona3f74f52024-07-17 17:18:17 +020021
Akronb31321e2024-07-18 11:17:46 +020022my ($input, $output, $copysrc);
Akrona3f74f52024-07-17 17:18:17 +020023
24GetOptions (
Akronb31321e2024-07-18 11:17:46 +020025 "input|i=s" => \$input,
26 "output|o=s" => \$output,
27 "copy-src|c=s" => \$copysrc,
Akrona3f74f52024-07-17 17:18:17 +020028)
29or die("Error in command line arguments\n");
30
31if ($cmd ne 'def' && $cmd ne 'list') {
32 print <<'HELP';
33Convert a list of C2 VC definitions or a single definition into
34KoralQuery VCs.
35
36 $ perl cosmasvc2koralquery def my_vc.txt | gzip -vc > my_vc.jsonld.gz
37 $ cat my_vc.txt | perl cosmasvc2koralquery def - | gzip -vc > my_vc.jsonld.gz
38
Akronb31321e2024-07-18 11:17:46 +020039Command: def
40
41 Convert a def file or a list of sigles to a KoralQuery VC.
42
43 Takes the list or def from STDIN and exports to STDOUT.
44
45Command: list
46
47 Convert a list with copy or regex instructions to KoralQuery VCs.
48
49 --output: The output directory
50 --copy-src: The directory for def files to copy
Akron3f875be2020-05-11 14:57:19 +020051
52HELP
Akrona3f74f52024-07-17 17:18:17 +020053exit 1;
Akron3f875be2020-05-11 14:57:19 +020054};
55
Akrona3f74f52024-07-17 17:18:17 +020056
57# Process a list
58if ($cmd eq 'list') {
Akronb31321e2024-07-18 11:17:46 +020059 KorAP::DefList->new(
60 file => ($input || $ARGV[0]),
61 copy => ($copysrc || '.'),
62 output => ($output || '.')
63 )->parse;
Akrona3f74f52024-07-17 17:18:17 +020064 exit(0);
65};
66
67# Parse a single def
Akron71cf2f52024-07-17 08:54:15 +020068my $def_parser;
Akron26b59702020-05-19 12:14:41 +020069if ($ARGV[0] eq '-') {
Akron71cf2f52024-07-17 08:54:15 +020070 $def_parser = KorAP::Def->new(\*STDIN);
71}
Akrona3f74f52024-07-17 17:18:17 +020072elsif ($input) {
73 $def_parser = KorAP::Def->new($input);
74}
Akron71cf2f52024-07-17 08:54:15 +020075else {
76 $def_parser = KorAP::Def->new($ARGV[0]);
Akron3f875be2020-05-11 14:57:19 +020077};
78
Akron71cf2f52024-07-17 08:54:15 +020079$def_parser->parse;
Akron26b59702020-05-19 12:14:41 +020080
Akron1c070452020-05-25 11:28:30 +020081# Stringify current (extended?) virtual corpus
Akron71cf2f52024-07-17 08:54:15 +020082print $def_parser->to_string;