Skip to content
Snippets Groups Projects
Commit 717f2f25 authored by Franck Dary's avatar Franck Dary
Browse files
parents 5b6f9194 cd9d2a56
No related branches found
No related tags found
No related merge requests found
#! /usr/bin/env python3
import sys
import os
################################################################################
def printUsageAndExit() :
print("USAGE : %s bin/ predOutputDir/ goldOutputDir/"%sys.argv[0], file=sys.stderr)
exit(1)
################################################################################
def getModelModelIndexFilename(d, f) :
model = ".".join(d[0].split('.')[:-1]).split('/')[-1]
modelIndex = int(model.split('_')[-1])
model = "_".join(model.split('_')[:-1])
filename = d[0]+"/"+f
return model, modelIndex, filename
################################################################################
if __name__ == "__main__" :
if len(sys.argv) != 4 :
printUsageAndExit()
binDir = sys.argv[1]
outputDir = sys.argv[2]
goldOutputDir = sys.argv[3]
filesByModel = {}
for d in os.walk(binDir) :
for f in d[2] :
if "predicted_eval" in f :
model, index, filename = getModelModelIndexFilename(d, f)
if model not in filesByModel :
filesByModel[model] = []
while len(filesByModel[model]) <= index :
filesByModel[model].append(["",""])
filesByModel[model][index][0] = filename
if "test.conllu" in f :
model, index, filename = getModelModelIndexFilename(d, f)
if model not in filesByModel :
filesByModel[model] = []
while len(filesByModel[model]) <= index :
filesByModel[model].append(["",""])
filesByModel[model][index][1] = filename
with open(goldOutputDir+"/corpus.conllu", "w") as out :
for f in filesByModel[list(filesByModel.keys())[0]] :
for line in open(f[1], "r") :
print(line, end="", file=out)
for model in filesByModel :
outDir = outputDir+"/"+model
os.makedirs(outDir, exist_ok=True)
with open(outDir+"/corpus.conllu", "w") as out :
for f in filesByModel[model] :
for line in open(f[0], "r") :
print(line, end="", file=out)
################################################################################
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