File size: 4,782 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
'''
Created on ٢٨/٠٦/٢٠١٠
@Created by: Muhammad Altabba
'''
from xml.dom import minidom
from ..Lexicon.SpecialWords.StandAloneParticle import *;
from ..Lexicon.SpecialWords.ProperNoun import *;
from ..Lexicon.SpecialWords.ClosedNouns import *;
from ...Controllers.Morphology.Entities.UnderivedCliticless import UnderivedCliticless;
from ..Tagging.POSTags.POS import POSConstants;
from ..Tagging.POSTags.NominalPOS import *;
class SpecialWordsRepository(object):
"""
# PyUML: Do not remove this line! # XMI_ID:_q0BgAo35Ed-gg8GOK1TmhA
"""
'''
Special Words Loader
'''
ProperNouns = dict();
Particles = dict();
ClosedNouns = dict();
CompoundNouns = dict();
def __init__(self):
'''
Constructor
'''
self.ProperNouns = dict();
self.Particles = dict();
self.ClosedNouns = dict();
self.CompoundNouns = dict();
pass
def Load(self, basePath):
self.ProperNouns = self.LoadProperNouns(basePath + 'specialwords/');
self.Particles = self.LoadParticles(basePath + 'specialwords/');
file = 'closednouns.xml';
self.ClosedNouns = self.LoadClosedNouns(basePath + 'specialwords/', file);
file = 'compoundnouns.xml';
self.CompoundNouns = self.LoadClosedNouns(basePath + 'specialwords/', file);
pass
def LoadProperNouns(self, path):
file = 'propernouns.xml';
tempDict = dict();
xmldoc = minidom.parse(path + file);
for xmlRoot in xmldoc.getElementsByTagName('propernoun'):
unvoweled = xmlRoot.attributes['unvoweledform'].value;
voweled = xmlRoot.attributes['voweledform'].value;
# tempDict[unvoweled] = ProperNoun(unvoweled, voweled);
if(unvoweled not in tempDict.keys()):
tempDict[unvoweled] = [ProperNoun(unvoweled, voweled)];
else:
# print(str(type(tempDict[unvoweled])));
tempDict[unvoweled].append(ProperNoun(unvoweled, voweled));
return tempDict;
pass
def LoadClosedNouns(self, path, file):
tempDict = dict();
xmldoc = minidom.parse(path + file);
for xmlRoot in xmldoc.getElementsByTagName('noun'):
unvoweled = xmlRoot.attributes['unvoweledform'].value;
voweled = xmlRoot.attributes['voweledform'].value;
prefixeclass = xmlRoot.attributes['prefixeclass'].value;
suffixeclass = xmlRoot.attributes['suffixeclass'].value;
type = xmlRoot.attributes['type'].value;
if('case' in xmlRoot.attributes.keys()):
case = xmlRoot.attributes['case'].value;
else:
case = '';
if('gender' in xmlRoot.attributes.keys()):
gender = xmlRoot.attributes['gender'].value;
else:
gender = '';
if('number' in xmlRoot.attributes.keys()):
number = xmlRoot.attributes['number'].value;
else:
number = '';
definiteness = xmlRoot.attributes['definiteness'].value;
closedNoun = ClosedNoun(unvoweled, voweled);
closedNoun.AssignFromAlKalilDB(prefixeclass, suffixeclass,\
type, definiteness, gender, case, number);
if(unvoweled not in tempDict.keys()):
tempDict[unvoweled] = [closedNoun];
else:
tempDict[unvoweled].append(closedNoun);
return tempDict;
pass
def LoadParticles(self, path):
file = 'standaloneparticles.xml';
tempDict = dict();
tempList = [];
xmldoc = minidom.parse(path + file);
for xmlRoot in xmldoc.getElementsByTagName('particle'):
unvoweled = xmlRoot.attributes['unvoweledform'].value;
voweled = xmlRoot.attributes['voweledform'].value;
prefixeclass = xmlRoot.attributes['prefixeclass'].value;
suffixeclass = xmlRoot.attributes['suffixeclass'].value;
type = xmlRoot.attributes['type'].value;
particle = StandAloneParticle();
particle.AssignFromAlKalilDB(unvoweled, voweled, prefixeclass, suffixeclass, type);
tempList.append(particle);
if(unvoweled not in tempDict.keys()):
tempDict[unvoweled] = [];
tempDict[unvoweled].append(len(tempList)-1);
return [tempDict, tempList];
pass
|