#!/freeware/bin/gnu-tools/gawk -f BEGIN { if(ARGC <= 3) {printf("Use: WLAT_FIND_SENTENCE \n") | "stderr"; exit(0); } # Read the lexicon fname = ARGV[1]; hlen = 1; while((getline < fname) == 1) # header length {hlen++; if($0 ~ "^#+$") break; } close(fname); fname = sprintf("tail +%i %s | sort",hlen,fname); iword = 0; while((fname | getline) == 1) # read data {wndx[$1] = iword; word[iword++] = $1; } close(fname); # Read and process the word graph fname = ARGV[2]; sentences = ARGV[3]; while((getline < fname) == 1) # skip header if($0 ~ "^#+$") break; sent_len = -1; isent = iline = 0; while(1) {iline++; if((EOF=((getline=0; ) {ndx = hyp_ndx[$2,ipos]; if(($2<0) && (ndx==sent_len) && (!($2 in result) || (result[$2]=0; ) {ndx = hyp_ndx[$2,ipos]; if(!(($3,ndx) in hyp_score) || (hyp_score[$3,ndx]=0; ) {if($4 != sent[ndx=hyp_ndx[$2,ipos]]) continue; ndx1 = ndx+1; if(!(($3,ndx1) in hyp_score) || (hyp_score[$3,ndx1]=-4; ) if(i in result) break; if(i in result) printf("%.3f (econd=%i,nword=%i) ",result[i],-i,sent_len); else printf("NOT_FOUND (nword=%i) ",sent_len); for(j=0;j_","",$NF); sent_len = split($NF,sword,"_"); for(i=sent_len;--i>=0; ) {sent[i] = -99; if((w=sword[i+1]) in wndx) sent[i] = wndx[w]; else printf("unkown word '%s' in sentence %i\n",w,isent) | "stderr"; sent[sent_len] = -99; } } } close(fname); close(sentences); exit(0); }