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
|
# Check that all words, pairs, and triples in output ARGV[2] are in original ARGV[1]
BEGIN {
while (getline <ARGV[1] > 0) {
for (i = 1; i <= NF; i++) {
wd[++nw] = $i # input words
single[$i]++
}
}
for (i = 1; i < nw; i++)
pair[wd[i],wd[i+1]]++
for (i = 1; i < nw-1; i++)
triple[wd[i],wd[i+1],wd[i+2]]++
while (getline <ARGV[2] > 0) {
outwd[++ow] = $0 # output words
if (!($0 in single))
print "unexpected word:", $0
}
for (i = 1; i < ow; i++)
if (!((outwd[i],outwd[i+1]) in pair))
print "unexpected pair:", outwd[i], outwd[i+1]
for (i = 1; i < ow-1; i++)
if (!((outwd[i],outwd[i+1],outwd[i+2]) in triple))
print "unexpected triple:", outwd[i], outwd[i+1], outwd[i+2]
}
|