コード例 #1
0
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."
コード例 #2
0
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."
コード例 #3
0
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()
    if sopt == "E":
        sandhi.sandhioptions("E", "N", "S", "Y")
        soptPrint = "E,N,S,Y"
    elif sopt == "E1":
        sandhi.sandhioptions("E", "N", "S", "")
        soptPrint = "E,N,S,"
    elif sopt == "C":
        sandhi.sandhioptions("C", "N", "S", "")
        soptPrint = "C,N,S,"
    else:
        print "ERROR: 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:", soptPrint
            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."
コード例 #4
0
"""
 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)
コード例 #5
0
"""
 ScharfSandhiArg.py  May 25, 2015
 Python equivalent of ScharfSandhiArg.java
 
"""
from scharfsandhi import ScharfSandhi
ScharfSandhi.dbg = True  # July 24, 2015
if __name__ == '__main__':
    import sys
    sopt = sys.argv[1]
    s = sys.argv[2]
    if sopt == "E":
        err = ScharfSandhi.sandhioptions("E", "N", "S", "Y")
        soptPrint = "E,N,S,Y"
    elif sopt == "E1":
        err = ScharfSandhi.sandhioptions("E", "N", "S", "")
        soptPrint = "E,N,S,"
    elif sopt == "C":
        err = ScharfSandhi.sandhioptions("C", "N", "S", "")
        soptPrint = "C,N,S,"
    else:
        print "ERROR: sopt must be E, E1, or C, not", sopt
        exit(1)
    ans = ScharfSandhi.sandhi(s)
    print(ans)
コード例 #6
0
"""
 ScharfSandhiArg.py  May 25, 2015
 Jul 26, 2015. 
 Jul 27, 2015
"""
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
    if sopt == "E":
        err = sandhi.sandhioptions("E", "N", "S", "Y")
        soptPrint = "E,N,S,Y"
    elif sopt == "E1":
        err = sandhi.sandhioptions("E", "N", "S", "")
        soptPrint = "E,N,S,"
    elif sopt == "C":
        err = sandhi.sandhioptions("C", "N", "S", "")
        soptPrint = "C,N,S,"
    else:
        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
コード例 #7
0
"""
 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
    ec = sys.argv[1]
    despace = sys.argv[2]
    s = sys.argv[3]
    sandhi = ScharfSandhi()
    sandhi.history = []  # init history.  It is modified by wrapper
    sandhi.dbg = True
    err = sandhi.sandhioptions(ec, "N", "S", despace)
    if err != 0:
        print("ERROR: options must be E or C, Y or N, not:", ec, despace)
        exit(1)
    ans = sandhi.sandhi(s)
    for h in sandhi.history:
        print(h)
    print('ScharfSandhiArg: ans="%s"' % ans)
コード例 #8
0
"""
 ScharfSandhiArg.py  May 25, 2015
 Jul 26, 2015. 
 
"""
from scharfsandhi import ScharfSandhi

if __name__ == '__main__':
    import sys
    sopt = sys.argv[1]
    s = sys.argv[2]
    sandhi = ScharfSandhi()
    sandhi.dbg = True
    if sopt == "E":
        err = sandhi.sandhioptions("E", "N", "S", "Y")
        soptPrint = "E,N,S,Y"
    elif sopt == "E1":
        err = sandhi.sandhioptions("E", "N", "S", "")
        soptPrint = "E,N,S,"
    elif sopt == "C":
        err = sandhi.sandhioptions("C", "N", "S", "")
        soptPrint = "C,N,S,"
    else:
        print "ERROR: sopt must be E, E1, or C, not", sopt
        exit(1)
    ans = sandhi.sandhi(s)
    print(ans)