added a way to edit, remove, and add words

This commit is contained in:
UndeadMaelys 2022-03-24 21:47:24 +01:00
parent 39335c7e09
commit 93da415c03
9 changed files with 396 additions and 177 deletions

View File

@ -1,44 +1,45 @@
return function(query) function addWord()
results_table = {} number = tonumber(number)
for i=1, #words do -- open file
local exit = true local file = io.open(data_get, "r")
local all = true local pos = 0
for _, v in pairs(arg) do
if v == "-r" or v == "--raw" then -- get insertion point
all = false pos = file:seek("end",-9)
word = string.gsub(words[i][1],"%p","") -- store after
if string.find(word, query) then local after = file:read("*all")
exit = false
break -- store before
end file:seek("set")
end local before = file:read(pos-1)
if v == "-e" or v == "--english" then
all = false -- done reading
word = string.gsub(words[i][2],"%p","") file:close()
if string.find(word, query) then
exit = false modify = {}
break print("insert new phonetics:")
end modify[1] = io.read()
end print("insert new meaning:")
end modify[2] = io.read()
if all == true then print("insert new type:")
for j=1, #words[i]-1 do modify[3] = io.read()
word = string.gsub(words[i][j],"%p","") print("insert new canon origin:")
if string.find(word, query) then modify[4] = io.read()
exit = false print("insert new meta origin:")
break modify[5] = io.read()
end print("insert new notes:")
end modify[6] = io.read()
end
if not exit then local file = io.open(data_output, "w+")
local word = {i,words[i]} file:write(before)
table.insert(results_table,word) file:write("\ntable.insert(t,{\"")
end for i=1, #modify do
end if i > 1 then
if #results_table ~= 0 then file:write("\",\"")
results_table = adjustTableSizes(results_table) end
printOutputTable(results_table) file:write(modify[i])
else end
print("no words found for <" .. query .. ">") file:write("\"})\n")
end file:write(after)
file:close()
end end

143
edit_word.lua Normal file
View File

@ -0,0 +1,143 @@
function editWord(number)
number = tonumber(number)
-- determine modifications
local modify_all = true
local reenable_modify_all = false
local mph = false
local mm = false
local mt = false
local mco = false
local mmo = false
local mn = false
for _, v in pairs(arg) do
if v == "--modify-phonetics"
or v == "-mph" then
modify_all = false
mph = true
end
if v == "--modify-meaning"
or v == "-mm" then
modify_all = false
mm = true
end
if v == "--modify-type"
or v == "-mt" then
modify_all = false
mt = true
end
if v == "--modify-canon-origin"
or v == "-mco" then
modify_all = false
mco = true
end
if v == "--modify-meta-origin"
or v == "-mmo" then
modify_all = false
mmo = true
end
if v == "--modify-notes"
or v == "-mn" then
modify_all = false
mn = true
end
if v == "--modify-all"
or v == "-ma" then
reenable_modify_all = true
end
end
if reenable_modify_all then
modify_all = true
end
-- open file
local file = io.open(data_get, "r")
local text = file:read("*all")
local pos = 0
-- move to line
for i=1, number do
local npos = string.find(text,"\n",pos+1)
if npos == nil then break end
pos = npos
end
file:seek("set",0)
local before = file:read(pos)
file:seek("set",pos)
-- move to things to modify
pos = string.find(text,"{\"",pos)+1
file:seek("set",pos)
modify = {}
for i=1, 6 do
-- find next "
length = string.find(text,"\"",pos+1)-pos
table.insert(modify,file:read(length-1))
if i < 6 then
pos = string.find(text,"\"",pos+length+1)
end
file:seek("set",pos)
end
file:seek("set",string.find(text,"})",pos+length+1)+1)
local after = file:read("*all") or ""
file:close()
print("FILE:")
print(" phonetics",modify[1])
print(" meaning",modify[2])
print(" type",modify[3])
print(" canon origin",modify[4])
print(" meta origin",modify[5])
print(" notes",modify[6])
print("")
if modify_all or mph then
print("insert new phonetics:")
modify[1] = io.read()
end
if modify_all or mm then
print("insert new meaning:")
modify[2] = io.read()
end
if modify_all or mt then
print("insert new type:")
modify[3] = io.read()
end
if modify_all or mco then
print("insert new canon origin:")
modify[4] = io.read()
end
if modify_all or mmo then
print("insert new meta origin:")
modify[5] = io.read()
end
if modify_all or mn then
print("insert new notes:")
modify[6] = io.read()
end
print("NEW:")
print(" phonetics",modify[1])
print(" meaning",modify[2])
print(" type",modify[3])
print(" canon origin",modify[4])
print(" meta origin",modify[5])
print(" notes",modify[6])
--rewrite with new info
local file = io.open(data_output, "w+")
file:write(before)
file:write("table.insert(t,{\"")
for i=1, #modify do
if i > 1 then
file:write("\",\"")
end
file:write(modify[i])
end
file:write("\"})")
file:write(after)
file:close()
end

