Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PSTAL étudiant.e.s
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carlos Ramisch
PSTAL étudiant.e.s
Commits
53054e6c
Commit
53054e6c
authored
9 months ago
by
Carlos Ramisch
Browse files
Options
Downloads
Patches
Plain Diff
Improve conllulib documentation, add extra_cols_dict to vocab converter
parent
e690b1c8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/conllulib.py
+22
-5
22 additions, 5 deletions
lib/conllulib.py
with
22 additions
and
5 deletions
lib/conllulib.py
+
22
−
5
View file @
53054e6c
...
...
@@ -154,6 +154,12 @@ class CoNLLUReader(object):
###############################
def
morph_feats
(
self
):
"""
Extract the list of morphological features from the
"
FEATS
"
field of the
CoNLL-U file. At the end, rewinds the file so that it can be read through
again. The result is a list of unique strings corresponding to the keys
appearing in the FEATS column of the corpus (before the = sign)
"""
morph_feats_list
=
set
([])
for
sent
in
conllu
.
parse_incr
(
self
.
infile
):
for
tok
in
sent
:
...
...
@@ -165,7 +171,7 @@ class CoNLLUReader(object):
###############################
def
to_int_and_vocab
(
self
,
col_name_dict
):
def
to_int_and_vocab
(
self
,
col_name_dict
,
extra_cols_dict
=
{}
):
int_list
=
{};
vocab
=
{}
for
col_name
,
special_tokens
in
col_name_dict
.
items
():
...
...
@@ -174,10 +180,14 @@ class CoNLLUReader(object):
for
special_token
in
special_tokens
:
# Simple access to undefined dict key creates new ID (dict length)
vocab
[
col_name
][
special_token
]
for
col_name
in
extra_cols_dict
.
keys
()
:
int_list
[
col_name
]
=
[]
for
s
in
self
.
readConllu
():
# IMPORTANT : only works if "col_name" is the same as in lambda function definition!
for
col_name
in
col_name_dict
.
keys
():
int_list
[
col_name
].
append
([
vocab
[
col_name
][
tok
[
col_name
]]
for
tok
in
s
])
for
col_name
,
col_fct
in
extra_cols_dict
.
items
():
int_list
[
col_name
].
append
(
list
(
map
(
col_fct
,
[
tok
[
col_name
]
for
tok
in
s
])))
# vocabs cannot be saved if they have lambda function: erase default_factory
for
col_name
in
col_name_dict
.
keys
():
vocab
[
col_name
].
default_factory
=
None
...
...
@@ -185,16 +195,20 @@ class CoNLLUReader(object):
###############################
def
to_int_from_vocab
(
self
,
col_names
,
unk_token
,
vocab
=
{}):
def
to_int_from_vocab
(
self
,
col_names
,
unk_token
,
vocab
=
{}
,
extra_cols_dict
=
{}
):
int_list
=
{}
unk_toks
=
{}
for
col_name
in
col_names
:
int_list
[
col_name
]
=
[]
unk_toks
[
col_name
]
=
vocab
[
col_name
].
get
(
unk_token
,
None
)
for
col_name
in
extra_cols_dict
.
keys
()
:
int_list
[
col_name
]
=
[]
for
s
in
self
.
readConllu
():
for
col_name
in
col_names
:
id_getter
=
lambda
v
,
t
:
v
[
col_name
].
get
(
t
[
col_name
],
unk_toks
[
col_name
])
int_list
[
col_name
].
append
([
id_getter
(
vocab
,
tok
)
for
tok
in
s
])
for
col_name
,
col_fct
in
extra_cols_dict
.
items
():
int_list
[
col_name
].
append
(
list
(
map
(
col_fct
,
[
tok
[
col_name
]
for
tok
in
s
])))
return
int_list
###############################
...
...
@@ -214,6 +228,9 @@ class CoNLLUReader(object):
@staticmethod
def
to_bio
(
sent
,
bio_style
=
'
bio
'
,
name_tag
=
'
parseme:ne
'
):
"""
TODO
"""
bio_enc
=
[]
neindex
=
0
for
tok
in
sent
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment