File size: 1,539 Bytes
21baa2f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
'''
Created on ١٩/٠٣/٢٠١٠
@Created by: Muhammad Altabba
'''
from .State import State
from .TransitionCondition import TransitionCondition
class StatesGraph(object):
"""
# PyUML: Do not remove this line! # XMI_ID:_qzIIAo35Ed-gg8GOK1TmhA
"""
'''
Store Graph of States of on-memory Tagging rules
'''
States = dict();
Start = None;
ActionsToApply = dict();
#Dictionary maps between each end and the desired action.
#Keys are RELATIVE_WORD_INDEX and values are list of ACTIONS.
def __init__(self, start = None, states = None):
'''
Constructor
'''
if states == None:
self.States = dict();
self.Start = start;
self.ActionsToApply = dict();
pass
def Match(self, currentState, sentence, wordNumber, charIndex = None, charIndexForward = True):
# print('-- Match...');
[nextState, actions, numberToConsume] = currentState.NextStateWithActions(sentence.Words[wordNumber], charIndex, charIndexForward);
# print('-- [nextState, actions, numberToConsume] = '+str([nextState, actions, numberToConsume]));
if nextState != None:
if wordNumber not in self.ActionsToApply.keys():
self.ActionsToApply[wordNumber] = actions;
else:
self.ActionsToApply[wordNumber].Actions.append(actions);
return [nextState, numberToConsume];
return [None, None];
pass
|