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