def checkSMCstr(strch, dict_valnames): machine = AppClass.AppClass() # print(machine.GetValDict()) machine.SetValDict(dict_valnames) # print(machine.GetValDict()) match = machine.CheckString(strch) # print(machine.GetValDict()) if match: return str(machine.GetStrNum()) + ' : ' + str(machine.getNumLitstr()) else: return 'Unacceptable'
def from_console(): # Ctrl + D to stop start = time.time() recognizer = AppClass.AppClass() for line in sys.stdin: match = recognizer.CheckString(line[:-1]) if match: print('OK') check = recognizer.check_conflicts() if check is not None: print('conflict: ' + check[0] + ' initial type is ' + check[1]) else: print('NOT OK') end = time.time() with open('time.txt', 'w') as f: f.write(str(end - start))
def iscorrect(st): retcode = 0 if len(st) < 1: print("No string to check.\n") retcode = 2 else: appobject = AppClass.AppClass() if appobject.CheckString(st) == False: f.write(st + ' is not acceptable\n') retcode = 1 else: if d.get(appobject._func) == None: d[appobject._func] = 1 else: d[appobject._func] = d[appobject._func] + 1 f.write(st + ' is acceptable\n') return retcode
def from_file(): recognizer = AppClass.AppClass() f = open('generated_10000.txt', 'r') res = open('results.txt', 'w') start = time.time() for line in f.readlines(): match = recognizer.CheckString(line) if match: res.write(line + ' OK ') check = recognizer.check_conflicts() if check is not None: res.write('conflict: ' + check[0] + ' initial type is ' + check[1] + '\n') else: res.write('\n') else: res.write(line + ' NOT OK ' + '\n') end = time.time() with open('time.txt', 'w') as tm: tm.write(str(end - start)) f.close()
def SMCcheck(): machine = AppClass.AppClass() f = open('genSTR.txt', 'r') res = open('resSMC.txt', 'w') ftime = open('timeSMC.txt', 'w') time_start = time.perf_counter() numline = 0 for line in f.readlines(): numline += 1 match = machine.CheckString(line) if match: # print(machine.GetStrNum() + ': ' + str(machine.getNumLitstr())) res.write( str(machine.GetStrNum()) + ' : ' + str(machine.getNumLitstr()) + '\n') if numline % 10000 == 0: ftime.write(str(time.perf_counter() - time_start) + '\n') print('***File was checked by SMC***') ftime.close() f.close() res.close()
def analyze(filename): checker = AppClass.AppClass() with open('timing-smc.txt', 'w') as out: out.write('# amount TIME\n') with open(filename, 'r') as dt: cnt = 0 start = time.time() for line in dt: cnt += 1 checker.CheckString(line) if not cnt % 100000: end = time.time() with open('timing-smc.txt', 'a') as out: out.write( str(cnt / 100000) + ' ' + str(end - start) + '\n') cnt = checker.get_lines_read() dct = dict(reversed(sorted(checker.get_dict().items(), key=lambda x: x[1]))) with open('answer_smc.txt', 'w') as ans: ans.write('Lines read successfully: ' + str(cnt) + '\n') ans.writelines( ['Variable ' + x + '---' + str(dct[x]) + '\n' for x in dct.keys()])
# $Id: checkstring.py,v 1.1 2005/05/28 17:48:29 cwrapp Exp $ # # CHANGE LOG # $Log: checkstring.py,v $ # Revision 1.1 2005/05/28 17:48:29 cwrapp # Added Python examples 1 - 4 and 7. # # import sys import AppClass retcode = 0 if len(sys.argv) < 2: print "No string to check.\n" retcode = 2 elif len(sys.argv) > 2: print "Only one argument is accepted.\n" retcode = 3 else: appobject = AppClass.AppClass() str = sys.argv[1] if appobject.CheckString(str) == False: result = "not acceptable" retcode = 1 else: result = "acceptable" print 'The string "%s" is %s.\n' % (str, result) sys.exit(retcode)