Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Akron | 3587f36 | 2020-05-20 17:50:38 +0200 | [diff] [blame] | 2 | use strict; |
3 | use warnings; | ||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 4 | use KorAP::Def; |
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 5 | use KorAP::DefList; |
Akron | 34a4f58 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 6 | use lib 'lib'; |
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 7 | use Getopt::Long; |
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 8 | |
Akron | 99d2d08 | 2024-07-18 16:17:08 +0200 | [diff] [blame] | 9 | binmode(STDERR, ':encoding(UTF-8)'); |
10 | |||||
Akron | 340a9cb | 2020-05-20 12:55:22 +0200 | [diff] [blame] | 11 | # 2020-05-20 |
12 | # Preliminary support for C2 def-files. | ||||
Akron | 34a4f58 | 2020-05-27 12:18:57 +0200 | [diff] [blame] | 13 | # 2020-05-29 |
14 | # Introduce optimizable object system. | ||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 15 | # 2024-07-17 |
16 | # Add KorAP::Def. | ||||
Akron | 340a9cb | 2020-05-20 12:55:22 +0200 | [diff] [blame] | 17 | |
Akron | 431d957 | 2024-07-18 13:21:02 +0200 | [diff] [blame] | 18 | our $VERSION = 0.3; |
Akron | 26b5970 | 2020-05-19 12:14:41 +0200 | [diff] [blame] | 19 | our @ARGV; |
20 | |||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 21 | my $cmd = shift @ARGV; |
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 22 | |
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 23 | |
Akron | b31321e | 2024-07-18 11:17:46 +0200 | [diff] [blame] | 24 | my ($input, $output, $copysrc); |
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 25 | |
26 | GetOptions ( | ||||
Akron | b31321e | 2024-07-18 11:17:46 +0200 | [diff] [blame] | 27 | "input|i=s" => \$input, |
28 | "output|o=s" => \$output, | ||||
29 | "copy-src|c=s" => \$copysrc, | ||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 30 | ) |
31 | or die("Error in command line arguments\n"); | ||||
32 | |||||
33 | if ($cmd ne 'def' && $cmd ne 'list') { | ||||
34 | print <<'HELP'; | ||||
35 | Convert a list of C2 VC definitions or a single definition into | ||||
36 | KoralQuery 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 | |||||
Akron | b31321e | 2024-07-18 11:17:46 +0200 | [diff] [blame] | 41 | Command: 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 | |||||
47 | Command: 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 | ||||
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 53 | |
54 | HELP | ||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 55 | exit 1; |
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 56 | }; |
57 | |||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 58 | |
59 | # Process a list | ||||
60 | if ($cmd eq 'list') { | ||||
Akron | b31321e | 2024-07-18 11:17:46 +0200 | [diff] [blame] | 61 | KorAP::DefList->new( |
62 | file => ($input || $ARGV[0]), | ||||
63 | copy => ($copysrc || '.'), | ||||
64 | output => ($output || '.') | ||||
65 | )->parse; | ||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 66 | exit(0); |
67 | }; | ||||
68 | |||||
69 | # Parse a single def | ||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 70 | my $def_parser; |
Akron | 26b5970 | 2020-05-19 12:14:41 +0200 | [diff] [blame] | 71 | if ($ARGV[0] eq '-') { |
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 72 | $def_parser = KorAP::Def->new(\*STDIN); |
73 | } | ||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame] | 74 | elsif ($input) { |
75 | $def_parser = KorAP::Def->new($input); | ||||
76 | } | ||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 77 | else { |
78 | $def_parser = KorAP::Def->new($ARGV[0]); | ||||
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 79 | }; |
80 | |||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 81 | $def_parser->parse; |
Akron | 26b5970 | 2020-05-19 12:14:41 +0200 | [diff] [blame] | 82 | |
Akron | 1c07045 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 83 | # Stringify current (extended?) virtual corpus |
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 84 | print $def_parser->to_string; |