Created
July 11, 2018 08:26
-
-
Save BlogBlocks/e732e957038dfc977dd88932f6badac8 to your computer and use it in GitHub Desktop.
modeled after CFG generators, but much more simple to understand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def main(): | |
a = "A,The" | |
b = "dog,cat,little kid,elephant,mouse,ugly neighbor kid,princess,clown,chimp,priest" | |
c = "ran,cried,ate,made noise,jumped,slept,stepped on a spider" | |
d = "and said `hello` to the gerbil,and then ate the fish,with the turtle" | |
e = "without stopping,and called for his mother,along side his friend " | |
f = "didn't get to go to the zoo for crying., had to go home to eat.\ | |
,loved to eat pizza for breakfast.,just like a little piggy - cried all the way home" | |
NP =random.choice(a.split(",")) | |
VP =random.choice(b.split(",")) | |
VP1 =random.choice(c.split(",")) | |
VP1a =random.choice(c.split(",")) | |
VP2 =random.choice(d.split(",")) | |
VP3 =random.choice(e.split(",")) | |
if VP == "little kid" and VP1a == "slept": | |
VP1a = random.choice(f.split(",")) | |
S = random.choice([[NP,VP,VP1a],[NP,VP,VP1,VP3],[NP,VP,VP1,VP2]]) | |
print " ".join(S) | |
for x in range(20): | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just run the file no more needed:
example output from above:
The little kid didn't get to go to the zoo for crying.
A little kid ran
The chimp made noise and then ate the fish
The dog made noise and called for his mother
A little kid stepped on a spider and called for his mother
The ugly neighbor kid stepped on a spider along side his friend
The mouse ate
A elephant ate without stopping
The ugly neighbor kid cried without stopping
A chimp cried
A princess cried
The princess stepped on a spider
The cat stepped on a spider and called for his mother
The elephant cried and called for his mother