83
lexicon
View File

@ -6,15 +6,19 @@ require "R2H2"
require "color" require "color"
adjustTableSizes = require "output_sizes" require "output_sizes"
printOutputTable = require "output_word" require "output_word"
showList = require "show_list" require "show_list"
searchList = require "search_list" require "search_list"
removeWord = require "remove_word" require "remove_word"
addWord = require "add_word" require "add_word"
require "edit_word"
words = dofile("words.lua") data_get = "words.lua"
data_output = "words.lua"
words = dofile(data_get)
for _, v in pairs(arg) do for _, v in pairs(arg) do
if v == "-h" if v == "-h"
@ -32,25 +36,29 @@ or arg[1] == "how"
or arg[1] == "howdo" then or arg[1] == "howdo" then
print([[ print([[
[l]ist [e]dit <word_id>
- shows all words in heonian. - removes the word from the lexicon
[h]elp [h]elp
- shows this message - shows this message
[l]ist
- shows all words in heonian.
[n]ew
- add new word to the data
[r]emove <word_id>
- removes the word from the lexicon
[s]earch <query> [s]earch <query>
- searches all words and shows only those that return to string.find() - searches all words and shows only those that return to string.find()
[tr]anscript <word> [tr]anscript <word>
- transcripts the word to heonian script - transcripts the word to heonian script
Parameters: General parameters:
-a / --all (shows more info on the word, if any)
-c / --copy (copies transcription to keyboard)
-e / --english (limits the search to the translated words)
-h / --help (shows what does the command do) -h / --help (shows what does the command do)
-r / --raw (limits the search to the heonian words)
-v / --verbose (shows the transcription process)
]]) ]])
return return
end end
@ -124,26 +132,57 @@ Parameters:
-h / --help (shows what does the command do) -h / --help (shows what does the command do)
]]) ]])
else else
if arg[2] then removeWord(arg[2]) if arg[2]
and tonumber(arg[2]) <= #words
and tonumber(arg[2]) > 0 then
removeWord(arg[2])
else print("no word to remove") end else print("no word to remove") end
return return
end end
end end
if arg[1] == "a" if arg[1] == "n"
or arg[1] == "remove" then or arg[1] == "new" then
if please_help then if please_help then
print([[ print([[
[r]emove <word_id> [n]ew
- removes the word from the lexicon - add new word to the data
Parameters: Parameters:
-h / --help (shows what does the command do) -h / --help (shows what does the command do)
]]) ]])
else else
if arg[2] then addWord(...) addWord()
else print("no word to add") end end
end
if arg[1] == "e"
or arg[1] == "edit" then
if please_help then
print([[
[e]dit <word_id>
- removes the word from the lexicon
Parameters:
-h / --help / (shows what does the command do)
-mph / --modify-phonetics / edit the phonetics field
-mm / --modify-meaning / edit the meaning field
-mt / --modify-type / edit the type field
-mco / --modify-canon-origin / edit the canon origin field
-mmo / --modify-meta-origin / edit the meta origin field
-mn / --modify-notes / edit the notes field
-ma / --modify-all / edit all the fields
(-ma is enabled by default, disabled if other flags)
]])
else
if arg[2]
and tonumber(arg[2]) <= #words
and tonumber(arg[2]) > 0 then
editWord(arg[2])
else print("no word to edit") end
return return
end end
end end

