uhh sentences are fun. no plural at all so far tho
This commit is contained in:
parent
a67ed078e9
commit
21fd372eb2
132
main.lua
132
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
|
63
strings.lua
Normal file
63
strings.lua
Normal file
@ -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 = "'~()!?:></.,\t…"
|
||||
for i=1, #symbol_table do
|
||||
while string.find(str, "%"..string.sub(symbol_table,i,i)) do
|
||||
str = string.gsub(str, "%"..string.sub(symbol_table,i,i),"")
|
||||
end
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
|
||||
function find_n_replace(str, find,repl, caution)
|
||||
if string.find(str, find) then
|
||||
if caution then
|
||||
if not string.find(str, caution, string.find(str, find)+string.len(find)-string.len(caution)) then -- sometimes you want to avoid certain false positives
|
||||
str = string.gsub(str,find, repl)
|
||||
end
|
||||
else
|
||||
str = string.gsub(str,find, repl)
|
||||
end
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
function minimum_apostrophes(str)
|
||||
local restr = ""
|
||||
for i = 1, #str do
|
||||
if string.sub(str,i,i) == "'" then -- only makes sense to separate vowels from vowels
|
||||
if string.find(string.sub(str,i-1,i-1),"[aeiou]") then
|
||||
if string.find(string.sub(str,i+1,i+1),"[aeiou]") then
|
||||
restr = restr .. string.sub(str,i,i)
|
||||
end
|
||||
else -- only consontant meaningful of checking is n'y opposed to ny
|
||||
if string.find(string.sub(str,i-1,i-1),"[n]")
|
||||
and string.find(string.sub(str,i+1,i+1),"[y]") then
|
||||
restr = restr .. string.sub(str,i,i)
|
||||
end
|
||||
end
|
||||
else
|
||||
restr = restr .. string.sub(str,i,i)
|
||||
end
|
||||
end
|
||||
return restr
|
||||
end
|
Loading…
Reference in New Issue
Block a user