From 870b4913e2e541ceaed4f3c16d0b4cf49a6fd0bc Mon Sep 17 00:00:00 2001 From: ashkankzme Date: Mon, 5 Aug 2024 15:13:30 -0700 Subject: [PATCH] returning empty lists for items with no valid labels --- lib/model/classycat_classify.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/model/classycat_classify.py b/lib/model/classycat_classify.py index 1fc344d..89a1da6 100644 --- a/lib/model/classycat_classify.py +++ b/lib/model/classycat_classify.py @@ -126,8 +126,11 @@ def classify_and_store_results(self, schema_id, items): for i in range(len(items))] # filtering out the results that have out-of-schema labels + # our of schema labels will not be included in the final results, + # and items with no labels can be retried later by the user, indicated by an empty list for labels permitted_labels = [topic['topic'] for topic in schema['topics']] + ['Other', 'Unsure'] - final_results = [result for result in final_results if all(label in permitted_labels for label in result['labels'])] + for result in final_results: + result['labels'] = [label for label in result['labels'] if label in permitted_labels] if len(final_results) == 0: logger.info(f"The returned classifications did not produce labels from the schema: {items}")