From 717d89efd3b03c99528eaace26e8dc3586450a5d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 4 Jun 2024 17:02:45 -0400 Subject: [PATCH] Refactor find_phrases function to improve code readability and maintainability --- system_777/numbers.py | 36 ++++++--------------------- test.py | 57 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/system_777/numbers.py b/system_777/numbers.py index 061480c..0bda7bb 100644 --- a/system_777/numbers.py +++ b/system_777/numbers.py @@ -179,16 +179,6 @@ def find_words( return sorted(list(set(matching_words))) -def find_phrases( - target_value: int, *, system: str | GematriaSystem = GematriaSystem.HEBREW -): - for phrase in EXTRACTED_PHRASES: - n = calculate_gematria(phrase, system=system) - - if n == target_value: - yield (phrase) - - # Sample dictionary of words and phrases WORDS = [ "Hello", @@ -283,23 +273,11 @@ EXTRACTED_PHRASES = extract_phrases_from_corpus(gutenberg, N_GRAMS) EXTRACTED_PHRASES = set(EXTRACTED_PHRASES) -# Example usage -# target_gematria_value = 777 -# matching_words = find_words(target_gematria_value, system=GematriaSystem.English) -# matching_phrases = find_phrases(target_gematria_value, system=GematriaSystem.English) +def find_phrases( + target_value: int, *, system: str | GematriaSystem = GematriaSystem.HEBREW +): + for phrase in EXTRACTED_PHRASES: + n = calculate_gematria(phrase, system=system) -# print(f"Words with Gematria value {target_gematria_value}: {matching_words}") -# print(f"Phrases with Gematria value {target_gematria_value}: {matching_phrases}") -# print( -# f"Extracted phrases with Gematria value {target_gematria_value}: {find_phrases(target_gematria_value, system=GematriaSystem.English)}" -# ) - -if __name__ == "__main__": - target_gematria_value = 777 - matching_words = find_words(target_gematria_value, system=GematriaSystem.English) - # matching_phrases = set( - # find_phrases(target_gematria_value, system=GematriaSystem.English) - # ) - - # print(f"Words with Gematria value {target_gematria_value}: {matching_words}") - # print(f"Phrases with Gematria value {target_gematria_value}: {matching_phrases}") + if n == target_value: + yield (phrase) diff --git a/test.py b/test.py index 77e3a5c..606bbeb 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,3 @@ -import system_777 from system_777.numbers import ( calculate_gematria, find_words, @@ -7,16 +6,50 @@ from system_777.numbers import ( ) -NAME = "I AM THAT I AM" -SYSTEM = GematriaSystem.HEBREW -# GEMATRIA_VALUE = calculate_gematria(NAME, system=SYSTEM) +class MetaphysicalShowcase: + def __init__(self): + self.target_value = 777 + self.system = GematriaSystem.ENGLISH -# print(f"The gematria value of the name '{NAME}' is {GEMATRIA_VALUE}.") -# print() -# print("Possible phrases with the gematria value of the name:") -found_phrases = [] -for phrase in find_words(calculate_gematria(NAME, system=SYSTEM)): - if phrase not in found_phrases: - found_phrases.append(phrase) + def demonstrate_gematria_calculation(self, name: str): + value = calculate_gematria(name, self.system) + print( + f"The Gematria value of '{name}' in {self.system.value} system is: {value}" + ) - print(phrase) + def demonstrate_matching_words(self): + words = find_words(self.target_value, system=self.system) + print( + f"Words with Gematria value {self.target_value} in {self.system.value} system: {words}" + ) + + def demonstrate_matching_phrases(self): + phrases = list(find_phrases(self.target_value, system=self.system)) + print( + f"Phrases with Gematria value {self.target_value} in {self.system.value} system: {phrases}" + ) + + def set_target_value(self, value: int): + self.target_value = value + print(f"Target value set to: {self.target_value}") + + def set_system(self, system: GematriaSystem): + self.system = system + print(f"Gematria system set to: {self.system.value}") + + +if __name__ == "__main__": + showcase = MetaphysicalShowcase() + + # Demonstrate changing target value and system + showcase.set_target_value(636) + showcase.set_system(GematriaSystem.ENGLISH) + + # Demonstrate Gematria calculation for a specific name + showcase.demonstrate_gematria_calculation("Metatron") + + # Demonstrate finding matching words + showcase.demonstrate_matching_words() + + # Demonstrate finding matching phrases + showcase.demonstrate_matching_phrases()