changes to badges and types n stuff

This commit is contained in:
UndeadMaelys
2022-05-08 18:31:09 +02:00
parent 3d0fc9145f
commit 941f701d7d
7 changed files with 1072 additions and 739 deletions

View File

@@ -1,12 +1,62 @@
require "r2h2_modified"
require "color"
words = dofile("heonian-content/words.lua")
input = arg[1] or "input.txt"
function apply(text)
print(text)
end
function printD(...)
io.stderr:write(
effectText(
EFFECT.Bold,
colorText(
COLOR.HighPurple,
"\tDEBUG:\t"
)
) ..
colorText(
COLOR.HighPurple,
table.unpack({...}) , "\n"
)
)
end
function printW(...)
io.stderr:write(
effectText(
EFFECT.Bold,
colorText(
COLOR.HighYellow,
"\t WARN:\t"
)
) ..
colorText(
COLOR.HighYellow,
table.unpack({...}) .. "\n"
)
)
end
function printE(...)
io.stderr:write(
effectText(
EFFECT.Bold,
colorText(
COLOR.HighRed,
"\tERROR:\t"
)
) ..
colorText(
COLOR.HighRed,
table.unpack({...}) .. "\n"
)
)
end
function process_content(content)
content = content .. " "
for i=1, 2 do
@@ -31,6 +81,7 @@ function process_content(content)
new_word = strip_symbols(new_word)
new_word, indicators = revert_verbs(new_word, indicators)
new_word, indicators = revert_nouns(new_word,indicators)
new_word, indicators = categorize_word(new_word,indicators)
add_word(new_word)
local html_stuff = [[
@@ -89,7 +140,7 @@ function process_content(content)
ac = string.sub(ac, string.find(ac, " ")+1)
-- now we print the thing with teh appropiate indicators.
--print(print_text, table.unpack(indicators))
printD(print_text, table.unpack(indicators))
end
apply_html("html/convo/text/end.html")
end
@@ -126,7 +177,7 @@ function add_word(str)
end
if add then
table.insert(word_list,str)
if not in_dictionary(str) then io.stderr:write("Error: \""..str.."\" is not known\n") end
if not in_dictionary(str) then printW("\"" .. str .. "\" is not known") end
end
end
@@ -161,9 +212,11 @@ function check_symbol(str)
end
function find_n_replace(str, tbl,find,repl,indicator)
if string.find(str, find) then
str = string.gsub(str,find, repl)
table.insert(tbl,indicator)
if not in_dictionary(str) then
if string.find(str, find) then
str = string.gsub(str,find, repl)
table.insert(tbl,indicator)
end
end
return str, tbl
end
@@ -174,37 +227,75 @@ function in_dictionary(str)
end
end
function check_morphemes(str, tbl,match,repl,indicator)
function categorize_word(str,indicators)
local ind = {}
for _, v in pairs(words) do
if strip_symbols(v[1]) == strip_spaces(str) then
table.insert(ind, string.lower(v[3]))
break
end
end
for _, v in pairs(indicators) do
table.insert(ind, v)
end
return str, ind
end
function check_morphemes(str, tbl,match,repl,indicators)
if type(indicators) ~= "table" then
indicators = {indicators}
end
if not in_dictionary(str) then
local flen = string.len(match)
if string.sub(str, -flen) == match
and string.sub(str,-3) ~= "ton" then
str = string.sub(str, 0,string.len(str)-flen)
table.insert(tbl,indicator)
if string.sub(str, -flen) == match then
str = string.sub(str, 0,string.len(str)-flen) .. repl
if tbl then
for _, v in pairs(indicators) do
table.insert(tbl,v)
end
end
end
end
return str, tbl
end
function revert_nouns(str, tbl)
str, tbl = check_morphemes(str,tbl,"lfur","","formal-n1")
str, tbl = check_morphemes(str,tbl,"lafura","","formal-n2")
str, tbl = check_morphemes(str,tbl,"lan","","genitive")
str, tbl = check_morphemes(str,tbl,"la","","possesive")
str, tbl = check_morphemes(str,tbl,"n","","plural")
str, tbl = check_morphemes(str,tbl,"lfur","","formal1")
str, tbl = check_morphemes(str,tbl,"lafura","","formal2")
str, tbl = check_morphemes(str,tbl,"n","","plural")
return str, tbl
end
function revert_verbs(str, tbl)
str, tbl = find_n_replace(str, tbl,"kanya","ku","present-tense")
str, tbl = find_n_replace(str, tbl,"kome","ku","past-tense")
str, tbl = find_n_replace(str, tbl,"kupash","ku","volitional-mood")
str, tbl = find_n_replace(str, tbl,"kudash","ku","imperative-mood")
str, tbl = find_n_replace(str, tbl,"kubash","ku","shy-mood")
str, tbl = find_n_replace(str, tbl,"kutash","ku","threat-mood")
str, tbl = find_n_replace(str, tbl,"kushu","ku","comfy-mood")
str, tbl = find_n_replace(str, tbl,"kuha","ku","excited-mood")
str, tbl = find_n_replace(str, tbl,"faku","ku","negated")
-- moods first
str, tbl = revert_mood(str, tbl,"pash","","volitional-mood")
str, tbl = revert_mood(str, tbl,"dash","","imperative-mood")
str, tbl = revert_mood(str, tbl,"bash","","shy-mood")
str, tbl = revert_mood(str, tbl,"tash","","threat-mood")
str, tbl = revert_mood(str, tbl,"shu","","comfy-mood")
str, tbl = revert_mood(str, tbl,"ha","","excited-mood")
-- once we've cleaned moods lets try to get tense
str, tbl = check_morphemes(str, tbl,"kanya","ku",{"present-tense-formal","formal-v1"})
str, tbl = check_morphemes(str, tbl,"kome","ku",{"past-tense-formal","formal-v2"})
-- maybe it's informal?
str, tbl = check_morphemes(str, tbl,"nya","",{"present-tense-informal","informal-v1"})
str, tbl = check_morphemes(str, tbl,"me","",{"past-tense-informal","informal-v2"})
for _, v in pairs(tbl) do
if v == "informal-v1"
or v == "informal-v2" then
str = str .. "ku"
end
end
-- negate
str, tbl = check_morphemes(str, tbl,"faku","ku","negated")
return str, tbl
end
function revert_mood(str, tbl,match,repl,indicator)
str, tbl = find_n_replace(str, tbl,"fa"..match,repl,indicator.."-negated")
str, tbl = find_n_replace(str, tbl,match,repl,indicator)
return str, tbl
end
@@ -286,7 +377,7 @@ end
-- lets make the html
apply_html("html/start.html")
-- get text
local file = io.open("input.txt","r")
local file = io.open(input,"r")
local text = file:read("*all")
file:close()