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
442d956c
Commit
442d956c
authored
4 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Script to check problems in conllu files now reads mcd directly from said file
parent
0b8abdb3
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/conlluCheckProblems.py
+30
-21
30 additions, 21 deletions
scripts/conlluCheckProblems.py
with
30 additions
and
21 deletions
scripts/conlluCheckProblems.py
+
30
−
21
View file @
442d956c
#! /usr/bin/env python3
import
sys
from
readMCD
import
readMCD
headColName
=
"
HEAD
"
deprelColName
=
"
DEPREL
"
idColName
=
"
ID
"
################################################################################
def
printUsageAndExit
()
:
print
(
"
USAGE : %s file.conllu
mcd
"
%
sys
.
argv
[
0
],
file
=
sys
.
stderr
)
print
(
"
USAGE : %s file.conllu
"
%
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
)
!=
1
:
print
(
"
ERROR : invalid mcd line
\'
%s
\'
. Aborting
"
%
line
,
file
=
sys
.
stderr
)
################################################################################
def
checkMCD
(
mcd
)
:
for
col
in
[
headColName
,
deprelColName
,
idColName
]
:
if
col
not
in
mcd
:
print
(
"
ERROR : column
'
{}
'
missing from mcd
'
{}
'"
.
format
(
col
,
"
"
.
join
(
mcd
.
keys
())),
file
=
sys
.
stderr
)
exit
(
1
)
mcd
[
len
(
mcd
)]
=
splited
[
0
].
strip
()
return
mcd
################################################################################
################################################################################
def
logError
(
message
,
sentence
)
:
print
(
message
)
for
line
in
sentence
:
for
col
in
line
:
print
(
col
,
end
=
"
\t
"
)
print
(
""
)
################################################################################
################################################################################
def
checkSentence
(
fileLineIndex
,
sentence
,
conllMCD
,
conllMCDr
)
:
idIndex
=
int
(
conllMCDr
[
idColName
])
govIndex
=
int
(
conllMCDr
[
headColName
])
...
...
@@ -120,11 +121,12 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
################################################################################
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
!=
3
:
if
len
(
sys
.
argv
)
!=
2
:
printUsageAndExit
()
conllMCD
=
readMCD
(
sys
.
argv
[
2
])
conllMCDr
=
{
v
:
k
for
k
,
v
in
conllMCD
.
items
()}
baseMCD
=
"
ID FORM LEMMA POS XPOS FEATS HEAD DEPREL
"
conllMCD
,
conllMCDr
=
readMCD
(
baseMCD
)
checkMCD
(
conllMCD
)
sentence
=
[]
fileLineIndex
=
0
...
...
@@ -137,11 +139,18 @@ if __name__ == "__main__" :
if
len
(
clean
)
<
3
:
if
sentFirstLine
==
-
1
:
exit
(
1
)
checkSentence
(
sentFirstLine
,
sentence
,
conllMCD
,
conllMCD
r
)
checkSentence
(
sentFirstLine
,
sentence
,
conllMCD
r
,
conllMCD
)
sentence
=
[]
sentFirstLine
=
-
1
elif
clean
[
0
]
!=
'
#
'
:
if
sentFirstLine
==
-
1
:
sentFirstLine
=
fileLineIndex
sentence
.
append
(
clean
.
split
(
'
\t
'
))
continue
if
clean
[
0
]
==
'
#
'
:
splited
=
line
.
split
(
"
global.columns =
"
)
if
len
(
splited
)
>
1
:
conllMCD
,
conllMCDr
=
readMCD
(
splited
[
-
1
].
strip
())
checkMCD
(
conllMCD
)
continue
if
sentFirstLine
==
-
1
:
sentFirstLine
=
fileLineIndex
sentence
.
append
(
clean
.
split
(
'
\t
'
))
################################################################################
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