plugged in r2h2

This commit is contained in:
UndeadMaelys 2022-05-04 21:06:53 +02:00
parent 2b3b24a15e
commit 5035a58df2
6 changed files with 359 additions and 146 deletions

241
R2H2.lua Normal file
View File

@ -0,0 +1,241 @@
--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"}
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
-- evaluate conditions that cancel the script
if text == "" then
step = false
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 string.sub(text,i,i) == " "
or 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) == "." then -- this forces the new syllable, since . is the syllable separator, also skips the symbol and repositions
-- 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 .. "?"
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

View File

@ -1,6 +1,7 @@
require "R2H2"
function strip_symbols(str)
local symbol_table = " ~()!?:></.\t"
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),"")
@ -72,13 +73,16 @@ while p ~= nil do
convo_end()
elseif string.sub(text,p+1,p+1) == "\t" then
-- its tabbed so its spoken?
convo_start()
apply_html("html/convo/text/start.html")
convo_start(
)
apply_html("html/convo/text/start_roman.html")
print(string.sub(text,p+2,np-1))
content = content .. " " .. reverse_verbs(strip_symbols(string.sub(text,p+2,np-1)))
--content = content .. " " .. reverse_verbs(strip_symbols(string.sub(text,p+2,np-1)))
--print("\n"..reverse_verbs(strip_symbols(string.sub(text,p+2,np-1))))
apply_html("html/convo/text/end.html")
apply_html("html/convo/text/start.html")
print("\n"..reverse_verbs(strip_symbols(string.sub(text,p+2,np-1))))
-- heonian
apply_html("html/convo/text/start_heonian.html")
print(convertToHeonian(strip_symbols(string.sub(text,p+2,np-1))))
apply_html("html/convo/text/end.html")
else
-- new user name

View File

@ -1 +0,0 @@
<p>

View File

@ -0,0 +1 @@
<p class="convo-heonian">

View File

@ -0,0 +1 @@
<p class="convo_roman">

245
test.html
View File

@ -8,6 +8,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<main>
<div class="convo-container">
<div class="convo">
<div class="convo-header">
@ -15,12 +17,11 @@
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
nyanpash! balfur yu e she polika'nya dre?
</p>
<p>
nyanpash balfur yu e she polika'nya dre
<p class="convo-heonian">

