Skip to content
Snippets Groups Projects
Commit 442d956c authored by Franck Dary's avatar Franck Dary
Browse files

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
#! /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, conllMCDr)
checkSentence(sentFirstLine, sentence, conllMCDr, 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'))
################################################################################
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment