Refactor find_phrases function to improve code readability and maintainability

This commit is contained in:
2024-06-04 17:02:45 -04:00
parent 4e0ff03557
commit 717d89efd3
2 changed files with 52 additions and 41 deletions
+7 -29
View File
@@ -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)
+45 -12
View File
@@ -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()