File size: 10,425 Bytes
8332c01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
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()