-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgemGram.py
67 lines (55 loc) · 1.88 KB
/
gemGram.py
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
import random
import getwordsfromdbs as gwdb
import sys
from termcolor import colored, COLORS
def calculateGematria(word, cipher="English extended"):
# Dictionary of letter to numerical value mappings
if cipher == "English extended":
values = {
'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8,
'i': 9, 'j': 10, 'k': 20, 'l': 30, 'm': 40, 'n': 50, 'o': 60,
'p': 70, 'q': 80, 'r': 90, 's': 100, 't': 200, 'u': 300, 'v': 400,
'w': 500, 'x': 600, 'y': 700, 'z': 800
}
else:
# Add other ciphers here as necessary
raise ValueError("Unsupported cipher")
# Calculate the gematria value by summing the values of each letter
value = 0
for letter in word:
value += values.get(letter.lower(), 0)
return value
def buildGematriaDictionary(wordlist):
gematria_dict = {}
for word in wordlist:
gematria = calculateGematria(word)
if gematria in gematria_dict:
gematria_dict[gematria].append(word)
else:
gematria_dict[gematria] = [word]
return gematria_dict
def transformText(text, gematria_dict):
transformed_text = ""
words = text.split()
for word in words:
gematria = calculateGematria(word)
if gematria in gematria_dict:
replacement_word = random.choice(gematria_dict[gematria])
transformed_text += replacement_word + " "
else:
transformed_text += word + " "
return transformed_text
wordlist = gwdb.getDeepMem()
gematria_dict = buildGematriaDictionary(wordlist)
if len(sys.argv)>1:
text = sys.argv[1]
else:
text = "testisana"
if len(sys.argv)>2:
iter = int(sys.argv[2])
else:
iter = 1
print("Transforming sentence: "+text)
for i in range(iter):
transformed_text = transformText(text, gematria_dict)
print(colored(transformed_text, "red"))