-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter-noAnswer.awk
30 lines (30 loc) · 1001 Bytes
/
filter-noAnswer.awk
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
function strip( thing ) {
sub(" *$","",thing);sub("^ *","",thing);
return thing;
}
function finish( id,doc,question,answer,candidates, A,n,i ) {
answer=tolower(strip(answer));
doc=tolower(strip(doc));
#print "id: " id,"doc: ",doc,"question: " question,"answer: " answer,"candidates:",candidates;
if (index(doc,answer)==0) {
gsub("-"," ",answer);
#print "re-answer: " answer;
if (index(doc,answer)==0) { print id; }
}
#print "</entry>";
}
BEGIN { RS="\n\n";FS=OFS="\n";state="id"; }
{
if (state == "id") {
if (id) {
finish(id,doc,question,answer,candidates);
}
for(i=1;i<=NF;i++) {id=$i; if (id !~ /^[#]/) break;}
state="doc";
}
else if (state == "doc") { doc=$0; state="question"; }
else if (state == "question") { question=$0; state="answer"; }
else if (state == "answer") { answer=$0; state="candidates"; }
else if (state == "candidates") { candidates=$0; state="id"; }
}
END { finish(id,doc,question,answer,candidates); }