diff --git a/color.lua b/color.lua new file mode 100644 index 0000000..06596e1 --- /dev/null +++ b/color.lua @@ -0,0 +1,85 @@ +function Enum(tbl) + for i = 1, #tbl do + local v = tbl[i] + tbl[v] = i + end + return tbl +end + +COLOR = Enum { + "Black", + "Red", + "Green", + "Yellow", + "Blue", + "Purple", + "Cyan", + "LightGray", + "Gray", + "HighRed", + "HighGreen", + "HighYellow", + "HighBlue", + "HighPurple", + "HighCyan", + "White" +} + +EFFECT = Enum { + "Normal", + "Bold", + "Dim", + "Italic", + "Underline", + "BlinkSlow", + "BlinkFast", + "Invert", + "Conceal", + "CrossedOut" +} + +function effectText(Effect, ...) + local Text = "" + local tab = false + for _, v in pairs({...}) do + if not tab then + tab = true + else + Text = Text .. "\t" + end + Text = Text .. v + end + return "\027["..tostring(Effect-1).."m"..Text.."\027[0;m" +end + +function colorText(Color, ...) + local Text = "" + local tab = false + for _, v in pairs({...}) do + if not tab then + tab = true + else + Text = Text .. "\t" + end + Text = Text .. v + end + return "\027[38;5;"..tostring(Color-1).."m"..Text.."\027[0;m" +end + +function colorTextBackground(Color, ...) + local Text = "" + local tab = false + for _, v in pairs({...}) do + if not tab then + tab = true + else + Text = Text .. "\t" + end + Text = Text .. v + end + return "\027[48;5;"..tostring(Color-1).."m"..Text.."\027[0;m" +end + +function scrollTerminalUp(amount) + return "\027["..amount.."T" +end diff --git a/converter.lua b/converter.lua index 32cb9b7..3df16f0 100644 --- a/converter.lua +++ b/converter.lua @@ -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() diff --git a/html/pop_up.html b/html/pop_up.html index 4f73034..eb24c0e 100644 --- a/html/pop_up.html +++ b/html/pop_up.html @@ -4,7 +4,6 @@
nyan'pash! balfur yu e she polika'nya @@ -113,48 +113,48 @@ LU'NYA
! @@ -189,40 +189,40 @@ ESH'NYUI
re chu meshu yu polika'nya @@ -231,40 +231,40 @@ ESH'NYUI
@@ -311,16 +311,16 @@ LU'NYA
aa, anko! @@ -329,16 +329,16 @@ LU'NYA
, ! @@ -385,48 +385,48 @@ ESH'NYUI
ba yu e wawote to pu @@ -441,8 +441,8 @@ ESH'NYUI lili'nya @@ -459,48 +459,48 @@ ESH'NYUI
@@ -515,8 +515,8 @@ ESH'NYUI @@ -554,120 +554,120 @@ LU'NYA
relfur chu mya pu yu mya relfur lup apatka'nya faka'nya'pash ponme mya wawote polika'nya peekaka'nya'pash. @@ -676,120 +676,120 @@ LU'NYA
@@ -816,8 +816,8 @@ ESH'NYUI
mi'shi'pashshu @@ -826,8 +826,8 @@ ESH'NYUI
@@ -836,40 +836,40 @@ ESH'NYUI
balfur yu e ton polika'nya @@ -886,40 +886,40 @@ ESH'NYUI
@@ -954,8 +954,8 @@ LU'NYA
mishi'pash!! @@ -964,8 +964,8 @@ LU'NYA
!! @@ -974,56 +974,56 @@ LU'NYA
relfurla mya ton polika'nya yu meluton ka'nya! @@ -1032,56 +1032,56 @@ LU'NYA
! @@ -1090,24 +1090,24 @@ LU'NYA
balfurla yu dra? @@ -1116,24 +1116,24 @@ LU'NYA
? @@ -1160,72 +1160,72 @@ ESH'NYUI
relfurla yu esh'dre mya ton polika'nya yu puroton ka'nyashu @@ -1234,72 +1234,72 @@ ESH'NYUI
@@ -1308,48 +1308,48 @@ ESH'NYUI
relfur yu shi'ro'bae'pu yu pon'ya ka'nyashu @@ -1358,48 +1358,48 @@ ESH'NYUI
@@ -1426,40 +1426,40 @@ LU'NYA
puroton yu ponya ton ka'nya! @@ -1468,40 +1468,40 @@ LU'NYA
! @@ -1528,40 +1528,40 @@ ESH'NYUI
be'nyui rerenlafura yu meluton mimifaka'nya… @@ -1570,40 +1570,40 @@ ESH'NYUI
… @@ -1612,32 +1612,32 @@ ESH'NYUI
relfur yu meluton mimiku'pashshu @@ -1646,32 +1646,32 @@ ESH'NYUI
@@ -1706,24 +1706,24 @@ LU'NYA relfur chu parefaka'nya… @@ -1740,24 +1740,24 @@ LU'NYA … @@ -1766,40 +1766,40 @@ LU'NYA
be'nyui babanlafura yu meluton naomiminku @@ -1816,40 +1816,40 @@ LU'NYA
@@ -1884,40 +1884,40 @@ ESH'NYUI
uu, relfur yu naomiminku mya @@ -1932,24 +1932,24 @@ ESH'NYUI mya ton ka'nya... @@ -1958,40 +1958,40 @@ ESH'NYUI
, @@ -2006,24 +2006,24 @@ ESH'NYUI . @@ -2032,40 +2032,40 @@ ESH'NYUI
relfur yu guraton to meluton @@ -2082,40 +2082,40 @@ ESH'NYUI
@@ -2132,32 +2132,32 @@ ESH'NYUI
relfur yu ton mimiku'pashshu @@ -2166,32 +2166,32 @@ ESH'NYUI
@@ -2218,32 +2218,32 @@ LU'NYA
ishi balfur yu mishi'pash! @@ -2252,32 +2252,32 @@ LU'NYA
! @@ -2286,64 +2286,64 @@ LU'NYA
balfur chu mya arilaen yu en ka'nya peekaka'nya @@ -2360,64 +2360,64 @@ LU'NYA
@@ -2452,32 +2452,32 @@ ESH'NYUI
yesh balfur yu mishi'pashshu @@ -2486,32 +2486,32 @@ ESH'NYUI
@@ -2540,64 +2540,64 @@ ESH'NYUI
relfur yu ari'laen parefaka'nya, balfur yu pareka'nya dra? @@ -2606,64 +2606,64 @@ ESH'NYUI
, ? @@ -2690,32 +2690,32 @@ LU'NYA
relfur chu arilaen dedaka'nya. @@ -2724,32 +2724,32 @@ LU'NYA
@@ -2758,24 +2758,24 @@ LU'NYA
imanla rila shashka'nya'pash. @@ -2784,24 +2784,24 @@ LU'NYA
@@ -2810,56 +2810,56 @@ LU'NYA
imanla shoo chu ike to pikeshe ka'nya. @@ -2868,56 +2868,56 @@ LU'NYA
@@ -2930,32 +2930,32 @@ LU'NYA
relfur chu arilaenlan luka'nya'pash. @@ -2964,32 +2964,32 @@ LU'NYA
@@ -3016,48 +3016,48 @@ ESH'NYUI
arilaenla shoo chu pikeshe fuka'nya'bash dra? @@ -3066,48 +3066,48 @@ ESH'NYUI
? @@ -3134,32 +3134,32 @@ LU'NYA
gao chu relfur yu @@ -3174,8 +3174,8 @@ LU'NYA kan'ya. @@ -3184,32 +3184,32 @@ LU'NYA
@@ -3224,8 +3224,8 @@ LU'NYA @@ -3234,32 +3234,32 @@ LU'NYA
relfur chu arilaen dedaka'nya. @@ -3268,32 +3268,32 @@ LU'NYA
@@ -3444,16 +3444,16 @@ denotes the subject