Commit 1e8cdf0b authored by Alexis Nasr's avatar Alexis Nasr
Browse files

code refactoring

parent 2a1858d8
......@@ -139,7 +139,7 @@ class Config:
def extractFeatVec(self, FeatModel):
featVec = []
i = 0
for f in FeatModel.getArray():
for f in FeatModel.getFeatArray():
# print(f, '=', self.getWordFeat(f))
featVec.append(self.getWordFeat(f))
i += 1
......
import numpy as np
class FeatModel:
array = []
nbFeat = 0
inputVectorSize = None
def __init__(self, featModFilename, dicos):
self.featArray = self.readFeatModelFile(featModFilename)
self.inputVectorSize = self.computeInputSize(dicos)
def readFeatModelFile(self, featModFilename):
try:
featModFile = open(featModFilename, encoding='utf-8')
except IOError:
print(featModFilename, " : ce fichier n'existe pas")
exit(1)
featArray = []
for ligne in featModFile:
(container, position, wordFeature) = ligne.split()
# print("container = ", container, "position = ", position, "wordFeature = ", wordFeature)
......@@ -19,14 +22,13 @@ class FeatModel:
if not wordFeature in set(['POS', 'LEMMA', 'FORM']):
print("error while reading featMod file : ", featModFilename, "wordFeature :", wordFeature, "undefined")
exit(1)
self.array.append((container, int(position), wordFeature))
self.nbFeat += 1
featArray.append((container, int(position), wordFeature))
featModFile.close()
self.inputVectorSize = self.computeInputSize(dicos)
return featArray
def computeInputSize(self, dicos):
inputVectorSize = 0
for featTuple in self.getArray():
for featTuple in self.getFeatArray():
feat = featTuple[2]
inputVectorSize += dicos.getDico(feat).getSize()
return inputVectorSize
......@@ -35,19 +37,19 @@ class FeatModel:
return self.inputVectorSize
def getNbFeat(self):
return self.nbFeat
return len(self.featArray)
def getArray(self):
return self.array
def getFeatArray(self):
return self.featArray
def getFeatContainer(self, featIndex):
return self.array[featIndex][0]
return self.featArray[featIndex][0]
def getFeatPosition(self, featIndex):
return self.array[featIndex][1]
return self.featArray[featIndex][1]
def getFeatWordFeature(self, featIndex):
return self.array[featIndex][2]
return self.featArray[featIndex][2]
def buildInputVector(self, featVec, dicos):
inputVector = np.zeros(self.inputVectorSize, dtype="int32")
......
class Mcd:
array = []
nbCol = 0
def __init__(self, mcdFilename):
self.array = self.readMcdFile(mcdFilename)
def readMcdFile(self, mcdFilename):
try:
mcdFile = open(mcdFilename, encoding='utf-8')
except IOError:
print(mcdFilename, " : ce fichier n'existe pas")
exit(1)
colDescriptionArray = []
for ligne in mcdFile:
(col, name, type, status) = ligne.split()
#print("col = ", col, "name = ", name, "type = ", type, "status =", status)
......@@ -16,12 +18,12 @@ class Mcd:
if(type != "INT" and type != "SYM"):
print("error while reading mcd file : ", mcdFilename, "type :", type, "undefined")
exit(1)
self.array.append((int(col), name, type, status))
colDescriptionArray.append((int(col), name, type, status))
mcdFile.close()
self.nbCol = int(col) + 1
return colDescriptionArray
def getNbCol(self):
return self.nbCol
return len(self.array)
def getArray(self):
return self.array
......@@ -36,7 +38,7 @@ class Mcd:
return self.array[colIndex][3]
def locateCol(self, name):
for colIndex in range(self.nbCol):
for colIndex in range(self.getNbCol()):
if self.array[colIndex][1] == name:
return colIndex
return None
......
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