Spaces:
Runtime error
Runtime error
| import json | |
| from prettytable import PrettyTable | |
| from colorama import Fore, Style | |
| from collections import defaultdict | |
| import unicodedata | |
| def strip_diacritics(text): | |
| """ | |
| Entfernt Diakritika von Unicode-Zeichen, um den Basisbuchstaben zu erhalten, und gibt Warnungen | |
| f眉r tats盲chlich unbekannte Zeichen aus. | |
| """ | |
| stripped_text = '' | |
| for char in unicodedata.normalize('NFD', text): | |
| if unicodedata.category(char) not in ['Mn', 'Cf']: | |
| stripped_text += char | |
| else: | |
| print(f"Info: Diakritisches Zeichen '{char}' wird ignoriert.") | |
| return stripped_text | |
| def hebrew_letter_to_value(letter): | |
| """ | |
| Konvertiert einen einzelnen Buchstaben in seinen Gematria-Wert, ignoriert Leerzeichen | |
| und Nicht-Buchstaben-Zeichen. | |
| """ | |
| # Dein vorhandenes W枚rterbuch bleibt unver盲ndert | |
| values = { | |
| # Lateinische Buchstaben | |
| 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 600, | |
| 'k': 10, 'l': 20, 'm': 30, 'n': 40, 'o': 50, 'p': 60, 'q': 70, 'r': 80, 's': 90, | |
| 't': 100, 'u': 200, 'v': 700, 'w': 900, 'x': 300, 'y': 400, 'z': 500, | |
| 'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6, 'G': 7, 'H': 8, 'I': 9, 'J': 600, | |
| 'K': 10, 'L': 20, 'M': 30, 'N': 40, 'O': 50, 'P': 60, 'Q': 70, 'R': 80, 'S': 90, | |
| 'T': 100, 'U': 200, 'V': 700, 'W': 900, 'X': 300, 'Y': 400, 'Z': 500, | |
| # Basisbuchstaben und einige bereits genannte Varianten | |
| '丕': 1, '兀': 1, '廿': 1, '丌': 1, '亘': 2, '噩': 3, '丿': 4, '賴': 5, '賵': 6, '夭': 7, '丨': 8, '胤': 9, | |
| '賷': 10, '賶': 10, '賰': 20, '讴': 20, '賱': 30, '賲': 40, '賳': 50, '爻': 60, '毓': 70, '賮': 80, | |
| '氐': 90, '賯': 100, '乇': 200, '卮': 300, '鬲': 400, '孬': 500, '禺': 600, '匕': 700, '囟': 800, '馗': 900, '睾': 1000, | |
| '俦': 1, # Alif Wasla | |
| '賭': 0, # Tatweel | |
| # Zus盲tzliche Varianten und Sonderzeichen | |
| '丞': 400, # Taa Marbuta | |
| '丐': 6, # Waw mit Hamza dar眉ber | |
| '卅': 10, # Ya mit Hamza dar眉ber | |
| '亍': 1, # Hamza | |
| '賶': 10, # Alif Maqsurah | |
| '俟': 400, # Taa' marbuta goal | |
| '倬': 2, # Pe (Persisch/Urdu) | |
| '趩': 3, # Che (Persisch/Urdu) | |
| '跇': 7, # Zhe (Persisch/Urdu) | |
| '诏': 20, # Gaf (Persisch/Urdu) | |
| '诃': 20, # Ngaf (Kazakh, Uyghur, Uzbek, and in some Arabic dialects) | |
| '诤': 50, # Noon Ghunna (Persisch/Urdu) | |
| '踿': 5, # Heh with Yeh above (Persisch/Urdu) | |
| '蹝': 10, # Barree Yeh (Persisch/Urdu) | |
| '貗': 0, # Afghani Sign (wird als W盲hrungssymbol verwendet, nicht f眉r Gematria relevant, aber hier zur Vollst盲ndigkeit aufgef眉hrt) | |
| # Anmerkung: Das W盲hrungssymbol und 盲hnliche Zeichen sind in einem Gematria-Kontext normalerweise nicht relevant, | |
| # werden aber der Vollst盲ndigkeit halber aufgef眉hrt. Es gibt noch viele weitere spezifische Zeichen in erweiterten | |
| # arabischen Schriftsystemen (z.B. f眉r andere Sprachen wie Persisch, Urdu, Pashto usw.), die hier nicht vollst盲ndig | |
| # abgedeckt sind. | |
| # Grund- und Schlussformen hebr盲ischer Buchstaben | |
| '讗': 1, '讘': 2, '讙': 3, '讚': 4, '讛': 5, '讜': 6, '讝': 7, '讞': 8, '讟': 9, '讬': 10, | |
| '讻': 20, '讱': 500, '诇': 30, '诪': 40, '诐': 600, '谞': 50, '谉': 700, '住': 60, '注': 70, '驻': 80, '祝': 800, | |
| '爪': 90, '抓': 900, '拽': 100, '专': 200, '砖': 300, '转': 400, | |
| # Griechische Buchstaben | |
| '伪': 1, '尾': 2, '纬': 3, '未': 4, '蔚': 5, '蠞': 6, '味': 7, '畏': 8, '胃': 9, '喂': 10, | |
| '魏': 20, '位': 30, '渭': 40, '谓': 50, '尉': 60, '慰': 70, '蟺': 80, '蠠': 90, '蟻': 100, | |
| '蟽': 200, '蟿': 300, '蠀': 400, '蠁': 500, '蠂': 600, '蠄': 700, '蠅': 800, '稀': 900, | |
| # Griechische Gro脽buchstaben | |
| '螒': 1, '螔': 2, '螕': 3, '螖': 4, '螘': 5, '蠝': 6, '螙': 7, '螚': 8, '螛': 9, '螜': 10, | |
| '螝': 20, '螞': 30, '螠': 40, '螡': 50, '螢': 60, '螣': 70, '螤': 80, '蠟': 90, '巍': 100, | |
| '危': 200, '韦': 300, '违': 400, '桅': 500, '围': 600, '唯': 700, '惟': 800, '蠣': 900, | |
| } | |
| # Stelle sicher, dass Diakritika entfernt werden, bevor auf das W枚rterbuch zugegriffen wird | |
| letter_no_diacritics = strip_diacritics(letter) | |
| if letter_no_diacritics in values: | |
| return values[letter_no_diacritics.lower()] | |
| elif letter.strip() == "": # Ignoriere Leerzeichen und leere Zeilen | |
| return 0 | |
| else: | |
| # Gib eine spezifische Warnung aus, wenn das Zeichen unbekannt ist | |
| print(f"Warnung: Unbekanntes Zeichen '{letter}' ignoriert.") | |
| return 0 | |
| def calculate_gematria(text): | |
| """Calculate the Gematria value of a given Hebrew text, ignoring spaces and non-Hebrew characters.""" | |
| return sum(hebrew_letter_to_value(letter) for letter in text if letter.strip() != "") | |
| # Funci贸n para calcular el valor de gematria de una letra hebrea antigua | |
| def gematria(letra): | |
| valores = {'讗': 1, '讘': 2, '讙': 3, '讚': 4, '讛': 5, '讜': 6, '讝': 7, '讞': 8, '讟': 9, | |
| '讬': 10, '讻': 20, '诇': 30, '诪': 40, '谞': 50, '住': 60, '注': 70, '驻': 80, | |
| '爪': 90, '拽': 100, '专': 200, '砖': 300, '转': 400, '讱': 20, '诐': 40, '谉': 50, '祝': 80, '抓': 90} | |
| return valores.get(letra, 0) | |
| # Funci贸n para generar todas las combinaciones posibles de dos letras en hebreo antiguo | |
| def generar_combinaciones(): | |
| letras = ['讗', '讘', '讙', '讚', '讛', '讜', '讝', '讞', '讟', '讬', '讻', '诇', '诪', '谞', '住', '注', '驻', '爪', '拽', '专', '砖', '转', | |
| '讱', '诐', '谉', '祝', '抓'] | |
| combinaciones = [] | |
| for letra1 in letras: | |
| for letra2 in letras: | |
| combinaciones.append(letra1 + letra2) | |
| return combinaciones | |
| # Funci贸n para calcular la suma de los valores de gematria y el producto de los valores de gematria de una combinaci贸n | |
| def calcular_valores(combinacion): | |
| valor1 = gematria(combinacion[0]) | |
| valor2 = gematria(combinacion[1]) | |
| suma = valor1 + valor2 | |
| producto = valor1 * valor2 | |
| ratio = valor1 / valor2 if valor2 != 0 else float('inf') | |
| return suma, producto, ratio | |
| # Funci贸n principal | |
| def main(): | |
| combinaciones = generar_combinaciones() | |
| table = PrettyTable() | |
| table.field_names = ["#", Fore.BLUE + "Producto" + Style.RESET_ALL, | |
| Fore.BLUE + "Suma" + Style.RESET_ALL, | |
| Fore.BLUE + "Ratio" + Style.RESET_ALL, | |
| Fore.BLUE + "Valor 2" + Style.RESET_ALL, | |
| Fore.BLUE + "Valor 1" + Style.RESET_ALL, | |
| Fore.BLUE + "Combinaci贸n" + Style.RESET_ALL] | |
| # Diccionario de combinaciones agrupadas por ratio | |
| combinaciones_por_ratio = defaultdict(set) | |
| # Versos del G茅nesis Sefard铆 (ejemplo) | |
| versos_genesis_sefardi = [ | |
| "讘专讗砖讬转 讘专讗 讗诇讛讬诐 讗转 讛砖诪讬诐 讜讗转 讛讗专抓", | |
| "讜讛讗专抓 讛讬转讛 转讛讜 讜讘讛讜 讜讞砖讱 注诇志驻谞讬 转讛讜诐 讜专讜讞 讗诇讛讬诐 诪专讞驻转 注诇志驻谞讬 讛诪讬诐", | |
| "讜讬讗诪专 讗诇讛讬诐 讬讛讬 讗讜专 讜讬讛讬志讗讜专", | |
| "讜讬专讗 讗诇讛讬诐 讗转志讛讗讜专 讻讬志讟讜讘 讜讬讘讚诇 讗诇讛讬诐 讘讬谉 讛讗讜专 讜讘讬谉 讛讞砖讱", | |
| "讜讬拽专讗 讗诇讛讬诐 诇讗讜专 讬讜诐 讜诇讞砖讱 拽专讗 诇讬诇讛 讜讬讛讬志注专讘 讜讬讛讬志讘拽专 讬讜诐 讗讞讚" | |
| # Agrega m谩s versos seg煤n sea necesario... | |
| ] | |
| # Funci贸n para obtener el primer par de letras de un verso | |
| def obtener_primer_par_letras(verso): | |
| for i in range(len(verso) - 1): | |
| if verso[i].isalpha() and verso[i+1].isalpha(): | |
| return verso[i:i+2] | |
| return None | |
| # Diccionario para almacenar el primer par de letras y su ratio por verso | |
| primer_par_por_verso = {} | |
| for verso in versos_genesis_sefardi: | |
| primer_par = obtener_primer_par_letras(verso) | |
| if primer_par: | |
| suma, producto, ratio = calcular_valores(primer_par) | |
| primer_par_por_verso[verso] = (primer_par, ratio) | |
| # Diccionario para agrupar los primeros pares de letras por ratio | |
| primer_par_por_ratio = defaultdict(list) | |
| for verso, (primer_par, ratio) in primer_par_por_verso.items(): | |
| primer_par_por_ratio[ratio].append((primer_par, verso)) | |
| # Crear la tabla de primeros pares de letras por ratio | |
| table_primer_par = PrettyTable() | |
| table_primer_par.field_names = [Fore.BLUE + "Primer Par" + Style.RESET_ALL, Fore.BLUE + "Ratio" + Style.RESET_ALL, Fore.BLUE + "Verso" + Style.RESET_ALL] | |
| for ratio, pares_verso in sorted(primer_par_por_ratio.items(), key=lambda x: x[0], reverse=True): | |
| for primer_par, verso in pares_verso: | |
| table_primer_par.add_row([primer_par, f"{ratio:.2f}", verso]) | |
| print(table_primer_par) | |
| # Procesar combinaciones y crear la tabla principal | |
| for idx, combinacion in enumerate(combinaciones, start=1): | |
| suma, producto, ratio = calcular_valores(combinacion) | |
| combinacion_str = combinacion | |
| # Resaltar en verde si la combinaci贸n est谩 en el conjunto de combinaciones del G茅nesis Sefard铆 | |
| if combinacion in set(''.join(obtener_primer_par_letras(verso)) for verso in versos_genesis_sefardi): | |
| combinacion_str = Fore.GREEN + combinacion + Style.RESET_ALL | |
| table.add_row([idx, producto, suma, f"{ratio:.2f}", gematria(combinacion[1]), gematria(combinacion[0]), combinacion_str]) | |
| combinaciones_por_ratio[ratio].add(combinacion) | |
| # Mostrar la tabla de combinaciones | |
| print("\nTabla de combinaciones:") | |
| print(table) | |
| # Mostrar la tabla de combinaciones agrupadas por ratio | |
| print("\nTabla de combinaciones agrupadas por ratio:") | |
| table_ratio = PrettyTable() | |
| table_ratio.field_names = [Fore.BLUE + "Ratio" + Style.RESET_ALL, Fore.BLUE + "Combinaciones" + Style.RESET_ALL] | |
| for ratio, combinaciones in sorted(combinaciones_por_ratio.items(), key=lambda x: x[0], reverse=True): | |
| combinaciones_str = ", ".join(combinaciones) | |
| table_ratio.add_row([f"{ratio:.2f}", combinaciones_str]) | |
| print(table_ratio) | |
| # Calcular el n煤mero de combinaciones 煤nicas de primeros pares de letras | |
| primeros_pares_unicos = set(primer_par for primer_par, _ in primer_par_por_verso.values()) | |
| num_primeros_pares_unicos = len(primeros_pares_unicos) | |
| num_combinaciones_totales = len(combinaciones) | |
| print(f"\nN煤mero de primeros pares de letras 煤nicos: {num_primeros_pares_unicos}") | |
| print(f"N煤mero de combinaciones totales posibles: {num_combinaciones_totales}") | |
| if __name__ == "__main__": | |
| main() | |