def index(path, index_file):
"""Classify each text file in a directory and write
the results to the index_file.
"""
result = {}
for filename in os.listdir(path):
file_path = os.path.join(path, filename)
if not os.path.isfile(file_path):
continue
try:
with io.open(file_path, "r") as f:
text = f.read()
categories = classify(text, verbose=False)
result[filename] = categories
except Exception:
print("Failed to process {}".format(file_path))
with io.open(index_file, "w", encoding="utf-8") as f:
f.write(json.dumps(result, ensure_ascii=False))
print("Texts indexed in file: {}".format(index_file))
return result
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Difficile da capire"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Informazioni o codice di esempio errati"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Mancano le informazioni o gli esempi di cui ho bisogno"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Problema di traduzione"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Altra"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Facile da capire"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Il problema è stato risolto"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Altra"
}]