|
|
| ''' |
| Created on ٠٢/٠٤/٢٠١٠ |
| |
| @Created by: Muhammad Altabba |
| ''' |
| from ...Controllers.Tokenization.TokenType import TokenType; |
| from ..Transducers.StatesGraph import *; |
| from ..Transducers.State import *; |
|
|
|
|
| class AffixParser(object): |
| """ |
| # PyUML: Do not remove this line! # XMI_ID:_qyiSsI35Ed-gg8GOK1TmhA |
| """ |
| ''' |
| Morphological Affix Parser. |
| ''' |
|
|
| def __init__(self): |
| ''' |
| Constructor |
| ''' |
| |
| def ParsePrefix(self, sentences, statesGraphs): |
| |
| |
| for i in range(len(sentences)): |
| j = 0; |
| while j <len(sentences[i].Words): |
| while(j < len(sentences[i].Words) and ( |
| sentences[i].Words[j].TokenType.Id != TokenType.Constants.Id.ArabicText\ |
| or sentences[i].Words[j].MorphologicalParsingCompleted == True)): |
| j += 1; |
| if(j == len(sentences[i].Words)): |
| break; |
| for k2 in range(len(statesGraphs)): |
| |
| statesGraph = StatesGraph(statesGraphs[k2].Start, statesGraphs[k2].States); |
| state = statesGraph.Start; |
| |
| l = 0; |
| while l < len(sentences[i].Words[j].String): |
| [nextState, numberToConsume] = statesGraph.Match(state, sentences[i], j, l); |
| |
| if type(nextState) is State: |
| l += numberToConsume; |
| |
| |
| if nextState.IsEnd == True: |
| |
| for currentWordIndex, actions in statesGraph.ActionsToApply.items(): |
| actions.ApplyToWord(sentences[i], currentWordIndex); |
| |
| |
| statesGraph.ActionsToApply.clear(); |
| state = nextState; |
| else: |
| break; |
| j += 1; |
| pass |
|
|
| |
| def ParseSuffix(self, sentences, statesGraphs): |
| |
| |
| for i in range(len(sentences)): |
| j = 0; |
| while j <len(sentences[i].Words): |
| while(j < len(sentences[i].Words) and ( |
| sentences[i].Words[j].TokenType.Id != TokenType.Constants.Id.ArabicText\ |
| or sentences[i].Words[j].MorphologicalParsingCompleted == True)): |
| j += 1; |
| if(j == len(sentences[i].Words)): |
| break; |
| for k2 in range(len(statesGraphs)): |
| |
| statesGraph = StatesGraph(statesGraphs[k2].Start, statesGraphs[k2].States); |
| state = statesGraph.Start; |
| |
| l = len(sentences[i].Words[j].String)-1; |
| while l >= 0: |
| |
| [nextState, numberToConsume] = statesGraph.Match(state, sentences[i], j, l, False); |
| |
| if type(nextState) is State: |
| |
| l -= numberToConsume; |
| |
| |
| if nextState.IsEnd == True: |
| |
| for currentWordIndex, actions in statesGraph.ActionsToApply.items(): |
| |
| actions.ApplyToWord(sentences[i], currentWordIndex); |
| |
| |
| |
| statesGraph.ActionsToApply.clear(); |
| state = nextState; |
| else: |
| |
| break; |
| j += 1; |
|
|