forked from norybaby/poet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrhyme_helper.py
35 lines (28 loc) · 875 Bytes
/
rhyme_helper.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
class RhymeWords():
rhyme_list = []
@staticmethod
def read_rhyme_words(infile):
with open(infile,'r',encoding='utf-8',errors='ignore') as fr:
for line in fr:
words = set(line.split())
RhymeWords.rhyme_list.append(words)
@staticmethod
def get_rhyme_words(w):
for words in RhymeWords.rhyme_list:
if w in words:
return words
return None
@staticmethod
def print_stats():
count = 0
for words in RhymeWords.rhyme_list:
count += len(words)
print(words)
for w in words:
if len(w) > 1:
print(w)
print('count = ',count)
if __name__ == '__main__':
infile = './data/poem/rhyme_words.txt'
RhymeWords.read_rhyme_words(infile)
RhymeWords.print_stats()