Created
August 27, 2021 19:05
-
-
Save fabiommendes/242cc0b611e63136f4890f922a334c7c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from random import choice | |
""" | |
intro : PLANETA em SIGNO <apontamento> | |
apontamento : VERBO_APTO sorte. | |
sorte : você terá SORTE AREA_DA_VIDA | |
| <sorte>, mas <sorte> | |
| <sorte> e também <sorte> | |
continuacao : "Cuidado com novas amizades, pois Marte e Mercúrio opostos sinalizam conflitos para o signo de Cancer." | |
""" | |
PLANETA = ["Mercúrio", "Vênus", "Marte", "Lua", "Plutão"] | |
SIGNO = ["Capricórnio", "Escorpião", "Touro", "Peixes", "Áries"] | |
VERBO_APTO = ["indica que", "sugere que", "garante que"] | |
SORTE = ["muita sorte", "azar", "surpresas", "percalços", "supresas desagradáveis"] | |
AREA_DA_VIDA = ["no emprego", "no amor", "nas amizades", "na família", "nos estudos"] | |
gramatica = { | |
"intro": [ | |
[PLANETA, ["em"], SIGNO, "apontamento", ["."]], | |
], | |
"apontamento": [ | |
[VERBO_APTO, "sorte"], | |
], | |
"sorte": [ | |
[["você terá"], SORTE, AREA_DA_VIDA], | |
[["você terá"], SORTE, AREA_DA_VIDA], | |
[["você terá"], SORTE, AREA_DA_VIDA], | |
[["você terá"], SORTE, AREA_DA_VIDA], | |
[["você terá"], SORTE, AREA_DA_VIDA], | |
["sorte", [", mas"], "sorte"], | |
["sorte", ["e também"], "sorte"], | |
[], | |
], | |
"continuacao": [ | |
[["Cuidado com novas amizades, pois Marte e Mercúrio opostos sinalizam conflitos para o signo de Cancer."]], | |
], | |
} | |
def palavras(gramatica, symb): | |
res = [] | |
producao = choice(gramatica[symb]) | |
for symb in producao: | |
if isinstance(symb, list): | |
res.append(choice(symb)) | |
else: | |
res.extend(palavras(gramatica, symb)) | |
return res | |
def exemplo(gramatica=gramatica, symb="intro"): | |
return ' '.join(palavras(gramatica, symb)) | |
print(exemplo()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment