def testfile(filein,fileknown,sopt): with open(filein,"r") as f: lines = [l.rstrip('\r\n ') for l in f] with open(fileknown,"r") as f: correct = [l.rstrip('\r\n ') for l in f] sandhi = ScharfSandhi() err = sandhi.simple_sandhioptions(sopt) if err != 0: print "ERROR",err," sopt must be E, E1, or C, not",sopt exit(1) i=0 nok = 0 for line in lines: out = sandhi.sandhi(line) known = correct[i] ok = "?" if out == known: ok = "OK" nok = nok+1 else: ok = "PROBLEM" print "Problem at line",i print " input:",line print " options:",sopt print "computed:",out print "standard:",known print "========================================" i = i + 1 print "Test Results:" print "Input:",filein print "Standard:",fileknown print nok,"input lines were ok out of",len(lines),"total lines."
def testfile2(filein): with open(filein, "r") as f: cases = [Case(l.rstrip('\r\n ')) for l in f] sandhi = ScharfSandhi() i = 0 nok = 0 icase = 0 for case in cases: icase = icase + 1 (sopt, line, known) = (case.sopt, case.input, case.answer) err = sandhi.simple_sandhioptions(sopt) if err != 0: print "ERROR", err, " sopt must be E, E1, or C, not", sopt print "line", icase, "of file", filein exit(1) out = sandhi.sandhi(line) ok = "?" if out == known: ok = "OK" nok = nok + 1 else: ok = "PROBLEM" print "Problem at case", i print " options:", sopt print " input:", line print "computed:", out print "standard:", known print "========================================" i = i + 1 print "Test Results for file:", filein print nok, "input case were ok out of", len(cases), "total cases."
""" ScharfSandhiArg.py May 25, 2015 Jul 26, 2015. Jul 27, 2015 9 May 2020 PMS added parenthesis for python 3 compatibility """ from scharfsandhi import ScharfSandhi if __name__ == '__main__': import sys sopt = sys.argv[1] s = sys.argv[2] sandhi = ScharfSandhi() sandhi.history=[] # init history. It is modified by wrapper sandhi.dbg=True err = sandhi.simple_sandhioptions(sopt) if err != 0: print("ERROR: sopt must be E, E1, or C, not",sopt) exit(1) ans = sandhi.sandhi(s) for h in sandhi.history: print(h) print('ScharfSandhiArg: ans="%s"' % ans)