Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(link).
- -compile(export_all).
- main(Psi) ->
- {_, List} = generate(top, Psi),
- iolist_to_binary(List).
- g(top) ->
- [
- [{intro}, idrather]
- ];
- g(idrather) ->
- [
- [<<"I'd rather">>, action]
- ];
- g(intro) ->
- [
- [adj_holy, [adj_holy], [adj], god, {adverb}, <<",">>]
- ];
- g(action) ->
- [
- [<<"eat">>, substance],
- [<<"drink">>, substance, <<"smoothie">>],
- [<<"fuck">>, animal],
- [<<"take it from">>, animal]
- ];
- g(subject) ->
- [
- [article, [adj], noun]
- ];
- g(adverb) ->
- [
- [<<"in a bag of">>, substance]
- ];
- g(animal) ->
- [
- [article, {adj}, n_animal]
- ];
- g(n_animal) ->
- dict(["cow", "dog", "goat", "rooster"]);
- g(god) ->
- dict(["baby Jesus", "Jesus", "God", "cow", "virgin Mary"]);
- g(substance) ->
- [
- [{someones}, n_substance]
- ];
- g(someones) ->
- [
- [animal, <<"='s">>],
- [god, <<"='s">>]
- ];
- g(n_substance) ->
- dict(["piss", "shit", "jizz", "pee"]);
- g(adj_holy) ->
- dict(["sweet", "holy", "almighty"]);
- g(adj) ->
- [
- [<<", soaked in">>, substance, <<",">>],
- [substance, <<"=-flavored">>]
- |dict(["rotten", "rabid", "putrid", "dead", "deceased", "dead", "tap-dancing", "worm-infested"])
- ];
- g(verb) ->
- dict(["eat", "fuck", "flagellate"]);
- g(noun) ->
- dict(["goat", "dog", "granpa"]);
- g(article) ->
- dict(["a"]);
- g(A) ->
- [[atom_to_binary(A, utf8)]].
- generate({_Optional}, 0) ->
- %% When we run out of psihoza, we should not generate optional
- %% terms:
- {0, []};
- generate({Optional}, Psi) ->
- case rand:uniform(2) of
- 1 -> {Psi, []};
- 2 -> generate(Optional, Psi)
- end;
- generate([_], 0) ->
- {0, []};
- generate([Repeat], Psi0) ->
- case rand:uniform(2) of
- 1 -> {Psi0, []};
- 2 ->
- {Psi1, Hd} = generate(Repeat, Psi0),
- {Psi, Tl} = generate([Repeat], Psi1),
- {Psi, [Hd|Tl]}
- end;
- generate(Tree, Psi) when is_atom(Tree) ->
- Voretions = g(Tree),
- Pos = rand:uniform(length(Voretions)),
- Tokens = lists:nth(Pos, Voretions),
- lists:foldr(fun do_generate/2, {Psi, []}, Tokens);
- generate(Terminal, _) when is_binary(Terminal) ->
- {1, [<<" ">>, Terminal]}.
- do_generate(Term, {Psi0, Acc}) ->
- {Psi, Hd} = generate(Term, Psi0),
- {Psi, [Hd|Acc]}.
- dict(L) ->
- [[list_to_binary(I)] || I <- L].
Add Comment
Please, Sign In to add comment