Skip to content

Commit

Permalink
Merge pull request #366 from ghostsquad/feat/text-search
Browse files Browse the repository at this point in the history
feat: add text search node
  • Loading branch information
WAS-PlaiLabs committed May 15, 2024
2 parents 4d19605 + 2154c6e commit f1f21b7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
- Text Dictionary Keys: Returns the keys, as a list from a dictionary object
- Text Dictionary To Text: Returns the dictionary as text
- Text File History: Show previously opened text files *(requires restart to show last sessions files at this time)*
- Text Find: Find a substring or pattern within another string. Returns boolean
- Text Find and Replace: Find and replace a substring in a string
- Text Find and Replace by Dictionary: Replace substrings in a ASCII text input with a dictionary.
- The dictionary keys are used as the key to replace, and the list of lines it contains chosen at random based on the seed.
Expand Down
35 changes: 34 additions & 1 deletion WAS_Node_Suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4732,7 +4732,7 @@ def image_batch(self, **kwargs):
self._check_image_dimensions(batched_tensors, image_names)
batched_tensors = torch.cat(batched_tensors, dim=0)
return (batched_tensors,)


# Latent TO BATCH

Expand Down Expand Up @@ -10133,6 +10133,38 @@ def text_concatenate(self, delimiter, clean_whitespace, **kwargs):
return (merged_text,)


# Text Find


# Note that these nodes are exposed as "Find", not "Search". This is the first class that follows the naming convention of the node itself.
class WAS_Find:
def __init__(self):
pass

@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"text": (TEXT_TYPE, {"forceInput": (True if TEXT_TYPE == 'STRING' else False)}),
"substring": ("STRING", {"default": '', "multiline": False}),
"pattern": ("STRING", {"default": '', "multiline": False}),
}
}

RETURN_TYPES = ("BOOLEAN")
RETURN_NAMES = ("found")
FUNCTION = "execute"

CATEGORY = "WAS Suite/Text/Search"

def execute(self, text, substring, pattern):
if substring:
return substring in text

return bool(re.search(pattern, text))



# Text Search and Replace

class WAS_Search_and_Replace:
Expand Down Expand Up @@ -13932,6 +13964,7 @@ def count_places(self, int_input):
"Text Find and Replace by Dictionary": WAS_Search_and_Replace_Dictionary,
"Text Find and Replace Input": WAS_Search_and_Replace_Input,
"Text Find and Replace": WAS_Search_and_Replace,
"Text Find": WAS_Find,
"Text Input Switch": WAS_Text_Input_Switch,
"Text List": WAS_Text_List,
"Text List Concatenate": WAS_Text_List_Concatenate,
Expand Down

0 comments on commit f1f21b7

Please sign in to comment.