View File

@ -1,4 +1,4 @@
return function(tbl) function adjustTableSizes(tbl)
local words_max_length = {1,1,1,1,1,1} local words_max_length = {1,1,1,1,1,1}
for i=1, #tbl do for i=1, #tbl do

View File

@ -1,10 +1,14 @@
return function(tbl) function printOutputTable(tbl,all)
local show_all = false local show_all = false
for _, v in pairs(arg) do for _, v in pairs(arg) do
if v == "-a" or v == "--all" then show_all = true end if v == "-a" or v == "--all" then show_all = true end
end end
if all then
show_all = true
end
for i=1, #tbl do for i=1, #tbl do
local this_number = tbl[i][1] local this_number = tbl[i][1]
local this_word = tbl[i][2] local this_word = tbl[i][2]

View File

@ -1,44 +1,76 @@
return function(query) function removeWord(number)
results_table = {} number = tonumber(number)
for i=1, #words do
local exit = true local file = io.open(data_get, "r")
local all = true local text = file:read("*all")
for _, v in pairs(arg) do local pos = 0
if v == "-r" or v == "--raw" then -- move to line
all = false for i=1, number do
word = string.gsub(words[i][1],"%p","") local npos = string.find(text,"\n",pos+1)
if string.find(word, query) then if npos == nil then
exit = false print("last line")
break break
end end
end pos = npos
if v == "-e" or v == "--english" then
all = false
word = string.gsub(words[i][2],"%p","")
if string.find(word, query) then
exit = false
break
end
end
end
if all == true then
for j=1, #words[i]-1 do
word = string.gsub(words[i][j],"%p","")
if string.find(word, query) then
exit = false
break
end
end
end
if not exit then
local word = {i,words[i]}
table.insert(results_table,word)
end
end end
if #results_table ~= 0 then
results_table = adjustTableSizes(results_table) -- get before
printOutputTable(results_table) file:seek("set",0)
else local before = file:read(pos-1)
print("no words found for <" .. query .. ">") file:seek("set",pos)
-- move to things to modify
pos = string.find(text,"\n",pos+1)
file:seek("set",pos)
-- find next section
local next_section = string.find(text,"\"",pos+1) or file:seek("end")
file:seek("set",pos)
local length = next_section-pos
-- get after
file:seek("set",pos)
local after = file:read("*all") or ""
-- done w file
file:close()
-- get word going to be removed
local results_table = {}
if words[number] then
table.insert(results_table,{number,words[number]})
end end
results_table = adjustTableSizes(results_table)
print("\nare you sure you want to remove the following entry? (y/N)")
printOutputTable(results_table,true)
print("")
local delete = string.lower(io.read())
if delete == "y"
or delete == "ye"
or delete == "yes"
then
delete = true
else
delete = false
end
--[[
print("Before")
print(text)
print("After:")
print(before)
print(after)
]]
if delete then
--rewrite with new info
local file = io.open(data_output, "w+")
file:write(before)
file:write("\n")
file:write(after)
file:close()
print("\nentry was deleted.\n")
else
print("\nentry was not deleted.\n")
end
end end

View File

@ -1,4 +1,4 @@
return function(query) function searchList(query)
results_table = {} results_table = {}
local skip_regular = false local skip_regular = false
for _, v in pairs(arg) do for _, v in pairs(arg) do
@ -35,7 +35,7 @@ return function(query)
end end
end end
if all == true then if all == true then
for j=1, #words[i]-1 do for j=1, #words[i] do
word = string.gsub(words[i][j],"%p","") word = string.gsub(words[i][j],"%p","")
if string.find(word, query) then if string.find(word, query) then
exit = false exit = false

