@JimSkon/

SentenceGenerator1

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.36709065261843365","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHJhbmRvbQpub3Vucz1bImJveCIsInRyZWUiLCJzaG92ZWwiLCJjYXQiLCJ3aW5kb3ciLCJzY2hvb2wiLCJibGFja3NtaXRoIl0KYWRqcz1bImNyYXp5Iiwib2RkIiwib3JhbmdlIiwic2lsbHkiLCJodW5ncmV5IiwiIl0KdmVyYnM9WyJzaW5ncyIsInJ1bnMiLCJmYWxscyIsInNwaW5zIiwiaXMiLCJzbmFja3MiLCJsb3ZlcyIsInJlc3RzIl0KZGV0cz1bImEiLCJteSIsInRoZSIsInRoYXQiXQpwcmVwcz1bIm9uIiwiYnkiLCJ1bmRlciIsImluIl0KCmRlZiBhcHBseVJ1bGVzKHBocmFzZSk6CiAgcHJpbnQocGhyYXNlKQogIG5ld1N0cj0iIgogIGZvciB0b2tlbiBpbiBwaHJhc2Uuc3BsaXQoKToKICAgIGlmIHRva2VuPT0iUyI6CiAgICAgIG5leHQ9Ik5QIFZQIgogICAgZWxpZiB0b2tlbj09Ik5QIjoKICAgICAgbmV4dD0iRGV0IE4iCiAgICBlbGlmIHRva2VuPT0iVlAiOgogICAgICBuZXh0PSJWIgogICAgZWxpZiB0b2tlbj09IkRldCI6CiAgICAgIG5leHQ9cmFuZG9tLmNob2ljZShkZXRzKQogICAgZWxpZiB0b2tlbj09Ik4iOgogICAgICBuZXh0PXJhbmRvbS5jaG9pY2Uobm91bnMpCiAgICBlbGlmIHRva2VuPT0iViI6CiAgICAgIG5leHQ9cmFuZG9tLmNob2ljZSh2ZXJicykKICAgIGVsc2U6CiAgICAgIG5leHQ9dG9rZW4KICAgIG5ld1N0ciArPSBuZXh0ICsgIiAiCiAgcmV0dXJuKG5ld1N0cikKCmRlZiBjcmVhdGVTZW50ZW5jZShuLHN0YXJ0KToKICBzZW50PXN0YXJ0CiAgZm9yIGkgaW4gcmFuZ2Uobik6CiAgICBzZW50PWFwcGx5UnVsZXMoc2VudCkKICByZXR1cm4oc2VudCkKICAgCnByaW50KGNyZWF0ZVNlbnRlbmNlKDQsIlMiKSkKCgoKCg=="},"asBuffer":null},"loaded":true}}
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
import random
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"]
preps=["on","by","under","in"]

def applyRules(phrase):
  print(phrase)
  newStr=""
  for token in phrase.split():
    if token=="S":
      next="NP VP"
    elif token=="NP":
      next="Det N"
    elif token=="VP":
      next="V"
    elif token=="Det":
      next=random.choice(dets)
    elif token=="N":
      next=random.choice(nouns)
    elif token=="V":
      next=random.choice(verbs)
    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(4,"S"))