forked from hayderkharrufa/arabic_poem_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhymes.py
34 lines (27 loc) · 1.1 KB
/
rhymes.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
# coding: utf-8
# author: Haydara https://www.youtube.com/haydara
import pickle
with open('vocabs.pkl', 'rb') as pickle_load:
voc_list = pickle.load(pickle_load)
allowed_chars = ['ذ', 'ض', 'ص', 'ث', 'ق', 'ف', 'غ', 'ع', 'ه', 'خ', 'ح', 'ج', 'د',
'ش', 'س', 'ي', 'ب', 'ل', 'ا', 'أ', 'ت', 'ن', 'م', 'ك', 'ط', 'ئ', 'ء', 'ؤ', 'ر', 'ى',
'ة', 'و', 'ز', 'ظ', 'ّ', ' ']
max_word_length = 9
def rhymes_with(word):
if word not in ['الله', 'والله', 'بالله', 'لله', 'تالله']:
word = word.replace('ّ', '')
ending = word[-2:]
rhymes = []
for w in voc_list:
if len(w) < max_word_length and w.endswith(ending):
rhymes.append(w)
return rhymes
def rhymes_with_last_n_chars(word, n):
if word not in ['الله', 'والله', 'بالله', 'لله', 'تالله', 'فالله']:
word = word.replace('ّ', '')
ending = word[-n:]
rhymes = []
for w in voc_list:
if len(w) < max_word_length and w.endswith(ending):
rhymes.append(w)
return rhymes