Browse Source

added sentence generator

master
Weird Constructor 3 years ago
parent
commit
1faf5a8267
  1. 11
      godot_project/gamelib/test_wgt.wl
  2. 25
      godot_project/gamelib/wordgen_tmpl.wl
  3. 8
      scripts/calc_markov.wl
  4. 20
      scripts/input.txt

11
godot_project/gamelib/test_wgt.wl

@ -0,0 +1,11 @@
!@import wgt wordgen_tmpl;
!word_set = ${
who = $[$[1, "You"], $[1, "I"], $[1, "Bob"], $[1, "Alice"]],
where = $[$[1, "to the mall"], $[1, "to the cinema"], $[4, "shopping"]],
};
range 1 10 1 {||
std:displayln ~
wgt:tmpl_gen word_set "{who} wants to go {where}.";
}

25
godot_project/gamelib/wordgen_tmpl.wl

@ -0,0 +1,25 @@
!@import std std;
!@import wlambda;
!@import wg wordgen;
!sm = std:rand:split_mix64_new[];
!new_gen = {!(word_set, tmpl) = @;
wg:gen $[tmpl] word_set {
std:rand:split_mix64_next_open01 sm
};
};
!@export tmpl_gen = {!(word_set, s) = @;
(std:fold $[] {
!out = _1;
!tmpl_word = _.1;
std:push out _.0;
(not ~ is_none tmpl_word) {
std:push out ~ new_gen word_set tmpl_word;
};
_1
} ~ std:re:map $q$([^{]*)(?:\{([^}]+)\})?$ {
$[_.1, _.2]
} s) | std:str:join "";
};

8
scripts/calc_markov.wl

@ -1,5 +1,6 @@
!txt = std:io:file:read_text "input.txt";
!start_words = $[];
!words = ${};
!last_word = $&$none;
std:re:map "([a-zA-Z]+|[.,])" \:next {
@ -12,7 +13,10 @@ std:re:map "([a-zA-Z]+|[.,])" \:next {
.last_word = word;
return :next $n;
};
!lc_last_word = std:str:to_lowercase last_word;
!lc_last_word = last_word; # std:str:to_lowercase last_word;
(lc_last_word == ".") {
std:push start_words word;
};
(is_none words.(lc_last_word)) {
words.(lc_last_word) = $[word];
} {
@ -33,7 +37,7 @@ words {
range 1 10 1 {!(i) = @;
!out = $&$[];
!vec = word_vec;
!vec = start_words;
!word_min_len =
5 + std:num:abs[std:rand:split_mix64_next r] % 4;

20
scripts/input.txt

@ -112,7 +112,7 @@
Do so: farewell.
Exit BALTHASAR
BALTHASAR
Come hither, Leonato. What was it you told me of
to-day, that your niece Beatrice was in love with
@ -380,7 +380,7 @@
point and choke a daw withal. You have no stomach,
signior: fare you well.
Exit
Ha! 'Against my will I am sent to bid you come in
@ -391,7 +391,7 @@
not take pity of her, I am a villain; if I do not
love her, I am a Jew. I will go get her picture.
Exit
@ -413,7 +413,7 @@
I'll make her come, I warrant you, presently.
Exit
Now, Ursula, when Beatrice doth come,
@ -576,7 +576,7 @@
For others say thou dost deserve, and I
Believe it better than reportingly.
Exit
@ -1146,7 +1146,7 @@
Well.
Exit
Troth, I think your other rabato were better.
@ -2140,7 +2140,7 @@
brought to Leonato's: I will go before and show
him their examination.
Exit
Come, let them be opinioned.
@ -2514,7 +2514,7 @@
Lackbeard there, he and I shall meet: and, till
then, peace be with him.
Exit
He is in earnest.
@ -2797,7 +2797,7 @@
And therefore will come.
Exit MARGARET
MARGARET
Sings
@ -3059,7 +3059,7 @@
Call her forth, brother; here's the friar ready.
Exit ANTONIO
ANTONIO
Good morrow, Benedick. Why, what's the matter,

Loading…
Cancel
Save