Compare commits
3 Commits
2faca4b4bd
...
6d7ae9cefd
Author | SHA1 | Date | |
---|---|---|---|
|
6d7ae9cefd | ||
|
5b3a9555d1 | ||
|
0beb347849 |
244
R2H2.lua
244
R2H2.lua
@ -1,244 +0,0 @@
|
||||
--functions
|
||||
function CopyToClipboard(textString)
|
||||
outClipFile, err = io.open("clipboardTempFile",'w')
|
||||
if err then
|
||||
print("[Error Opening Clipboard Temporary File for Writing]")
|
||||
return
|
||||
end
|
||||
outClipFile:write(textString,'\n')
|
||||
outClipFile:close()
|
||||
command = 'cat "' .. "clipboardTempFile" .. '" | xclip -selection clipboard &'
|
||||
os.execute(command)
|
||||
os.execute("rm clipboardTempFile")
|
||||
end
|
||||
|
||||
function PrintPosition(string)
|
||||
local print_text = ""
|
||||
for i = 1, string.len(string) do
|
||||
while i >= 10 do i = i - 10 end
|
||||
print_text = print_text .. tostring(i)
|
||||
end
|
||||
print("pos: " .. print_text)
|
||||
print_text = ""
|
||||
for i = 1, string.len(string) do
|
||||
i = math.floor(i/10)
|
||||
while i >= 10 do i = i - 10 end
|
||||
if i == 0 then i = " " end
|
||||
print_text = print_text .. tostring(i)
|
||||
end
|
||||
print(" " ..print_text)
|
||||
end
|
||||
|
||||
-- DATA
|
||||
-- vowels
|
||||
vowel_table = {"a","e","i","o","u"}
|
||||
symbol_vowel = {"","","","",""}
|
||||
symbol_extending_vowel = {"","","","",""}
|
||||
-- consonants
|
||||
consonant_table = {"g","sh","r","ny","ch","n","y","f","t","k","w","l","p","b","d","h","m"}
|
||||
symbol_consonant = {"","","","","","","","","","","","","","","","",""}
|
||||
symbol_extending_consonant = {"","","","","","","","","","","","","","","","",""}
|
||||
-- composites
|
||||
composing_consonant_table = {"g","sh","r","ny","ch","m","y","f","t","k","w","l","p","b","d","h"}
|
||||
symbol_composite = {
|
||||
{"","","","","","","","","","","","","","","",""},
|
||||
{"","","","","","","","","","","","","","","",""},
|
||||
{"","","","","","","","","","","","","","","",""},
|
||||
{"","","","","","","","","","","","","","","",""},
|
||||
{"","","","","","","","","","","","","","","",""}
|
||||
}
|
||||
|
||||
-- program start
|
||||
function convertToHeonian(text)
|
||||
local step = true -- this is set to false when a conclusion has been reached
|
||||
local transcribed = false
|
||||
local transcribed_text = ""
|
||||
|
||||
local debug = false
|
||||
local autocopy = false
|
||||
|
||||
for _, v in pairs(arg) do
|
||||
if v == "-v" or v == "--verbose" then debug = true end
|
||||
if v == "-c" or v == "--copy" then autocopy = true end
|
||||
end
|
||||
|
||||
-- if its necessary to run the script, then we continue :D
|
||||
if step then
|
||||
-- prepare text
|
||||
-- 1. add syllable marker at start if it isn't already present.
|
||||
if string.sub(text,1,1) ~= "." then text = "." .. text end
|
||||
-- 2. turn [x] into [ksh]
|
||||
text = string.gsub(text,"x","ksh")
|
||||
-- 3. turn [z] into [dsh]
|
||||
text = string.gsub(text,"z","d.sh")
|
||||
-- 4. turn [j] into [y]
|
||||
text = string.gsub(text,"j","y")
|
||||
|
||||
-- read input and transcribe
|
||||
-- debug log
|
||||
if debug then print("") end
|
||||
if debug then print("src: ".. text) end
|
||||
if debug then PrintPosition(text) end
|
||||
|
||||
-- sort through all the letters
|
||||
local i = 1
|
||||
while i < string.len(text)+1 do
|
||||
local pos = i
|
||||
-- know current pos, since we will be modifying i but still evaluating from the position
|
||||
local char_step = true
|
||||
-- this is false when a conclusion has been reached about what symbol does the next segment correspond to
|
||||
local debug_s = ""
|
||||
-- debug string
|
||||
local new_syllable = false
|
||||
-- this is true when a new syllable begins, and is used to distinguish normal vowels and consonants from trailing ones
|
||||
|
||||
if i == 1 then new_syllable = true end
|
||||
|
||||
if string.sub(text,i,i) == "\t"
|
||||
or string.sub(text,i,i) == "-" then -- check if its an unsupported symbol to skip it.
|
||||
-- adjust i
|
||||
i = i + 1
|
||||
pos = i
|
||||
char_step = false
|
||||
end
|
||||
-- init checkup
|
||||
if string.sub(text,i,i) == "."
|
||||
or string.sub(text,i,i) == "'"
|
||||
or string.sub(text,i,i) == " "
|
||||
or string.sub(text,i,i) == "’" then -- this forces the new syllable, since . is the syllable separator, also skips the symbol and repositions
|
||||
if string.sub(text,i,i) == " " then -- spaces are exception
|
||||
transcribed_text = transcribed_text .. " "
|
||||
new_syllable = true
|
||||
end
|
||||
-- debug log
|
||||
if debug then print("") end
|
||||
if debug then print(" @[".. tostring(i).."]"..debug_s.." new syllable MARKER found") end
|
||||
-- start syllable
|
||||
new_syllable = true
|
||||
debug_s = ""
|
||||
-- adjust i
|
||||
i = i + 1
|
||||
-- debug log
|
||||
if debug then print(" >>> adjusting by (1) from [".. pos .. "] to [".. i .. "]" ) end
|
||||
-- adjust pos
|
||||
pos = i
|
||||
end
|
||||
|
||||
-- debug log
|
||||
if debug then print("") end
|
||||
if debug then print(" @[".. tostring(i).."]"..debug_s.." checking string: ".. string.sub(text,i,i)) end -- debug print positional info
|
||||
|
||||
-- lets check if it is a composite
|
||||
if char_step == true then
|
||||
local cons_id = 0
|
||||
local length = 0
|
||||
-- check if its valid consonant for a composite
|
||||
for _, consonant in pairs(composing_consonant_table) do
|
||||
cons_id = cons_id + 1
|
||||
-- get consonant length its checking against, so we can properly compare.
|
||||
length = string.len(consonant)
|
||||
-- debug log
|
||||
--if debug then print(" checking composite consonant: " .. composing_consonant_table[cons_id]) end
|
||||
if string.sub(text,i,i+length-1) == consonant then
|
||||
-- debug log
|
||||
if debug then print(" (!) valid consonant: " .. composing_consonant_table[cons_id]) end
|
||||
-- check if its a valid vowel AFTER the valid consonant, while sorting through all vowels
|
||||
local vowel_id = 0
|
||||
for _, vowel in pairs(vowel_table) do
|
||||
vowel_id = vowel_id + 1
|
||||
--if debug then print(" checking composite: " .. composing_consonant_table[cons_id]..vowel_table[vowel_id]) end
|
||||
if string.sub(text,i+length,i+length) == vowel then
|
||||
-- adjust by consonant length + vowel
|
||||
i = i + string.len(consonant) + 1
|
||||
-- debug log
|
||||
if debug then print(" (!) valid composite: " .. consonant .. vowel ..", length: "..length+1) end
|
||||
if debug then print(" >>> adjusting by (" .. tostring(length+1) .. ") from [".. pos .. "] to [".. i .. "]" ) end
|
||||
-- transcribe; conclude;
|
||||
transcribed_text = transcribed_text .. symbol_composite[vowel_id][cons_id]
|
||||
char_step = false
|
||||
break
|
||||
end
|
||||
end
|
||||
-- no need to check for more consonants if one is valid
|
||||
break
|
||||
end
|
||||
end
|
||||
if debug then if char_step ~= false then print(" [!] invalid composite") end end
|
||||
end
|
||||
|
||||
-- lets check if it is a non composite vowel
|
||||
if char_step == true then
|
||||
local id = 0
|
||||
local length = 0
|
||||
for _, vowel in pairs(vowel_table) do
|
||||
id = id+ 1
|
||||
-- get vowel length its checking against, so we can properly compare.
|
||||
length = string.len(vowel)
|
||||
-- debug log
|
||||
--if debug then print(" checking standalone vowel: " .. vowel_table[id]) end
|
||||
if string.sub(text,i,i+length-1) == vowel then
|
||||
i = i + string.len(vowel)
|
||||
-- debug log
|
||||
if debug then print(" (!) valid vowel: " .. vowel_table[id]) end
|
||||
if debug then print(" >>> adjusting by (" .. tostring(length) .. ") from [".. pos .. "] to [".. i .. "]" ) end
|
||||
-- transcribe; conclude;
|
||||
local table = nil
|
||||
if new_syllable then
|
||||
table = symbol_vowel
|
||||
else
|
||||
table = symbol_extending_vowel
|
||||
end
|
||||
transcribed_text = transcribed_text .. table[id]
|
||||
char_step = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- lets check if it is a non composite consonant
|
||||
if char_step == true then
|
||||
local id = 0
|
||||
local length = 0
|
||||
for _, consonant in pairs(consonant_table) do
|
||||
id = id+ 1
|
||||
-- get consonant length its checking against, so we can properly compare.
|
||||
length = string.len(consonant)
|
||||
-- debug log
|
||||
--if debug then print(" checking standalone consonant: " .. consonant_table[id]) end
|
||||
if string.sub(text,i,i+length-1) == consonant then
|
||||
i = i + string.len(consonant)
|
||||
-- debug log
|
||||
if debug then print(" (!) valid consonant: " .. consonant_table[id]) end
|
||||
if debug then print(" >>> adjusting by (" .. tostring(length) .. ") from [".. pos .. "] to [".. i .. "]" ) end
|
||||
-- transcribe; conclude;
|
||||
local table = nil
|
||||
if new_syllable then
|
||||
table = symbol_consonant
|
||||
else
|
||||
table = symbol_extending_consonant
|
||||
end
|
||||
transcribed_text = transcribed_text .. table[id]
|
||||
char_step = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- if no idea, move on, and just be confused. prints ?
|
||||
if char_step == true then
|
||||
-- debug log
|
||||
if debug then print(" [!] no idea; moving on to next [".. pos + 1 .."]") end
|
||||
-- no idea
|
||||
transcribed_text = transcribed_text .. string.sub(text,i,i)
|
||||
i = i + 1
|
||||
-- debug log
|
||||
if debug then print(" >>> adjusting by (1) from [".. pos .. "] to [".. i .. "]" ) end
|
||||
end
|
||||
end
|
||||
|
||||
-- output
|
||||
if autocopy then CopyToClipboard(string.sub(transcribed_text,0,-1)) end
|
||||
return transcribed_text
|
||||
end
|
||||
end
|
@ -17,9 +17,9 @@ function process_content(content)
|
||||
|
||||
end
|
||||
|
||||
local ac = content
|
||||
local ac = check_symbol(content)
|
||||
while string.find(ac, " ") do
|
||||
local new_word = string.sub(ac, 0, string.find(ac, " "))
|
||||
local new_word = string.sub(ac, 0, string.find(ac, " ")-1)
|
||||
local indicators = {}
|
||||
|
||||
if i == 1 then
|
||||
@ -29,8 +29,8 @@ function process_content(content)
|
||||
end
|
||||
|
||||
new_word = strip_symbols(new_word)
|
||||
new_word = replace_symbols(new_word)
|
||||
new_word, indicators = revert_verbs(new_word, indicators)
|
||||
new_word, indicators = revert_nouns(new_word,indicators)
|
||||
add_word(new_word)
|
||||
|
||||
local html_stuff = [[
|
||||
@ -146,28 +146,62 @@ function strip_symbols(str)
|
||||
return str
|
||||
end
|
||||
|
||||
function replace_symbols(str)
|
||||
function replace_sign(str)
|
||||
while string.find(str, "%-") do
|
||||
str = string.gsub(str, "%-"," ")
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
function check_symbol(str)
|
||||
if not in_dictionary(str) then
|
||||
return replace_sign(str)
|
||||
end
|
||||
end
|
||||
|
||||
function find_n_replace(str, tbl,find,repl,indicator)
|
||||
if string.find(str, find) then
|
||||
str = string.gsub(str, find, repl)
|
||||
str = string.gsub(str,find, repl)
|
||||
table.insert(tbl,indicator)
|
||||
end
|
||||
return str, tbl
|
||||
end
|
||||
|
||||
function in_dictionary(str)
|
||||
for i=1, #words do
|
||||
if words[i][1] == str then return true end
|
||||
end
|
||||
end
|
||||
|
||||
function check_morphemes(str, tbl,match,repl,indicator)
|
||||
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)
|
||||
end
|
||||
end
|
||||
return str, tbl
|
||||
end
|
||||
|
||||
function revert_nouns(str, tbl)
|
||||
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","","formal")
|
||||
str, tbl = check_morphemes(str,tbl,"lafura","","formal")
|
||||
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,"faku","ku","negated")
|
||||
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,"faku","ku","negated")
|
||||
return str, tbl
|
||||
end
|
||||
|
||||
|
@ -14,7 +14,7 @@ LU'NYA
|
||||
|
||||
ESH'NYUI
|
||||
ba yu e wawote to pu mipura lili'nya dre?
|
||||
uwu
|
||||
r uwu
|
||||
|
||||
LU'NYA
|
||||
relfur chu mya pu yu mya relfur lup apatka'nya faka'nya'pash ponme mya wawote polika'nya peekaka'nya'pash.
|
||||
|
Loading…
Reference in New Issue
Block a user