Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -85,39 +85,92 @@ class Config: ...@@ -85,39 +85,92 @@ class Config:
return self.red() return self.red()
return False return False
def getWordFeat(self, featTuple): def getWordWithRelativeIndex(self, container, index):
container = featTuple[1] if container == 'S' :
index = featTuple[2] if index >= self.getStack().getLength() :
tape = featTuple[3] return None
indexInBuffer = self.getStack().array[self.getStack().getLength() - index - 1]
return self.getBuffer().getWord(indexInBuffer)
if(container == 'B'): elif container == 'B' :
# if((index < self.getBuffer().getLength()) and (index >= 0)):
absoluteIndex = self.getBuffer().getCurrentIndex() + index absoluteIndex = self.getBuffer().getCurrentIndex() + index
if absoluteIndex < self.getBuffer().getLength() and absoluteIndex >= 0 : if absoluteIndex < self.getBuffer().getLength() and absoluteIndex >= 0 :
w = self.getBuffer().getWord(absoluteIndex) return self.getBuffer().getWord(absoluteIndex)
else : else :
#print('word feature ', container, '.', index, '.', tape, ' cannot be interpreted, index ', index, "is out of bound") return None
return None
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' return 'NULL'
else: def getNlDepFeat(self, featTuple):
if(index < self.getStack().getLength()): container = featTuple[2]
#print('on cherche dans', self.getStack().getLength() - index - 1, "") index = featTuple[3]
w = self.getBuffer().getWord(self.getStack().array[self.getStack().getLength() - index - 1])
if w == None : word = self.getWordWithRelativeIndex(containe, index)
if word == None :
return 'NULL' return 'NULL'
else: return string(len(word.getLeftDaughters()))
#print('word feature ', container, '.', index, '.', tape, ' cannot be interpreted, index ', index, "is out of bound")
def getNrDepFeat(self, featTuple):
container = featTuple[2]
index = featTuple[3]
word = self.getWordWithRelativeIndex(containe, index)
if word == None :
return 'NULL' return 'NULL'
return string(len(word.getRightDaughters()))
return w.getFeat(tape)
# print('word feature ', container, '.', index, '.', tape, ' cannot be interpreted, tape ', tape, "is unknown") def getLlDepFeat(self, featTuple):
return 'NULL'
def getLrDepFeat(self, featTuple):
return 'NULL'
# 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): def affiche(self):
currentIndex = self.getBuffer().getCurrentIndex() currentIndex = self.getBuffer().getCurrentIndex()
...@@ -141,7 +194,8 @@ class Config: ...@@ -141,7 +194,8 @@ class Config:
i = 0 i = 0
for f in FeatModel.getFeatArray(): for f in FeatModel.getFeatArray():
# print(f, '=', self.getWordFeat(f)) # print(f, '=', self.getWordFeat(f))
featVec.append(self.getWordFeat(f)) featVec.append(self.getFeat(f))
# featVec.append(self.getWordFeat(f))
i += 1 i += 1
# print(featVec) # print(featVec)
return featVec return featVec
...@@ -3,7 +3,7 @@ class Word: ...@@ -3,7 +3,7 @@ class Word:
self.featDic = {} # dictionnaire dans lequel sont stockés les word features self.featDic = {} # dictionnaire dans lequel sont stockés les word features
self.leftDaughters = [] # liste des indices des dépendants gauches self.leftDaughters = [] # liste des indices des dépendants gauches
self.rightDaughters = [] # liste des indices des dépendants droits self.rightDaughters = [] # liste des indices des dépendants droits
self.index = invalidIndex() self.index = self.invalidIndex()
def getFeat(self, featName): def getFeat(self, featName):
if(not featName in self.featDic): if(not featName in self.featDic):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment