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
9d2a9871
Commit
9d2a9871
authored
3 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
script to check problem also output sentences without any problem
parent
7b65bf7f
No related branches found
Branches containing commit
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
+22
-5
22 additions, 5 deletions
scripts/conlluCheckProblems.py
with
22 additions
and
5 deletions
scripts/conlluCheckProblems.py
+
22
−
5
View file @
9d2a9871
...
...
@@ -24,11 +24,11 @@ def checkMCD(mcd) :
################################################################################
def
logError
(
message
,
sentence
)
:
print
(
message
)
print
(
message
,
file
=
sys
.
stderr
)
for
line
in
sentence
:
for
col
in
line
:
print
(
col
,
end
=
"
\t
"
)
print
(
""
)
print
(
col
,
end
=
"
\t
"
,
file
=
sys
.
stderr
)
print
(
""
,
file
=
sys
.
stderr
)
################################################################################
################################################################################
...
...
@@ -43,17 +43,19 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
multiWordEmptyNodes
=
set
()
id2index
=
{}
hadErr
=
False
# Verifying IDS
for
i
in
range
(
len
(
sentence
))
:
for
col
in
sentence
[
i
]
:
if
len
(
col
)
==
0
:
logError
(
"
Empty column on line %s
"
%
(
fileLineIndex
+
i
),
sentence
)
return
return
False
idStr
=
sentence
[
i
][
idIndex
]
if
idStr
in
id2index
:
logError
(
"
ERROR in IDs : line %s
'
%s
'
already seen
"
%
(
fileLineIndex
+
i
,
idStr
),
sentence
)
hadErr
=
True
id2index
[
idStr
]
=
i
...
...
@@ -63,11 +65,13 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
multiWordEmptyNodes
.
add
(
i
)
if
int
(
splited
[
0
])
!=
curId
+
1
or
int
(
splited
[
0
])
>=
int
(
splited
[
1
])
:
logError
(
"
ERROR in line %s, IDs : %s
"
%
(
fileLineIndex
+
i
,
idStr
),
sentence
)
hadErr
=
True
elif
len
(
idStr
.
split
(
'
.
'
))
==
2
:
multiWordEmptyNodes
.
add
(
i
)
splited
=
idStr
.
split
(
'
.
'
)
if
int
(
splited
[
0
])
!=
curId
or
int
(
splited
[
1
])
!=
curDigit
:
logError
(
"
ERROR in line %s, IDs : %s
"
%
(
fileLineIndex
+
i
,
idStr
),
sentence
)
hadErr
=
True
curDigit
+=
1
elif
idStr
.
isdigit
()
:
curId
+=
1
...
...
@@ -75,8 +79,10 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
maxId
=
max
(
maxId
,
int
(
idStr
))
if
int
(
idStr
)
!=
curId
:
logError
(
"
ERROR in line %s, IDs : %s
"
%
(
fileLineIndex
+
i
,
idStr
),
sentence
)
hadErr
=
True
else
:
logError
(
"
ERROR in line %s, IDs : %s
"
%
(
fileLineIndex
+
i
,
idStr
),
sentence
)
hadErr
=
True
nbRoot
=
0
# Verifying root
...
...
@@ -87,6 +93,7 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
if
nbRoot
!=
1
:
logError
(
"
ERROR %d root in sentence on line %s:
"
%
(
nbRoot
,
fileLineIndex
),
sentence
)
hadErr
=
True
# Verifying govs
for
i
in
range
(
len
(
sentence
))
:
...
...
@@ -95,8 +102,11 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
govStr
=
sentence
[
i
][
govIndex
]
if
not
govStr
.
isdigit
()
:
logError
(
"
ERROR line %d gov
\'
%s
\'
is not positive integer :
"
%
(
fileLineIndex
+
i
,
govStr
),
sentence
)
hadErr
=
True
if
int
(
govStr
)
>
maxId
:
logError
(
"
ERROR line %d gov
\'
%s
\'
is out of sentence :
"
%
(
fileLineIndex
+
i
,
govStr
),
sentence
)
hadErr
=
True
# Verifying cycles
alreadyReported
=
{}
...
...
@@ -114,8 +124,11 @@ def checkSentence(fileLineIndex, sentence, conllMCD, conllMCDr) :
if
currentNode
in
alreadySeen
:
if
currentNode
not
in
alreadyReported
:
logError
(
"
ERROR line %d (id=%s) loop in governors :
"
%
(
fileLineIndex
+
currentNode
,
sentence
[
currentNode
][
idIndex
]),
sentence
)
hadErr
=
True
alreadyReported
[
currentNode
]
=
True
break
return
not
hadErr
################################################################################
...
...
@@ -139,13 +152,17 @@ if __name__ == "__main__" :
if
len
(
clean
)
<
3
:
if
sentFirstLine
==
-
1
:
exit
(
1
)
checkSentence
(
sentFirstLine
,
sentence
,
conllMCDr
,
conllMCD
)
if
checkSentence
(
sentFirstLine
,
sentence
,
conllMCDr
,
conllMCD
)
:
for
line
in
sentence
:
print
(
"
\t
"
.
join
(
line
))
print
(
""
)
sentence
=
[]
sentFirstLine
=
-
1
continue
if
clean
[
0
]
==
'
#
'
:
splited
=
line
.
split
(
"
global.columns =
"
)
if
len
(
splited
)
>
1
:
print
(
line
.
strip
())
conllMCD
,
conllMCDr
=
readMCD
(
splited
[
-
1
].
strip
())
checkMCD
(
conllMCD
)
continue
...
...
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