diff --git a/scripts/confusionMatrices.py b/scripts/confusionMatrices.py index a850740e3821ceeb21b1cb3e5bcd0610946bbd6a..2e07dd237f04f87c27072e6b80bfe1a67bc9ed01 100644 --- a/scripts/confusionMatrices.py +++ b/scripts/confusionMatrices.py @@ -1,21 +1,11 @@ #!/usr/bin/env python3 from EDdA import data +from EDdA.store import preparePath from EDdA.classification import confusionMatrix, metrics, toPNG, topNGrams import os import sys -def preparePath(root, source, n, ranks, metricName): - path = "{root}/confusionMatrix/{inputHash}/{n}grams_top{ranks}_{name}.png".format( - root=root, - inputHash=source.hash, - n=n, - ranks=ranks, - name=metricName - ) - os.makedirs(os.path.dirname(path), exist_ok=True) - return path - def __syntax(this): print( "Syntax: {this} {required} {optional}".format( @@ -27,13 +17,14 @@ def __syntax(this): ) sys.exit(1) -def __compute(sourcePath, ns, ranksToTry, metricNames, outputDir): +def __compute(sourcePath, ns, ranksToTry, metricNames, root): source = data.load(sourcePath) + path = f"{root}/confusionMatrix/{source.hash}" for n in ns: for ranks in ranksToTry: vectorizer = topNGrams(source, n, ranks) for name in metricNames: - imagePath = preparePath(outputDir, source, n, ranks, name) + imagePath = preparePath(f"{path}/{n}grams_top{ranks}_{name}.png") toPNG(confusionMatrix(vectorizer, metrics[name]), imagePath) if __name__ == '__main__':