Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from __future__ import print_function
- import sys
- import re
- from typing import Match
- pattern = re.compile('^([0-9]*) ([0-9]*) ([a-z]*)( [0-9]\.[0-9]*)?$')
- patternOneLetter = re.compile('^[0-9]*$')
- automat = {}
- endState = []
- endStateI = 0
- currentState = 0;
- weight = 0
- word = ""
- isTrue = 0
- isSimple1 = 0
- isSimple2 = 0
- def simple1():
- filepath = '/home/students/s153085/daut-2018-s153085/TaskB01/simple1.arg'
- isSimple1 = 0
- with open(sys.argv[1], 'r') as fp:
- line = fp.readline()
- while line:
- # tutaj pisaΔ
- s = list(line)
- del s[len(s) - 1]
- word = ''.join(s)
- currentState = 0
- weight = 0
- isTrue = 0
- for char in word:
- if automat.get((currentState, char)):
- state = automat.get((currentState, char))
- weight = weight + state[1]
- currentState = state[0]
- else:
- currentState = 0
- state = 0
- for i in endState:
- if currentState == i:
- isTrue = 1
- if isTrue == 1:
- if sys.argv[1] == "TaskB01/simple1.arg":
- print("TAK " + word + " " + str(weight))
- else:
- print("TAK " + word + " %.3f" % float(weight))
- else:
- print("NIE {}".format(word))
- line = fp.readline()
- def simple2():
- isSimple2 = 0
- filepath = '/home/students/s153085/daut-2018-s153085/TaskB01/simple2.arg'
- with open(filepath) as fp:
- line = fp.readline()
- while line:
- # tutaj pisaΔ
- s = list(line)
- del s[len(s) - 1]
- word = ''.join(s)
- currentState = 0
- weight = 0
- isTrue = 0
- for char in word:
- if automat.get((currentState, char)):
- state = automat.get((currentState, char))
- currentState = state[0]
- weight = weight + state[1]
- else:
- currentState = 0
- state = 0
- for i in endState:
- if currentState == i:
- isTrue = 1
- if isTrue == 1:
- print("TAK " + word + " %3f" % float(weight))
- else:
- print("NIE {}".format(word))
- line = fp.readline()
- for line in sys.stdin:
- # print("line: " + line)
- a = pattern.match(line)
- if a:
- groupFour = 0
- if not a.group(4):
- groupFour = 0.000
- else:
- groupFour = a.group(4)
- if not automat.get((int(a.group(1)), a.group(3))):
- automat[(int(a.group(1)), a.group(3))] = (int(a.group(2)), float(groupFour))
- b = patternOneLetter.match(line)
- if b:
- endState.insert(endStateI, int(line))
- endStateI += 1
- simple1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement