Index: branches/apertium-separable/testing/transducer.py =================================================================== --- branches/apertium-separable/testing/transducer.py (revision 79840) +++ branches/apertium-separable/testing/transducer.py (revision 79841) @@ -1,44 +1,43 @@ import sys, re transitions = { - (-1,'^') : 0, - (0,'t') : 1, - (1,'a') : 2, - (2,'k') : 3, - (3,'e') : 4, - (4,'') : 5, - (5,'') : 6, - (6,'') : 6, - (6,'$') : 7, - (7,' ') : 8, - (8,'^') : 9, - (9, '&') : 10, - (10,'&') : 10, - (10,'') : 11, - (10,'') : 12, - (10,'') : 13, - (10,'') : 14, - (11,'') : 15, - (12,'') : 15, - (13,'') : 15, - (14,'') : 15, - (15,'') : 15, - (15,'$') : 16, - (16,' ') : 17, - (17,'^') : 18, #? - (18,'&') : 10, - (18,'o') : 19, - (19,'u') : 20, - (20,'t') : 21, - (21,'') : 22, - (21,'') : 23, - (22,'$') : 24, - (23,'$') : 24, - (24,'\n') : 25 + (0,'^') : 1, + (1,'t') : 2, + (2,'a') : 3, + (3,'k') : 4, + (4,'e') : 5, + (5,'') : 6, + (6,'') : 7, + (7,'') : 7, + (7,'$'): 8, + (8,' ') : 9, + (9,'^') : 10, + (10,'&') : 11, + (11,'&') : 11, + (11,'') : 12, + (11,'') : 13, + (11,'') : 14, + (11,'') : 15, + (12,'') : 16, + (13,'') : 16, + (14,'') : 16, + (15,'') : 16, + (16,'') : 16, + (16,'$') : 17, + (17,' ') : 18, + (18,'^') : 19, #? + (19,'&') : 11, + (19,'o') : 20, + (20,'u') : 21, + (21,'t') : 22, + (22,'') : 23, + (23,'') : 24, + (23,'$') : 25, + (24,'$') : 25, + (25,'\n') : 26 } states = { - -1 : '^', 0 : '^', 1 : 't', 2 : 'a', @@ -46,29 +45,31 @@ 4 : 'e', 5 : '', 6 : '', # - 7 : '$', - 8 : ' ', - 9 : '^', - 10 : '&', #'ANY_CHAR', # - 11 : '', - 12 : '', - 13 : '', - 14 : '', - 15 : '', - 16 : '$', - 17 : ' ', - 18 : '^', - 19 : 'o', - 20 : 'u', - 21 : 't', - 22 : '', - 23 : '', - 24 : '$', - 25 : '\n', + 7 : '', #the second one + 8 : '$', + 9 : ' ', + 10 : '^', + 11 : '&', #'ANY_CHAR', # + 12 : '', + 13 : '', + 14 : '', + 15 : '', + 16 : '', + 17 : '$', + 18 : ' ', + 19 : '^', + 20 : 'o', + 21 : 'u', + 22 : 't', + 23 : '', + 24 : '', + 25 : '$', + 26 : '\n', } def next_token(first_tag_passed, in_lemma, in_take, in_out): token = sys.stdin.read(1) + # print 'next_token' + token if token == '<': #if in tag in_lemma = False c = '' @@ -79,61 +80,57 @@ token = '' # first_tag_passed = True # print in_lemma, in_take, in_out + if in_lemma and not in_take and not in_out: # print in_lemma, in_take, in_out - if in_lemma and not in_take and not in_out: token = '&' #ANY_CHAR - # if token == '^': - # in_lemma = True - # if token == '^': - # c = sys.stdin.read(1) - # # while c != '<': - # token += c - # c = sys.stdin.read(1) #unread? - # elif token == '\n': - # return '' return token -def step(state, token): - print(states[state] + str(state)) - # if state == 6 or state == 15: - # token = '' - return transitions.get((state,token)) #return the next state, or None if it doesn't exist +def step(state, token): #token is at the next state + next_state = transitions.get((state,token)) + if next_state == None: + # print(str(state), str(current_state), str(token)) + print('error: (current_state,token) pair not found in transitions. ' + str(current_state) + str(token)) + exit(1) + elif next_state == 25: + print('successful termination') + exit(0) + + print states[next_state] + # print('inside step(): printing ' + states[next_state] + ' current state ' + str(next_state)) #prints the prev token + return next_state #transitions.get((state,token)) #return the next state, or None if it doesn't exist + def main(): print('input a string:') - current_state = -1 + current_state = 0 first_tag_passed = False in_lemma = False in_take = False in_out = False - token = next_token(first_tag_passed, in_lemma, in_take, in_out) + # token = next_token(first_tag_passed, in_lemma, in_take, in_out) while states.get(current_state) != None: - next_state = step(current_state, token) #c is peeking; get next state - if next_state == None: - # print(str(state), str(current_state), str(token)) - print('error: (current_state,token) pair not found in transitions. ' + str(current_state) + str(token)) - exit(1) - elif next_state == 25: - print('successful termination') - exit(0) + token = next_token(first_tag_passed, in_lemma, in_take, in_out) + # print 'before step(): token = ' + token + ' current_state = ' + str(current_state) + next_state = step(current_state, token) - first_tag_passed = next_state in [5, 6, 11, 12, 13, 14, 15] - in_lemma = next_state in [1, 9, 10, 18] - in_take = current_state in [0, 1, 2, 3, 4] #-4 + first_tag_passed = next_state in [6, 7, 16, 12, 13, 14, 15, 16] #out not included + in_lemma = next_state in [1, 2, 3, 4, 10, 11, 20, 21, 22] #take and out don't need to be included? + in_take = next_state in [1, 2, 3, 4] # in_out = sys.stdin.read(4) == 'out<' in_out = next_state in [19, 20, 21] #-21 #should be: if peek(sys.stdin.read(3) == 'out<' current_state = next_state - token = next_token(first_tag_passed, in_lemma, in_take, in_out) + # print first_tag_passed, in_lemma, in_take, in_out + # print 'token' + token # print str(current_state), str(states.get(current_state)) - print('error: current_state not found in states') + print('error: current_state ' + state + ' not found in states') exit(0) #^take$ ^ccccc$ ^cccc$ ^out$ #^take$ ^the$ ^thing$ ^out$ -#^take$ ^thing$ ^out$ +#^take$ ^thing$ ^out$ +#^take$ ^thing$ ^out$ - if __name__ == '__main__': main() \ No newline at end of file