Index: branches/apertium-separable/testing/transducer.py =================================================================== --- branches/apertium-separable/testing/transducer.py (revision 79828) +++ branches/apertium-separable/testing/transducer.py (revision 79829) @@ -8,12 +8,12 @@ (3,'e') : 4, (4,'') : 5, (5,'') : 6, - (6,'') : 6, (6,'$') : 7, (7,' ') : 8, (8,'^') : 9, - (9,'c') : 10, - (10,'c') : 10, + (9, '&') : 10, + (10,'&') : 10, (10,'') : 11, (10,'') : 12, (10,'') : 13, @@ -25,8 +25,8 @@ (15,'') : 15, (15,'$') : 16, (16,' ') : 17, - (17,'^') : 18, - (18,'c') : 10, + (17,'^') : 18, #? + (18,'&') : 10, (18,'o') : 19, (19,'u') : 20, (20,'t') : 21, @@ -38,7 +38,7 @@ } states = { - -1 : '?', + -1 : '^', 0 : '^', 1 : 't', 2 : 'a', @@ -49,7 +49,7 @@ 7 : '$', 8 : ' ', 9 : '^', - 10 : 'c', #'ANY_CHAR', # + 10 : '&', #'ANY_CHAR', # 11 : '', 12 : '', 13 : '', @@ -64,37 +64,76 @@ 22 : '', 23 : '', 24 : '$', - 25 : '' + 25 : '\n', } -def next_token(): +def next_token(first_tag_passed, in_lemma, in_take, in_out): token = sys.stdin.read(1) - if token == '<': + if token == '<': #if in tag + in_lemma = False c = '' while c != '>': c = sys.stdin.read(1) token += c - # print token + if first_tag_passed: + token = '' + # first_tag_passed = True + # print in_lemma, in_take, 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, symbol): - print(states[state]) - return transitions.get((state,symbol)) #return the next state, or None if it doesn't exist +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 -print('input a string:') -current_state = -1 -c = next_token() -while states.get(current_state) != None: - current_state = step(current_state, c) #c is peeking; get next state - if current_state == None: - print('error: next state not found for ' (current_state,c) ) +def main(): + print('input a string:') + current_state = -1 + 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) + + 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) - c = next_token() -exit(0) + elif next_state == 25: + print('successful termination') + exit(0) -#^take$ ^ccccc$ ^ccccc$ ^out$ -#^take$ ^the$ ^thing$ ^out$ + 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 + # 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 str(current_state), str(states.get(current_state)) + print('error: current_state not found in states') + exit(0) -# if __name__ == '__main__': -# main() \ No newline at end of file +#^take$ ^ccccc$ ^cccc$ ^out$ +#^take$ ^the$ ^thing$ ^out$ +#^take$ ^thing$ ^out$ + + +if __name__ == '__main__': + main() \ No newline at end of file