View File

@ -1,4 +1,4 @@
return function() function showList()
results_table = {} results_table = {}
for i=1, #words do for i=1, #words do
local word = {i,words[i]} local word = {i,words[i]}

View File

@ -1,5 +1,5 @@
local t = {} local t = {}
table.insert(t,{"-el","bringer of","suffix","demonic","ariel","used in demonic names."}) table.insert(t,{"el","bringer of","suffix","demonic","ariel","used in demonic titles"})
table.insert(t,{"-lae","feed from","suffix","demonic","",""}) table.insert(t,{"-lae","feed from","suffix","demonic","",""})
table.insert(t,{"-sh","intention of","suffix","umyr intention/power","","used in myrean names."}) table.insert(t,{"-sh","intention of","suffix","umyr intention/power","","used in myrean names."})
table.insert(t,{"a.bae","young","modifier","","",""}) table.insert(t,{"a.bae","young","modifier","","",""})
@ -18,10 +18,9 @@ table.insert(t,{"an.ku","to walk, to experience","verb","","fern's name",""})
table.insert(t,{"an.me","anime","noun","","",""}) table.insert(t,{"an.me","anime","noun","","",""})
table.insert(t,{"ba","you","pronoun","","",""}) table.insert(t,{"ba","you","pronoun","","",""})
table.insert(t,{"ba.bii.ku","to count","verb","","",""}) table.insert(t,{"ba.bii.ku","to count","verb","","",""})
table.insert(t,{"ba.ku","to swim","verb","","",""}) table.insert(t,{"be.ku","to swim","verb","","",""})
table.insert(t,{"ba.lo","hand","noun","","",""}) table.insert(t,{"ba.lo","hand","noun","","",""})
table.insert(t,{"ba.pa.ba.pa.ku","to rub, to hug","verb","","",""}) table.insert(t,{"ba.pa.ku","to hold, to hug","verb","","",""})
table.insert(t,{"ba.pa.ku","to hold","verb","","",""})
table.insert(t,{"bae","small","modifier","","",""}) table.insert(t,{"bae","small","modifier","","",""})
table.insert(t,{"bae.la.pa","egg","noun","","",""}) table.insert(t,{"bae.la.pa","egg","noun","","",""})
table.insert(t,{"bae.ma.ra","yesterday","noun","","",""}) table.insert(t,{"bae.ma.ra","yesterday","noun","","",""})
@ -31,7 +30,7 @@ table.insert(t,{"be.taf","big","modifier","","",""})
table.insert(t,{"beg","many, big quantity","modifier","","",""}) table.insert(t,{"beg","many, big quantity","modifier","","",""})
table.insert(t,{"bi.men","bird","noun","","",""}) table.insert(t,{"bi.men","bird","noun","","",""})
table.insert(t,{"bo.ku","to sew","verb","","",""}) table.insert(t,{"bo.ku","to sew","verb","","",""})
table.insert(t,{"bokuch","clothes, anything sewn","noun","","",""}) table.insert(t,{"bo.kuch","clothes, anything sewn","noun","","",""})
table.insert(t,{"bu.lu.ku","to kill","verb","","",""}) table.insert(t,{"bu.lu.ku","to kill","verb","","",""})
table.insert(t,{"cha.we","narrow","modifier","","",""}) table.insert(t,{"cha.we","narrow","modifier","","",""})
table.insert(t,{"chib","tongue","noun","","",""}) table.insert(t,{"chib","tongue","noun","","",""})
@ -123,7 +122,7 @@ table.insert(t,{"kan.ku","to come here","verb","","",""})
table.insert(t,{"kash.ku","to break","verb","","",""}) table.insert(t,{"kash.ku","to break","verb","","",""})
table.insert(t,{"ki.ku","to say, to chat","verb","","",""}) table.insert(t,{"ki.ku","to say, to chat","verb","","",""})
table.insert(t,{"ku","to be","verb","","","basic verbal form."}) table.insert(t,{"ku","to be","verb","","","basic verbal form."})
table.insert(t,{"ku.ku.ku","to embody","noun","","",""}) table.insert(t,{"ku.ku.ku","to embody","verb","","",""})
table.insert(t,{"kya.ny","long","modifier","","",""}) table.insert(t,{"kya.ny","long","modifier","","",""})
table.insert(t,{"la.e","spouse","noun","","",""}) table.insert(t,{"la.e","spouse","noun","","",""})
table.insert(t,{"la.fen","feather","noun","","",""}) table.insert(t,{"la.fen","feather","noun","","",""})
@ -151,7 +150,7 @@ table.insert(t,{"mi.gu.ra","daytime","noun","","",""})
table.insert(t,{"mi.ku","to put into words","verb","","bincat",""}) table.insert(t,{"mi.ku","to put into words","verb","","bincat",""})
table.insert(t,{"mi.la.ta","sky","noun","","",""}) table.insert(t,{"mi.la.ta","sky","noun","","",""})
table.insert(t,{"mi.me","past","noun","","",""}) table.insert(t,{"mi.me","past","noun","","",""})
table.insert(t,{"mi.min.ku","to see","veb","","",""}) table.insert(t,{"mi.min.ku","to see","verb","","",""})
table.insert(t,{"mi.nya","present","noun","","",""}) table.insert(t,{"mi.nya","present","noun","","",""})
table.insert(t,{"mi.ra.ku","to fear","verb","","",""}) table.insert(t,{"mi.ra.ku","to fear","verb","","",""})
table.insert(t,{"mi.sha.ku","to fight","verb","","",""}) table.insert(t,{"mi.sha.ku","to fight","verb","","",""})
@ -197,8 +196,9 @@ table.insert(t,{"pi.she.ku","to drink","verb","","",""})
table.insert(t,{"po.me","stone","noun","","",""}) table.insert(t,{"po.me","stone","noun","","",""})
table.insert(t,{"po.nya","good","modifier","","",""}) table.insert(t,{"po.nya","good","modifier","","",""})
table.insert(t,{"pon.me","because","marker","","",""}) table.insert(t,{"pon.me","because","marker","","",""})
table.insert(t,{"pu","star","noun","heonian","actually puropu was first",""}) table.insert(t,{"pu","sun","noun","heonian","",""})
table.insert(t,{"pu.ro.pu","sol, sun","noun","heonian pu + ro + pu, star among stars","",""}) table.insert(t,{"bae.pu","star","noun","heonian","",""})
table.insert(t,{"shi.ro.bae.pu","night sky","noun","heonian shi + ro + bae.pu, star amidst darkness","",""})
table.insert(t,{"pu.ro.ton","yellow","modifier","","",""}) table.insert(t,{"pu.ro.ton","yellow","modifier","","",""})
table.insert(t,{"ra.ya","parent","noun","","",""}) table.insert(t,{"ra.ya","parent","noun","","",""})
table.insert(t,{"re","i","pronoun","","",""}) table.insert(t,{"re","i","pronoun","","",""})
@ -292,5 +292,5 @@ table.insert(t,{"yan.kuch.wa","ocean","noun","","",""})
table.insert(t,{"yea.mat","area","noun","","",""}) table.insert(t,{"yea.mat","area","noun","","",""})
table.insert(t,{"yesh","adorable","modifier","","",""}) table.insert(t,{"yesh","adorable","modifier","","",""})
table.insert(t,{"yi.ma","year","noun","","",""}) table.insert(t,{"yi.ma","year","noun","","",""})
table.insert(t,{"yu","denotes topic, emphasis","marker","","","overwrites subject if they are the same. otherwise, goes after subject marker"}) table.insert(t,{"yu","denotes topic, emphasis","marker","","","overwrites subject marker if they are in the same position, otherwise goes after it"})
return t return t