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 | |
22 | my $input; | ||||
23 | |||||
24 | GetOptions ( | ||||
25 | "input|i=s" => \$input | ||||
26 | ) | ||||
27 | or die("Error in command line arguments\n"); | ||||
28 | |||||
29 | if ($cmd ne 'def' && $cmd ne 'list') { | ||||
30 | print <<'HELP'; | ||||
31 | Convert a list of C2 VC definitions or a single definition into | ||||
32 | KoralQuery VCs. | ||||
33 | |||||
34 | $ perl cosmasvc2koralquery def my_vc.txt | gzip -vc > my_vc.jsonld.gz | ||||
35 | $ cat my_vc.txt | perl cosmasvc2koralquery def - | gzip -vc > my_vc.jsonld.gz | ||||
36 | |||||
37 | Commands: def, list | ||||
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 38 | |
39 | HELP | ||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame^] | 40 | exit 1; |
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 41 | }; |
42 | |||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame^] | 43 | |
44 | # Process a list | ||||
45 | if ($cmd eq 'list') { | ||||
46 | KorAP::DefList->new($input || $ARGV[0])->parse; | ||||
47 | exit(0); | ||||
48 | }; | ||||
49 | |||||
50 | # Parse a single def | ||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 51 | my $def_parser; |
Akron | 26b5970 | 2020-05-19 12:14:41 +0200 | [diff] [blame] | 52 | if ($ARGV[0] eq '-') { |
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 53 | $def_parser = KorAP::Def->new(\*STDIN); |
54 | } | ||||
Akron | a3f74f5 | 2024-07-17 17:18:17 +0200 | [diff] [blame^] | 55 | elsif ($input) { |
56 | $def_parser = KorAP::Def->new($input); | ||||
57 | } | ||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 58 | else { |
59 | $def_parser = KorAP::Def->new($ARGV[0]); | ||||
Akron | 3f875be | 2020-05-11 14:57:19 +0200 | [diff] [blame] | 60 | }; |
61 | |||||
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 62 | $def_parser->parse; |
Akron | 26b5970 | 2020-05-19 12:14:41 +0200 | [diff] [blame] | 63 | |
Akron | 1c07045 | 2020-05-25 11:28:30 +0200 | [diff] [blame] | 64 | # Stringify current (extended?) virtual corpus |
Akron | 71cf2f5 | 2024-07-17 08:54:15 +0200 | [diff] [blame] | 65 | print $def_parser->to_string; |