</p>
</div>
</div>
@ -31,19 +32,17 @@ nyanpash balfur yu e she polika'nya dre
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
re chu meshu yu polika'nya
</p>
<p>
re chu meshu yu polika'nya
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
(po'nyash!!!)
</p>
<p>
po'nyash
<p class="convo-heonian">

</p>
</div>
</div>
@ -54,19 +53,17 @@ po'nyash
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
aa, anko!
</p>
<p>
aa, anko
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
(po'nyash!)
</p>
<p>
po'nyash
<p class="convo-heonian">

</p>
</div>
</div>
@ -77,19 +74,17 @@ po'nyash
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
ba yu e wawote to pu mipura lili'nya dre?
</p>
<p>
ba yu e wawote to pu mipura lili'nya dre
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
uwu
</p>
<p>
uwu
<p class="convo-heonian">

</p>
</div>
</div>
@ -100,12 +95,11 @@ uwu
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
relfur chu mya pu yu mya relfur lup apatkanya fakanyapash ponme mya wawote polikanya peekakanyapash.
</p>
<p>
relfur chu mya pu yu mya relfur lup apatkanya fakanyapash ponme mya wawote polikanya peekakanyapash
<p class="convo-heonian">

</p>
</div>
</div>
@ -116,19 +110,17 @@ relfur chu mya pu yu mya relfur lup apatkanya fakanyapash ponme mya waw
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
mishipash~
</p>
<p>
mishipash
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
balfur yu e ton polikanya dre?
</p>
<p>
balfur yu e ton polikanya dre
<p class="convo-heonian">

</p>
</div>
</div>
@ -139,26 +131,23 @@ balfur yu e ton polikanya dre
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
mishipash!!
</p>
<p>
mishipash
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
relfurla mya ton polika'nya yu meluton kanya!
</p>
<p>
relfurla mya ton polika'nya yu meluton kanya
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
balfurla yu dra?
</p>
<p>
balfurla yu dra
<p class="convo-heonian">

</p>
</div>
</div>
@ -169,19 +158,17 @@ balfurla yu dra
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
relfurla yu eshdre mya ton polikanya yu puroton kanya~
</p>
<p>
relfurla yu eshdre mya ton polikanya yu puroton kanya
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
relfur yu shirobaepu yu ponya kanya~
</p>
<p>
relfur yu shirobaepu yu ponya kanya
<p class="convo-heonian">

</p>
</div>
</div>
@ -192,12 +179,11 @@ relfur yu shirobaepu yu ponya kanya
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
puroton yu ponya ton kanya!
</p>
<p>
puroton yu ponya ton kanya
<p class="convo-heonian">

</p>
</div>
</div>
@ -208,19 +194,17 @@ puroton yu ponya ton kanya
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
benyui-rerenlafura yu meluton mimifakanya…
</p>
<p>
benyui-rerenlafura yu meluton mimifakanya…
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
relfur yu meluton mimiku'pash~
</p>
<p>
relfur yu meluton mimiku'pash
<p class="convo-heonian">

</p>
</div>
</div>
@ -231,19 +215,17 @@ relfur yu meluton mimiku'pash
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
o, relfur chu parefakanya…
</p>
<p>
o, relfur chu parefakanya…
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
benyui-babanlafura yu meluton naomiminku dre?
</p>
<p>
benyui-babanlafura yu meluton naomiminku dre
<p class="convo-heonian">

</p>
</div>
</div>
@ -254,26 +236,23 @@ benyui-babanlafura yu meluton naomiminku dre
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
uu, relfur yu naomiminku mya mimifuku mya ton kanya...
</p>
<p>
uu, relfur yu naomiminku mya mimifuku mya ton kanya
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
relfur yu guraton to meluton mimifuku..
</p>
<p>
relfur yu guraton to meluton mimifuku
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
relfur yu ton mimikupash~
</p>
<p>
relfur yu ton mimikupash
<p class="convo-heonian">

</p>
</div>
</div>
@ -284,19 +263,17 @@ relfur yu ton mimikupash
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
ishi-balfur yu mishi'pash!
</p>
<p>
ishi-balfur yu mishi'pash
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
balfur chu mya arilaen yu en kanya peekakanya fa'dre?
</p>
<p>
balfur chu mya arilaen yu en kanya peekakanya fa'dre
<p class="convo-heonian">

</p>
</div>
</div>
@ -307,26 +284,23 @@ balfur chu mya arilaen yu en kanya peekakanya fa'dre
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
yesh-balfur yu mishi'pash~
</p>
<p>
yesh-balfur yu mishi'pash
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
(>///////////////<)
</p>
<p>
<p class="convo-heonian">
</p>
<p>
<p class="convo_roman">
relfur yu arilaen parefakanya, balfur yu parekanya dra?
</p>
<p>
relfur yu arilaen parefakanya, balfur yu parekanya dra
<p class="convo-heonian">

</p>
</div>
</div>
@ -337,37 +311,33 @@ relfur yu arilaen parefakanya, balfur yu parekanya dra
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
relfur chu arilaen dedakanya.
</p>
<p>
relfur chu arilaen dedakanya
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
imanla rila shashkanyapash.
</p>
<p>
imanla rila shashkanyapash
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
imanla shoo chu ike to pikeshe kanya.
</p>
<p>
imanla shoo chu ike to pikeshe kanya
<p class="convo-heonian">

</p>
</div>
</div>
<div class="convo-container">
<div class="convo">
<p>
<p class="convo_roman">
relfur chu arilaenlan lukanyapash.
</p>
<p>
relfur chu arilaenlan lukanyapash
<p class="convo-heonian">

</p>
</div>
</div>
@ -378,12 +348,11 @@ relfur chu arilaenlan lukanyapash
ESH'NYUI
</span>
</div>
<p>
<p class="convo_roman">
arilaenla shoo chu pikeshe fukanyabash dra?
</p>
<p>
arilaenla shoo chu pikeshe fukanyabash dra
<p class="convo-heonian">

</p>
</div>
</div>
@ -394,19 +363,17 @@ arilaenla shoo chu pikeshe fukanyabash dra
LU'NYA
</span>
</div>
<p>
<p class="convo_roman">
gao chu relfur yu fayu kanya.
</p>
<p>
gao chu relfur yu fayu kanya
<p class="convo-heonian">

</p>
<p>
<p class="convo_roman">
relfur chu arilaen dedakanya.
</p>
<p>
relfur chu arilaen dedakanya
<p class="convo-heonian">

</p>
</div>
</div>