-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsengen.py
More file actions
115 lines (86 loc) · 2.69 KB
/
sengen.py
File metadata and controls
115 lines (86 loc) · 2.69 KB
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
from random import randint
from datamuse import datamuse
"""
File: sengen.py
Generate sentences using context-free grammars.
"""
import random as rand
class CFG:
isNoun = True
isVerb = False
isAdj = False
sentence = "sink"
api = datamuse.Datamuse()
def countLines(file):
with open(file) as f:
lines = f.read().splitlines()
return lines
pronounList = countLines("C:/Users/Chubop/PycharmProjects/lil_lexie/pronouns")
nounList = countLines("C:/Users/Chubop/PycharmProjects/lil_lexie/nouns")
verbPhraseList = countLines("C:/Users/Chubop/PycharmProjects/lil_lexie/verb phrases")
verbList = countLines("C:/Users/Chubop/PycharmProjects/lil_lexie/verbs")
api = datamuse.Datamuse()
def makeRhyme(o):
foo_complete = api.words(rel_rhy=o, max=25)
list = []
for x in foo_complete:
list.append(x.get("word"))
print(list)
return list
def makeAntonym(o):
foo_complete = api.words(rel_ant=o, max=25)
list = []
for x in foo_complete:
list.append(x.get("word"))
print(list)
return list
def makeSentenceWithNoun(cfg):
word = cfg.sentence
if(cfg.isNoun == True):
verbPhrase = verbPhraseList[randint(1, len(verbPhraseList)) - 1]
pronoun = pronounList[randint(1, len(pronounList)) - 1]
cfg.sentence = "I'll " + verbPhrase + " " + pronoun + " " + word
return cfg.sentence
def makeSentenceWithVerb(cfg):
pass
def makeCouplet(word):
sentence = word
verbPhrase = verbPhraseList[randint(1, len(verbPhraseList)) - 1]
pronoun = pronounList[randint(1, len(pronounList)) - 1]
noun = nounList[randint(1, len(nounList)) - 1]
verb = verbList[randint(1, len(verbList)) - 1]
couplet = verb + " " + pronoun + " " + noun + " " + verbPhrase + " " + "a " + sentence
return couplet
def findVerbRhyme(word):
foo_complete = api.words(rel_rhy=word, max=25)
list = []
for x in foo_complete:
list.append(x.get("word"))
for x in list:
for y in verbList:
if x == y:
return y
def makeCoupletVerb(word):
verbPhrase = verbPhraseList[randint(1, len(verbPhraseList)) - 1]
sentence = word
list = makeAntonym(word)
couplet = "You " + list[randint(0, len(list)-1)] + " I " + sentence
return couplet
def checkNoun(word):
for x in nounList:
if(x == word):
return True
return False
def main():
rhymes = makeRhyme("sink")
cfg = CFG()
print(makeSentenceWithNoun(cfg))
word = rhymes[randint(0, len(rhymes)-1)]
while(checkNoun(word) != True):
word = rhymes[0]
print(checkNoun(word))
vRhyme = findVerbRhyme(word)
print(makeCoupletVerb(vRhyme))
()
if __name__ == "__main__":
main()