From 21fd372eb2bccd6934eec639da4059cb11130d89 Mon Sep 17 00:00:00 2001 From: UndeadMaelys Date: Tue, 17 May 2022 17:52:00 +0200 Subject: [PATCH] uhh sentences are fun. no plural at all so far tho --- main.lua | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++- strings.lua | 63 +++++++++++++++++++++++++ 2 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 strings.lua diff --git a/main.lua b/main.lua index a7b5723..35ed69f 100644 --- a/main.lua +++ b/main.lua @@ -1,12 +1,142 @@ +-- welcome to code hell :3 + require "quick-terminal-customization" +require "strings" + +-- lets get the words +words = dofile("heonian-content/words.lua") + +-- lets slice up the multiple types a word can be into lists +ListNouns = {} +ListModifiers = {} +ListVerbs = {} +ListMarkers = {} +ListInterrogativePronouns = {} +ListPersonalPronouns = {} + +for _, v in pairs(words) do -- v 1 = word / v 3 = type / v 2 = meaning. + v[1] = find_n_replace(v[1], "[.]","'") + v[1] = minimum_apostrophes(v[1]) + if v[1] == "re" or v[1] == "ba" or v[1] == "i'ma" then + table.insert(ListPersonalPronouns, {v[1], v[3], v[2]}) + end + + if string.find(v[3],"pronoun") then + table.insert(ListInterrogativePronouns, {v[1], v[3], v[2]}) + --print("pronoun") + elseif string.find(v[3],"noun") then + table.insert(ListNouns, {v[1], v[3], v[2]}) + --print("noun") + end + + if string.find(v[3],"verb") then + table.insert(ListVerbs, {v[1], v[3], v[2]}) + --print("verb") + end + + if string.find(v[3],"modifier") then + table.insert(ListModifiers, {v[1], v[3], v[2]}) + --print("modifier") + end + + if string.find(v[3],"marker") then + table.insert(ListMarkers, {v[1], v[3], v[2]}) + --print("modifier") + end +end + +function SentenceConstruct() + local sentence = "" + local r = 0 + local formal = false + -- formal or not? + local r = math.random(4) + if r == 1 then + formal = true + end + -- lets get subject + -- 80% pronoun + -- 20% noun + local subject = "" + local subject_unmodified = "" + r = math.random(10) + if r < 3 then + subject = ListNouns[math.random(#ListNouns)][1] + else + subject = ListPersonalPronouns[math.random(#ListPersonalPronouns)][1] + if formal then + subject = subject .. "lfur" + end + subject_unmodified = subject + end + + -- lets modify subject 30% of times + r = math.random(10) + if r < 4 then + subject = ListModifiers[math.random(#ListModifiers)][1] .. " ".. subject + end + + sentence = sentence .. subject .. " chu" + + -- objects? + -- lets refer to the something 30% of the time + r = math.random(10) + if r < 4 then + local rr = math.random(3) + if subject_unmodified and rr > 1 then -- refer to subject + sentence = sentence .. " " .. subject_unmodified .. "la " .. ListNouns[math.random(#ListNouns)][1] + else -- lets make up + sentence = sentence .. " " .. ListPersonalPronouns[math.random(#ListPersonalPronouns)][1] + print(sentence) + if formal then + sentence = sentence .. "lfur" + end + sentence = sentence .. "la " .. ListNouns[math.random(#ListNouns)][1] + end + elseif r < 8 then + sentence = sentence .. " " .. ListNouns[math.random(#ListNouns)][1] + sentence = sentence .. " " .. ListMarkers[math.random(#ListMarkers)][1] + end + + -- verb + local verb = ListVerbs[math.random(#ListVerbs)][1] + -- lets conjugate + -- 5% infinitive + -- 30% past + -- 65% present + print(verb) + r = math.random(20) + if r == 1 then -- infinitive + elseif r < 7 then -- past + if formal then + verb = string.sub(verb,1,#verb-1) .. "ome" + else + verb = string.sub(verb,1,#verb-2) .. "'me" + end + else -- present + if formal then + verb = string.sub(verb,1,#verb-1) .. "a'nya" + else + verb = string.sub(verb,1,#verb-2) .. "'nya" + end + end + -- 20% modify verb + r = math.random(5) + if r == 1 then + verb = ListModifiers[math.random(#ListModifiers)][1] .. " ".. verb + end + sentence = sentence .. " " .. verb + + return sentence +end function LoopStart() os.execute("clear") print(string.color(TERMINAL_COLOR.HighYellow,"-- HEONIAN LANGUAGE EXERCISES (HLE) --")) end - while 1 do LoopStart() + print(SentenceConstruct()) io.read() end \ No newline at end of file diff --git a/strings.lua b/strings.lua new file mode 100644 index 0000000..0487b18 --- /dev/null +++ b/strings.lua @@ -0,0 +1,63 @@ +function string.split(str, find, tbl) + split = tbl or {} + local p = 0 + local continue = true + while continue do + word = string.sub(str,p,string.find(str,find,p+1,-1)) + table.insert(split,word) + if string.find(str,find,p) then + str = string.sub(str,p) + p = string.find(str,find,p) + continue = true + p = p + 1 + else + continue = false + end + end + return split +end + +function strip_symbols(str) + local symbol_table = "'~()!?:>