Commit 2d61f0d5 authored by Alexis Nasr's avatar Alexis Nasr
Browse files

modification de Config.py pour prendre en compte des Configuration Features,...

modification de Config.py pour prendre en compte des Configuration Features, attention, la lecture des Configuration Features dans FeatModel.py n'est pas encore implémentée, correction d'un bug dans Word.py
parent 33c26755
......@@ -84,40 +84,93 @@ class Config:
elif(mvt_type == 'REDUCE'):
return self.red()
return False
def getWordFeat(self, featTuple):
container = featTuple[1]
index = featTuple[2]
tape = featTuple[3]
if(container == 'B'):
# if((index < self.getBuffer().getLength()) and (index >= 0)):
def getWordWithRelativeIndex(self, container, index):
if container == 'S' :
if index >= self.getStack().getLength() :
return None
indexInBuffer = self.getStack().array[self.getStack().getLength() - index - 1]
return self.getBuffer().getWord(indexInBuffer)
elif container == 'B' :
absoluteIndex = self.getBuffer().getCurrentIndex() + index
if absoluteIndex < self.getBuffer().getLength() and absoluteIndex >= 0 :
w = self.getBuffer().getWord(absoluteIndex)
else:
#print('word feature ', container, '.', index, '.', tape, ' cannot be interpreted, index ', index, "is out of bound")
return 'NULL'
else:
if(index < self.getStack().getLength()):
#print('on cherche dans', self.getStack().getLength() - index - 1, "")
w = self.getBuffer().getWord(self.getStack().array[self.getStack().getLength() - index - 1])
if w == None :
return 'NULL'
else:
#print('word feature ', container, '.', index, '.', tape, ' cannot be interpreted, index ', index, "is out of bound")
return 'NULL'
return w.getFeat(tape)
# print('word feature ', container, '.', index, '.', tape, ' cannot be interpreted, tape ', tape, "is unknown")
return self.getBuffer().getWord(absoluteIndex)
else :
return None
return None
# return 'NULL'
def getFeat(self, featTuple):
featType = featTuple[0]
if(featType == 'W'):
return self.getWordFeat(featTuple)
elif(featType == 'C'):
return self.getConfFeat(featTuple)
def getConfFeat(self, featTuple):
featSubType = featTuple[1]
if featSubType == 'DIST':
return self.getDistFeat(featTuple)
elif featSubType == 'NLDEP':
return self.getNldepFeat(featTuple)
elif featSubType == 'NRDEP':
return self.getNrdepFeat(featTuple)
elif featSubType == 'LLDEP':
return self.getLldepFeat(featTuple)
elif featSubType == 'LRDEP':
return self.getLrdepFeat(featTuple)
elif featSubType == 'SH':
return self.getStackHeightFeat(featTuple)
return 'NULL'
def getNlDepFeat(self, featTuple):
container = featTuple[2]
index = featTuple[3]
word = self.getWordWithRelativeIndex(containe, index)
if word == None :
return 'NULL'
return string(len(word.getLeftDaughters()))
def getNrDepFeat(self, featTuple):
container = featTuple[2]
index = featTuple[3]
word = self.getWordWithRelativeIndex(containe, index)
if word == None :
return 'NULL'
return string(len(word.getRightDaughters()))
def getLlDepFeat(self, featTuple):
return 'NULL'
def getLrDepFeat(self, featTuple):
return 'NULL'
def getStackHeightFeat(self, featTuple):
string(self.getStack().getLength())
def getDistFeat(self, featTuple):
containerWord1 = featTuple[1]
indexWord1 = featTuple[2]
containerWord2 = featTuple[3]
indexWord2 = featTuple[4]
word1 = self.getWordWithRelativeIndex(containerWord1, indexWord1)
word2 = self.getWordWithRelativeIndex(containerWord2, indexWord2)
if word1 == None or word2 == None :
return 'NULL'
return word1.getIndex() - word2.getIndex()
def getWordFeat(self, featTuple):
container = featTuple[1]
index = featTuple[2]
tape = featTuple[3]
word = self.getWordWithRelativeIndex(container, index)
if word == None :
return 'NULL'
return word.getFeat(tape)
def affiche(self):
currentIndex = self.getBuffer().getCurrentIndex()
......@@ -141,7 +194,8 @@ class Config:
i = 0
for f in FeatModel.getFeatArray():
# print(f, '=', self.getWordFeat(f))
featVec.append(self.getWordFeat(f))
featVec.append(self.getFeat(f))
# featVec.append(self.getWordFeat(f))
i += 1
# print(featVec)
return featVec
......@@ -3,7 +3,7 @@ class Word:
self.featDic = {} # dictionnaire dans lequel sont stockés les word features
self.leftDaughters = [] # liste des indices des dépendants gauches
self.rightDaughters = [] # liste des indices des dépendants droits
self.index = invalidIndex()
self.index = self.invalidIndex()
def getFeat(self, featName):
if(not featName in self.featDic):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment