# This code is dedicated to the public domain under the Creative Commons Zero (CC0) license. # To the extent possible under law, the author(s) have waived all of their rights to the code # and it is now in the public domain. You can freely use, modify, and distribute this code. # More information: https://creativecommons.org/publicdomain/zero/1.0/ from hebrew import Hebrew from hebrew import GematriaTypes # Define gematria methods gematria_methods = [ "mispar_hechrachi", "mispar_gadol", "mispar_siduri", "mispar_katan", "mispar_perati", "atbash", "albam", "mispar_meshulash", "mispar_kidmi", "mispar_mispari", "ayak_bachar", "ofan", "achas_beta", "avgad", "reverse_avgad", "mispar_musafi", "mispar_boneeh", "mispar_hamerubah_haklali", "mispar_haachor", "mispar_katan_mispari", "mispar_kolel", "mispar_shemi_milui", "mispar_neelam" ] # Function to read Torah chapter from file def read_torah(file_path): with open(file_path, 'r', encoding='utf-8') as f: return f.read() # Function to calculate gematria based on method def calculate_gematria(torah_text, method): hs = Hebrew(torah_text) # Handle different gematria methods if method == "mispar_hechrachi": return hs.gematria(GematriaTypes.MISPAR_HECHRACHI) elif method == "mispar_gadol": return hs.gematria(GematriaTypes.MISPAR_GADOL) # Add similar conditions for all other methods # Return raw letter gematria if no specific method matches return hs.gematria() # Function to save gematria values (letters or words) # Function to save gematria values (letters or words) def save_gematria(torah_text, method, calculate_for_words=False): output_file = f"{method}-{'words' if calculate_for_words else 'letters'}.txt" with open(output_file, 'w', encoding='utf-8') as f: lines = torah_text.splitlines() for line in lines: if calculate_for_words: words = line.split() word_values = [str(calculate_gematria(word, method)) for word in words] f.write(" ".join(word_values) + "\n") else: letter_values = [str(calculate_gematria(char, method)) for char in line if char != ' '] f.write(" ".join(letter_values) + "\n") # Main function to process the text def process_torah_chapter(file_path): torah_text = read_torah(file_path) for method in gematria_methods: save_gematria(torah_text, method, calculate_for_words=False) # Save letter gematria save_gematria(torah_text, method, calculate_for_words=True) # Save word gematria # Example usage process_torah_chapter('torah_text.txt') # Replace with your file path