-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgemGram4.py
42 lines (36 loc) · 1.39 KB
/
gemGram4.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
from collections import defaultdict
from itertools import product
import getwordsfromdbs as gwdb
from gemNumFuncs import getGematria
import pyphen
import sys
def calculateGematria(word):
return getGematria(word, "ScaExt")
def find_matching_syllables(syllables, gematria_value):
matching_syllables = defaultdict(list)
for syllable in syllables:
value = calculateGematria(syllable)
matching_syllables[value].append(syllable)
return matching_syllables[gematria_value]
def generate_matching_words(syllables, words):
matching_words = []
for word in words:
word_syllables = extract_syllables(word)
possible_matching_syllables = [
find_matching_syllables(syllables, calculateGematria(word_syllable))
for word_syllable in word_syllables
]
for matching_word_syllables in product(*possible_matching_syllables):
matching_word = ''.join(matching_word_syllables)
if calculateGematria(matching_word) == calculateGematria(word):
matching_words.append(matching_word)
return matching_words
def extract_syllables(words):
dic = pyphen.Pyphen(lang='en_US')
syllables=[]
for word in words:
syllables += dic.inserted(word.lower()).split('-')
return syllables
words = gwdb.getDeepMem()
syllables = extract_syllables(words)
print(generate_matching_words(syllables, sys.argv[1]))