Skip to content
Snippets Groups Projects
Commit 25e8bd5c authored by Alexis Nasr's avatar Alexis Nasr
Browse files

code refactoring

parent 1e8cdf0b
No related branches found
No related tags found
No related merge requests found
from Dico import Dico
class Dicos:
def __init__(self, mcd=False, fileName=False, verbose=False):
def __init__(self, mcd=False, fileName=False):
self.content = {}
if mcd :
self.initializeWithMcd(mcd)
if fileName :
self.initializeWithDicoFile(fileName)
def initializeWithMcd(self, mcd):
for index in range(mcd.getNbCol()):
if(mcd.getColStatus(index) == 'KEEP') and (mcd.getColType(index) == 'SYM') :
dico = self.addDico(mcd.getColName(index))
dico.add('NULL')
dico.add('ROOT')
if fileName :
def initializeWithDicoFile(self, fileName):
try:
dicoFile = open(fileName, encoding='utf-8')
except IOError:
......@@ -18,12 +24,14 @@ class Dicos:
for ligne in dicoFile:
if ligne[0] == '#' and ligne[1] == '#' :
currentDicoName = ligne[2:-1]
currentDico = self.getDico(currentDicoName)
# currentDico = self.getDico(currentDicoName)
currentDico = self.addDico(currentDicoName)
else:
symbol = ligne[:-1]
currentDico.add(symbol)
dicoFile.close()
def populateFromMcfFile(self, mcfFilename, mcd, verbose=False):
try:
mcfFile = open(mcfFilename, encoding='utf-8')
......
......@@ -48,16 +48,16 @@ class FeatModel:
def getFeatPosition(self, featIndex):
return self.featArray[featIndex][1]
def getFeatWordFeature(self, featIndex):
def getFeatLabel(self, featIndex):
return self.featArray[featIndex][2]
def buildInputVector(self, featVec, dicos):
inputVector = np.zeros(self.inputVectorSize, dtype="int32")
origin = 0
for i in range(self.getNbFeat()):
featureName = self.getFeatWordFeature(i)
size = dicos.getDico(featureName).getSize()
position = dicos.getCode(featureName, featVec[i])
label = self.getFeatLabel(i)
size = dicos.getDico(label).getSize()
position = dicos.getCode(label, featVec[i])
#print('featureName = ', featureName, 'value =', featVec[i], 'size =', size, 'position =', position, 'origin =', origin)
inputVector[origin + position] = 1
origin += size
......
import numpy as np
class Moves:
nb = 0
def __init__(self, dicos):
self.dicoLabels = dicos.getDico('LABEL')
if not self.dicoLabels :
......
class Word:
def __init__(self):
self.featDic = {}
self.leftDaughters = []
self.rightDaughters = []
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
def getFeat(self, featName):
if(not featName in self.featDic):
......
......@@ -80,7 +80,7 @@ print('reading mcd from file :', mcdFileName)
mcd = Mcd(mcdFileName)
print('reading dicos from file :', dicosFileName)
dicos = Dicos(mcd = mcd, fileName = dicosFileName, verbose=False)
dicos = Dicos(fileName = dicosFileName)
#dicos.populateFromMcfFile(mcfFileName, mcd, verbose=False)
#print('saving dicos in file :', dicosFileName)
......
......@@ -43,7 +43,7 @@ sys.stderr.write('\n')
mcd = Mcd(mcd_file)
sys.stderr.write('loading dicos\n')
dicos = Dicos(mcd = mcd, fileName=dicos_file, verbose=False)
dicos = Dicos(fileName=dicos_file, verbose=False)
moves = Moves(dicos)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment