Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
old_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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
old_macaon_data
Commits
a3a763db
Commit
a3a763db
authored
5 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Added script to get rules of word splitting for conllu
parent
deab664e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/conll2text.py
+0
-0
0 additions, 0 deletions
tools/conll2text.py
tools/conllu2splits.py
+80
-0
80 additions, 0 deletions
tools/conllu2splits.py
with
80 additions
and
0 deletions
script
s/conll2text.py
→
tool
s/conll2text.py
+
0
−
0
View file @
a3a763db
File moved
This diff is collapsed.
Click to expand it.
tools/conllu2splits.py
0 → 100755
+
80
−
0
View file @
a3a763db
#! /usr/bin/python3
import
sys
rules
=
{}
prefix
=
"
SPLITWORD
"
def
printUsageAndExit
()
:
print
(
"
USAGE : %s file.conllu conllu.mcd
"
%
sys
.
argv
[
0
],
file
=
sys
.
stderr
)
exit
(
1
)
def
readMCD
(
mcdFilename
)
:
mcd
=
{}
for
line
in
open
(
mcdFilename
,
"
r
"
,
encoding
=
"
utf8
"
)
:
clean
=
line
.
strip
()
if
len
(
line
)
<
2
or
line
[
0
]
==
'
#
'
:
continue
splited
=
line
.
split
(
'
'
)
if
len
(
splited
)
!=
2
:
print
(
"
ERROR : invalid mcd line
\'
%s
\'
. Aborting
"
%
line
,
file
=
sys
.
stderr
)
exit
(
1
)
mcd
[
splited
[
0
].
strip
()]
=
splited
[
1
].
strip
()
return
mcd
def
computeRules
(
sentence
)
:
wordById
=
{}
for
word
in
sentence
:
splited
=
word
[
0
].
split
(
"
-
"
)
if
len
(
splited
)
>
1
:
continue
wordById
[
word
[
0
]]
=
word
[
1
]
for
word
in
sentence
:
splited
=
word
[
0
].
split
(
"
-
"
)
if
len
(
splited
)
>
1
:
rule
=
""
for
id
in
splited
:
rule
+=
"
@
"
+
wordById
[
id
]
if
word
[
1
]
in
rules
:
if
rule
in
rules
[
word
[
1
]]
:
rules
[
word
[
1
]][
rule
]
+=
1
else
:
rules
[
word
[
1
]][
rule
]
=
1
else
:
rules
[
word
[
1
]]
=
{}
rules
[
word
[
1
]][
rule
]
=
1
def
main
()
:
if
len
(
sys
.
argv
)
!=
3
:
printUsageAndExit
()
conllMCD
=
readMCD
(
sys
.
argv
[
2
])
conllMCDr
=
{
v
:
k
for
k
,
v
in
conllMCD
.
items
()}
idId
=
int
(
conllMCDr
[
"
ID
"
])
idForm
=
int
(
conllMCDr
[
"
FORM
"
])
sentence
=
[]
for
line
in
open
(
sys
.
argv
[
1
],
"
r
"
)
:
if
len
(
line
.
strip
())
<
2
or
line
[
0
]
==
'
#
'
:
if
len
(
sentence
)
>
0
:
computeRules
(
sentence
)
sentence
=
[]
continue
splited
=
line
.
strip
().
split
(
'
\t
'
)
sentence
+=
[[
splited
[
idId
],
splited
[
idForm
]]]
for
word
in
rules
:
if
len
(
rules
[
word
])
>
1
:
print
(
"
WARNING : Abiguity detected in
\'
%s
\'
"
%
(
word
+
"
"
+
str
(
rules
[
word
])),
file
=
sys
.
stderr
)
for
rule
in
rules
[
word
]
:
print
(
prefix
+
word
+
rule
)
break
if
__name__
==
"
__main__
"
:
main
()
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