@JimSkon/

SentenceGenerator2

Python

No description

fork
loading
Files
  • main.py
main.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
import random
S=["NP VP"]
NP=["Det N","Det Adj N", "Proper"]
VP=["V"]
Proper=["Amanda","Zunnie","Raul"]
nouns=["box","tree","shovel","cat","window","school","blacksmith"]
adjs=["crazy","odd","orange","silly","hungrey"]
verbs=["sings","runs","falls","spins","is","snacks","loves","rests"]
dets=["a","my","the","that"]

def applyRules(phrase):
  print(phrase)
  newStr=""
  for token in phrase.split():
    if token=="S":
      next=random.choice(S)
    elif token=="NP":
      next=random.choice(NP)
    elif token=="VP":
      next=random.choice(VP)
    elif token=="Det":
      next=random.choice(dets)
    elif token=="N":
      next=random.choice(nouns)
    elif token=="Proper":
      next=random.choice(Proper)
    elif token=="V":
      next=random.choice(verbs)
    elif token=="Adj":
      next=random.choice(adjs)
    else:
      next=token
    newStr += next + " "
  return(newStr)

def createSentence(n,start):
  sent=start
  for i in range(n):
    sent=applyRules(sent)
  return(sent)
   
print(createSentence(3,"S"))