Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macaon_data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Franck Dary
macaon_data
Commits
cb3187f5
Commit
cb3187f5
authored
3 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added script mcf2conllu
parent
07738758
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/mcf2conllu.py
+58
-0
58 additions, 0 deletions
scripts/mcf2conllu.py
with
58 additions
and
0 deletions
scripts/mcf2conllu.py
0 → 100755
+
58
−
0
View file @
cb3187f5
#! /usr/bin/env python3
import
argparse
import
sys
################################################################################
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
input
"
,
type
=
str
,
help
=
"
Input mcf file
"
)
parser
.
add_argument
(
"
head
"
,
type
=
int
,
help
=
"
Index of the column containing governor relative index.
"
)
parser
.
add_argument
(
"
eos
"
,
type
=
int
,
help
=
"
Index of the column containing end of sentence info.
"
)
parser
.
add_argument
(
"
--form
"
,
type
=
int
,
default
=
None
,
help
=
"
Index of the column containing FORM.
"
)
parser
.
add_argument
(
"
--upos
"
,
type
=
int
,
default
=
None
,
help
=
"
Index of the column containing UPOS.
"
)
args
=
parser
.
parse_args
()
mcd
=
[]
sentence
=
[]
sentenceID
=
0
for
line
in
open
(
args
.
input
,
"
r
"
)
:
line
=
line
.
strip
()
if
len
(
line
)
==
0
:
continue
if
line
[
0
]
==
'
#
'
:
continue
splited
=
line
.
split
(
'
\t
'
)
if
len
(
mcd
)
==
0
:
mcd
=
[
str
(
k
)
for
k
in
range
(
1
,
len
(
splited
)
+
1
)]
mcd
[
args
.
head
]
=
"
HEAD
"
mcd
[
args
.
eos
]
=
"
ID
"
if
args
.
form
is
not
None
:
mcd
[
args
.
form
]
=
"
FORM
"
if
args
.
upos
is
not
None
:
mcd
[
args
.
upos
]
=
"
UPOS
"
print
(
"
# global.columns = %s
"
%
"
"
.
join
(
mcd
))
splited
[
args
.
head
]
=
int
(
splited
[
args
.
head
])
sentence
.
append
(
splited
)
eos
=
int
(
splited
[
args
.
eos
])
if
eos
==
1
:
sentenceID
+=
1
print
(
"
# sent_id = %d
"
%
sentenceID
)
for
i
in
range
(
len
(
sentence
))
:
sentence
[
i
][
args
.
eos
]
=
i
+
1
# Recycling EOS column into ID column
if
sentence
[
i
][
args
.
head
]
!=
0
:
sentence
[
i
][
args
.
head
]
+=
i
+
1
# Transforming relative head into absolute
for
word
in
sentence
:
print
(
'
\t
'
.
join
(
map
(
str
,
word
)))
print
(
""
)
sentence
=
[]
################################################################################
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