diff --git a/data-computer/v1/lda.py b/data-computer/v1/lda.py index 426a137..478d62e 100755 --- a/data-computer/v1/lda.py +++ b/data-computer/v1/lda.py @@ -51,7 +51,7 @@ best_topic = {} best_proba = 0 for topic in dico: - proba = float(dico[topic]["weight"]) + proba = float(dico[topic]["topic_weight"]) if proba>best_proba: best_proba = proba best_topic = topic @@ -119,9 +119,14 @@ topic_info = {} for topic_id, topic_weight in topics: topic_info[f"topic_{topic_id + 1}"] = {} - topic_words = [{"word":word, "word_weight":str(word_weight)} for word, word_weight in lda_model.show_topic(topic_id)] - topic_info[f"topic_{topic_id + 1}"]["words"] = topic_words - topic_info[f"topic_{topic_id + 1}"]["weight"] = str(topic_weight) + words = [] + words_weights = [] + for word, word_weight in lda_model.show_topic(topic_id): + words.append(word) + words_weights.append(words_weights) + topic_info[f"topic_{topic_id + 1}"]["words"] = words + topic_info[f"topic_{topic_id + 1}"]["words_weights"] = words_weights + topic_info[f"topic_{topic_id + 1}"]["topic_weight"] = str(topic_weight) line["value"]={} line["value"]["topics"]=topic_info