Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alexis Nasr
tbp
Commits
25e8bd5c
Commit
25e8bd5c
authored
Oct 14, 2020
by
Alexis Nasr
Browse files
code refactoring
parent
1e8cdf0b
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/Dicos.py
View file @
25e8bd5c
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
:
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'
)
self
.
initializeWithMcd
(
mcd
)
if
fileName
:
try
:
dicoFile
=
open
(
fileName
,
encoding
=
'utf-8'
)
except
IOError
:
print
(
fileName
,
'does not exist'
)
exit
(
1
)
for
ligne
in
dicoFile
:
if
ligne
[
0
]
==
'#'
and
ligne
[
1
]
==
'#'
:
currentDicoName
=
ligne
[
2
:
-
1
]
currentDico
=
self
.
getDico
(
currentDicoName
)
else
:
symbol
=
ligne
[:
-
1
]
currentDico
.
add
(
symbol
)
dicoFile
.
close
()
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'
)
def
initializeWithDicoFile
(
self
,
fileName
):
try
:
dicoFile
=
open
(
fileName
,
encoding
=
'utf-8'
)
except
IOError
:
print
(
fileName
,
'does not exist'
)
exit
(
1
)
for
ligne
in
dicoFile
:
if
ligne
[
0
]
==
'#'
and
ligne
[
1
]
==
'#'
:
currentDicoName
=
ligne
[
2
:
-
1
]
# 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
:
...
...
src/FeatModel.py
View file @
25e8bd5c
...
...
@@ -48,16 +48,16 @@ class FeatModel:
def
getFeatPosition
(
self
,
featIndex
):
return
self
.
featArray
[
featIndex
][
1
]
def
getFeat
WordFeature
(
self
,
featIndex
):
def
getFeat
Label
(
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
.
getFeat
WordFeature
(
i
)
size
=
dicos
.
getDico
(
featureName
).
getSize
()
position
=
dicos
.
getCode
(
featureName
,
featVec
[
i
])
label
=
self
.
getFeat
Label
(
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
...
...
src/Moves.py
View file @
25e8bd5c
import
numpy
as
np
class
Moves
:
nb
=
0
def
__init__
(
self
,
dicos
):
self
.
dicoLabels
=
dicos
.
getDico
(
'LABEL'
)
if
not
self
.
dicoLabels
:
...
...
src/Word.py
View file @
25e8bd5c
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
):
...
...
src/mcf2cff.py
View file @
25e8bd5c
...
...
@@ -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)
...
...
src/tbp_decode.py
View file @
25e8bd5c
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment