-
Notifications
You must be signed in to change notification settings - Fork 3
/
extractEntries.pl
executable file
·136 lines (127 loc) · 3.46 KB
/
extractEntries.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#/usr/bin/perl -w
#use strict;
use warnings;
use utf8;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
use Getopt::Long qw(GetOptions);
my $outputfilename = 'n-vroot.prq.foma';
my $label = 'N@->V';
my $title = 'Verbalized nouns';
my $header = 'NounToVerbPRQin';
my $separatorsymbol = "[--]";
my $separator = 0;
my $replace1 = 0;
my $source1 = " : {";
my $target1 = " : \"\@EP\"{";
my $replace2 = 0;
my $source2 = " : {";
my $target2 = " : \"\@EP\"{";
my $replace3 = 0;
my $source3 = " : {";
my $target3 = " : \"\@EP\"{";
# Obtaining the options
my @files;
my $options = "--file file_1 --file file_2 ... ";
GetOptions (
'file=s' => \@files,
'outputfilename=s' => \$outputfilename,
'label=s' => \$label,
'title=s' => \$title,
'header=s' => \$header,
"separator=i" => \$separator,
"replace1=i" => \$replace1,
"replace2=i" => \$replace2,
"replace3=i" => \$replace3,
'source1=s' => \$source1,
'target1=s' => \$target1,
'source2=s' => \$source2,
'target2=s' => \$target2,
'source3=s' => \$source3,
'target3=s' => \$target3,
) or die " Usage: $0 $options\n";
#if (@files) {
# print STDERR " Usage: $0 $options\n";
# exit;
#}
print STDERR " $label\n";
open(my $fh, '>', $outputfilename) or die "Could not open file '$outputfilename' $!";
print $fh "# -----------------\n";
print $fh "# $title \n";
print $fh "# -----------------\n";
print $fh "define $header [ \n";
my $count = 0;
my $file;
while (defined($file = shift @files)) {
open INFO, $file or die "Could not open $file: $!";
while (<INFO>)
{
if (m/$label/) {
if ($count == 0) {
my $myvar = $_;
if ($separator == 1) { $myvar =~ s/\"/\"$separatorsymbol/; }
if ($replace1 == 1) { $myvar =~ s/$source1/$target1/; }
if ($replace2 == 1) {
# splitting
if ($myvar =~ m/N@\->V::\[(.*)\]\s/) {
my $targetstring = "::[$1] ";
$targetstring =~ s/^\s+|\s+$//g;
$myvar =~ m/(.*)$source2/g;
my $result = "$1$targetstring$target2";
$myvar =~ m/$source2(.*)/s;
$myvar = "$result$1";
}
elsif ($myvar =~ m/V@\->N::\[(.*)\]\s/) {
my $targetstring = "::[$1] ";
$targetstring =~ s/^\s+|\s+$//g;
$myvar =~ m/(.*)$source2/g;
my $result = "$1$targetstring$target2";
$myvar =~ m/$source2(.*)/s;
$myvar = "$result$1";
}
else {
$myvar =~ s/$source2/$target2/;
}
}
if ($replace3 == 1) { $myvar =~ s/$source3/$target3/; }
$myvar =~ s/^\|/ /g;
print $fh $myvar;
}
else {
my $myvar = $_;
substr($myvar, 0, 1, "|") if " " eq substr($myvar, 0, 1);
if ($separator == 1) { $myvar =~ s/\"/\"$separatorsymbol/; }
if ($replace1 == 1) { $myvar =~ s/$source1/$target1/; }
if ($replace2 == 1) {
# splitting
if ($myvar =~ m/N@\->V::\[(.*)\]\s/) {
my $targetstring = "::[$1] ";
$targetstring =~ s/^\s+|\s+$//g;
$myvar =~ m/(.*)$source2/g;
my $result = "$1$targetstring$target2";
$myvar =~ m/$source2(.*)/s;
$myvar = "$result$1";
}
elsif ($myvar =~ m/V@\->N::\[(.*)\]\s/) {
my $targetstring = "::[$1] ";
$targetstring =~ s/^\s+|\s+$//g;
$myvar =~ m/(.*)$source2/g;
my $result = "$1$targetstring$target2";
$myvar =~ m/$source2(.*)/s;
$myvar = "$result$1";
}
else {
$myvar =~ s/$source2/$target2/;
}
}
if ($replace3 == 1) { $myvar =~ s/$source3/$target3/; }
print $fh $myvar;
}
$count++;
}
else { }
}
close(INFO);
}
print $fh "];\n";
close $fh;