From f6da7f2e79a9cc37d28792f1f9ba1e1798ed528c Mon Sep 17 00:00:00 2001 From: daxcay Date: Fri, 18 Oct 2024 22:09:06 +0530 Subject: [PATCH] Update DataSet_ConceptManager.py --- classes/DataSet_ConceptManager.py | 53 +++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/classes/DataSet_ConceptManager.py b/classes/DataSet_ConceptManager.py index 8ae14d3..395601d 100644 --- a/classes/DataSet_ConceptManager.py +++ b/classes/DataSet_ConceptManager.py @@ -1,11 +1,22 @@ +import random + + def append_text(tags, combined_texts): tags_list = [tag.strip() for tag in tags.split(',')] - text_pos_list = [text_pos.strip().split() for text_pos in combined_texts.split(',')] + text_pos_list = [text_pos.strip().split() + for text_pos in combined_texts.split(',')] for text_pos in text_pos_list: num_pos = len(text_pos) - 1 text = " ".join(text_pos[0:num_pos]) - pos = int(text_pos[num_pos]) + + pos_str = text_pos[num_pos] + + if pos_str == "#": + pos = random.randint(0, len(tags_list)) + else: + pos = int(pos_str) + if pos == 0: tags_list.insert(0, text) else: @@ -14,9 +25,27 @@ def append_text(tags, combined_texts): new_tags = ', '.join(tags_list) return new_tags + +def getWords(combined_texts): + + text_pos_list = [text_pos.strip().split() + for text_pos in combined_texts.split(',')] + + words = [] + + for text_pos in text_pos_list: + num_pos = len(text_pos) - 1 + text = " ".join(text_pos[0:num_pos]) + words.append(text) + + joined_words = ', '.join(words) + return joined_words + + def remove_text(tags, combined_texts): tags_list = [tag.strip() for tag in tags.split(',')] - text_pos_list = [text_pos.strip().split() for text_pos in combined_texts.split(',')] + text_pos_list = [text_pos.strip().split() + for text_pos in combined_texts.split(',')] for text_pos in text_pos_list: num_pos = len(text_pos) - 1 @@ -27,6 +56,7 @@ def remove_text(tags, combined_texts): new_tags = ', '.join(tags_list) return new_tags + class DataSet_ConceptManager: def __init__(self): @@ -37,32 +67,37 @@ class DataSet_ConceptManager: return { "required": { "TextFileContents": ("STRING", {"forceInput": True}), - "Mode": (['add','remove'],), + "Mode": (['add', 'remove'],), "Concepts": ("STRING", {"multiline": True, "default": "concept"}), }, } INPUT_IS_LIST = True - RETURN_TYPES = ("STRING",) - RETURN_NAMES = ("TextFileContents",) - OUTPUT_IS_LIST = (True,) + RETURN_TYPES = ("STRING", "STRING",) + RETURN_NAMES = ("TextFileContents", "Words",) + OUTPUT_IS_LIST = (True, False) FUNCTION = "SaveIT" OUTPUT_NODE = True CATEGORY = "🔶DATASET🔶" def SaveIT(self, TextFileContents, Mode, Concepts): try: - edited = [] + edited = [] + words = [] + for content in TextFileContents: if Mode[0] == "add": edited.append(append_text(content, Concepts[0])) elif Mode[0] == "remove": edited.append(remove_text(content, Concepts[0])) + words = getWords(Concepts[0]) + except Exception as e: print(f"Error saving: {e}") - return (edited,) + return (edited, words, ) + N_CLASS_MAPPINGS = { "DataSet_ConceptManager": DataSet_ConceptManager,