From 4a37ce593273fedf69e24a0757eea704ab732291 Mon Sep 17 00:00:00 2001 From: Alexis Nasr <alexis.nasr@lif.univ-mrs.fr> Date: Fri, 16 Oct 2020 08:49:08 +0200 Subject: [PATCH] code refactoring --- expe/basic.fm | 14 +++++++------- src/Config.py | 6 +++--- src/FeatModel.py | 17 ++++++++++------- src/tbp_decode.py | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/expe/basic.fm b/expe/basic.fm index f3dcb6e..d6b579a 100644 --- a/expe/basic.fm +++ b/expe/basic.fm @@ -1,7 +1,7 @@ -B -2 POS -B -1 POS -B 0 POS -B 1 POS -B 2 POS -S 0 POS -S 1 POS +W B -2 POS +W B -1 POS +W B 0 POS +W B 1 POS +W B 2 POS +W S 0 POS +W S 1 POS diff --git a/src/Config.py b/src/Config.py index afee5fc..df30721 100644 --- a/src/Config.py +++ b/src/Config.py @@ -86,9 +86,9 @@ class Config: return False def getWordFeat(self, featTuple): - container = featTuple[0] - index = featTuple[1] - tape = featTuple[2] + container = featTuple[1] + index = featTuple[2] + tape = featTuple[3] if(container == 'B'): diff --git a/src/FeatModel.py b/src/FeatModel.py index cbae8f9..d6af63d 100644 --- a/src/FeatModel.py +++ b/src/FeatModel.py @@ -14,22 +14,22 @@ class FeatModel: exit(1) featArray = [] for ligne in featModFile: - (container, position, wordFeature) = ligne.split() -# print("container = ", container, "position = ", position, "wordFeature = ", wordFeature) + (featType, container, position, wordFeature) = ligne.split() + #print("type =", featType, "container = ", container, "position = ", position, "wordFeature = ", wordFeature) if(container != "B" and container != "S"): print("error while reading featMod file : ", featModFilename, "container :", container, "undefined") exit(1) if not wordFeature in set(['POS', 'LEMMA', 'FORM']): print("error while reading featMod file : ", featModFilename, "wordFeature :", wordFeature, "undefined") exit(1) - featArray.append((container, int(position), wordFeature)) + featArray.append((featType, container, int(position), wordFeature)) featModFile.close() return featArray def computeInputSize(self, dicos): inputVectorSize = 0 for featTuple in self.getFeatArray(): - feat = featTuple[2] + feat = featTuple[3] inputVectorSize += dicos.getDico(feat).getSize() return inputVectorSize @@ -42,15 +42,18 @@ class FeatModel: def getFeatArray(self): return self.featArray - def getFeatContainer(self, featIndex): + def getFeatType(self, featIndex): return self.featArray[featIndex][0] - def getFeatPosition(self, featIndex): + def getFeatContainer(self, featIndex): return self.featArray[featIndex][1] - def getFeatLabel(self, featIndex): + def getFeatPosition(self, featIndex): return self.featArray[featIndex][2] + def getFeatLabel(self, featIndex): + return self.featArray[featIndex][3] + def buildInputVector(self, featVec, dicos): inputVector = np.zeros(self.inputVectorSize, dtype="int32") origin = 0 diff --git a/src/tbp_decode.py b/src/tbp_decode.py index fe4c748..a21e322 100644 --- a/src/tbp_decode.py +++ b/src/tbp_decode.py @@ -43,7 +43,7 @@ sys.stderr.write('\n') mcd = Mcd(mcd_file) sys.stderr.write('loading dicos\n') -dicos = Dicos(fileName=dicos_file, verbose=False) +dicos = Dicos(fileName=dicos_file) moves = Moves(dicos) -- GitLab