File size: 2,118 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 54 55 56 57 58 59 60 61 |
'''
Created on ٢٣/٠٣/٢٠١٠
@Created by: Muhammad Altabba
'''
import re;
class TransitionAction(object):
"""
# PyUML: Do not remove this line! # XMI_ID:_qzIINI35Ed-gg8GOK1TmhA
"""
'''
State Action
'''
Type = '';
AttributeName = '';
Value = '';
OnRelativeIndex = 0;
def __init__(self, attributeName, type, value, onRelativeIndex):
'''
Constructor
'''
self.AttributeName = attributeName;
self.Type = type;
self.Value = value;
self.OnRelativeIndex = onRelativeIndex;
pass
def ApplyToWord(self, sentence, wordIndex):
# print('-- apply...');
word = sentence.Words[wordIndex + self.OnRelativeIndex];
if self.Type == 'str':
setattr(word, self.AttributeName, self.Value);
elif self.Type == 'set.append':
# print('-- apply:')
eval('word.'+self.AttributeName).append(eval(self.Value));
# word.__getattribute__(self.AttributeName).append(eval(self.Value));
elif self.Type == 'dict':
# #Test Needed -------------------------------------------------------------
#value has the shape: {key1: value1, key2: value2}
dictionary = eval(self.Value);
for key, value in dictionary.items():
word.__getattribute__(self.AttributeName)[key] = value;
elif self.Type == 'general':
setattr(word, self.AttributeName, eval(self.Value));
# #Test Needed -------------------------------------------------------------
pass
def ApplyToWordSurfaceFormMorphemes(self, sentence, wordIndex, surfaceFormMorphemesIndexes):
# print('-- apply ApplyToWordSurfaceFormMorphemes...');
word = sentence.Words[wordIndex + self.OnRelativeIndex];
if self.Type == 'method':
for i in range(len(surfaceFormMorphemesIndexes)):
eval('word.SurfaceFormMorphemes[surfaceFormMorphemesIndexes[i]].'+self.AttributeName+'('+self.Value+')');
pass
|