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
1e8cdf0b
Commit
1e8cdf0b
authored
Oct 13, 2020
by
Alexis Nasr
Browse files
code refactoring
parent
2a1858d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/Config.py
View file @
1e8cdf0b
...
...
@@ -139,7 +139,7 @@ class Config:
def
extractFeatVec
(
self
,
FeatModel
):
featVec
=
[]
i
=
0
for
f
in
FeatModel
.
getArray
():
for
f
in
FeatModel
.
get
Feat
Array
():
# print(f, '=', self.getWordFeat(f))
featVec
.
append
(
self
.
getWordFeat
(
f
))
i
+=
1
...
...
src/FeatModel.py
View file @
1e8cdf0b
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
.
get
Feat
Array
():
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
.
a
rray
def
get
Feat
Array
(
self
):
return
self
.
featA
rray
def
getFeatContainer
(
self
,
featIndex
):
return
self
.
a
rray
[
featIndex
][
0
]
return
self
.
featA
rray
[
featIndex
][
0
]
def
getFeatPosition
(
self
,
featIndex
):
return
self
.
a
rray
[
featIndex
][
1
]
return
self
.
featA
rray
[
featIndex
][
1
]
def
getFeatWordFeature
(
self
,
featIndex
):
return
self
.
a
rray
[
featIndex
][
2
]
return
self
.
featA
rray
[
featIndex
][
2
]
def
buildInputVector
(
self
,
featVec
,
dicos
):
inputVector
=
np
.
zeros
(
self
.
inputVectorSize
,
dtype
=
"int32"
)
...
...
src/Mcd.py
View file @
1e8cdf0b
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
.
a
rray
.
append
((
int
(
col
),
name
,
type
,
status
))
colDescriptionA
rray
.
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
.
n
bCol
):
for
colIndex
in
range
(
self
.
getN
bCol
()
):
if
self
.
array
[
colIndex
][
1
]
==
name
:
return
colIndex
return
None
...
...
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