-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-fully-abs-bin.pl
65 lines (56 loc) · 1.43 KB
/
add-fully-abs-bin.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
use strict;
# Check usage:
if($#ARGV != 0)
{
print STDERR "Usage:\n";
print STDERR " cat <rules> | perl $0 <score-names>\n";
print STDERR "where <score-names> is a space-delimited file of score names already\n";
print STDERR "appearing in <rules>\n\n";
print STDERR "Output goes to standard out and <score-names>.new\n";
exit(1);
}
# Global constants and parameters:
my $ABS_SNAME = "abstract?";
my $SN_FILE = $ARGV[0];
# Read in list of score names already in rules:
open(my $FILE, $SN_FILE) or die "Can't open input file $SN_FILE: $!";
my $line = <$FILE>;
close($FILE);
chomp $line;
my @ScoreNames = split(/\s+/, $line);
# Read rule instances from standard in, one per line:
while(my $line = <STDIN>)
{
# Break rule line into fields:
chomp $line;
my ($type, $lhs, $srcRhs, $tgtRhs, $aligns, $scores) = split(/\t/, $line);
my @srcRhsList = split(/\s+/, $srcRhs);
my @tgtRhsList = split(/\s+/, $tgtRhs);
# Check if everything on the right-hand side is a nonterminal:
my $allNT = 1;
foreach my $elt (@srcRhsList)
{
if(!($elt =~ /^\[.+,\d+\]$/))
{
$allNT = 0;
last;
}
}
if($allNT)
{
foreach my $elt (@tgtRhsList)
{
if(!($elt =~ /^\[.+,\d+\]$/))
{
$allNT = 0;
last;
}
}
}
# Add fully-abstract feature:
print "$line $allNT\n";
}
# Write out new list of score names:
open($FILE, "> $SN_FILE.new") or die "Can't open output file $SN_FILE.new: $!";
print $FILE "@ScoreNames $ABS_SNAME\n";
close($FILE);