diff --git a/add_word.lua b/add_word.lua new file mode 100644 index 0000000..ced6cf7 --- /dev/null +++ b/add_word.lua @@ -0,0 +1,44 @@ +return function(query) + results_table = {} + for i=1, #words do + local exit = true + local all = true + for _, v in pairs(arg) do + if v == "-r" or v == "--raw" then + all = false + word = string.gsub(words[i][1],"%p","") + if string.find(word, query) then + exit = false + break + end + end + 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 + if #results_table ~= 0 then + results_table = adjustTableSizes(results_table) + printOutputTable(results_table) + else + print("no words found for <" .. query .. ">") + end +end \ No newline at end of file diff --git a/lexicon b/lexicon index 4d645a2..60ec69f 100755 --- a/lexicon +++ b/lexicon @@ -5,11 +5,14 @@ if not arg[1] then print("no argument, try again") return end require "R2H2" require "color" + adjustTableSizes = require "output_sizes" printOutputTable = require "output_word" showList = require "show_list" searchList = require "search_list" +removeWord = require "remove_word" +addWord = require "add_word" words = dofile("words.lua") @@ -29,7 +32,7 @@ or arg[1] == "how" or arg[1] == "howdo" then print([[ -[a]ll +[l]ist - shows all words in heonian. [h]elp @@ -46,17 +49,17 @@ Parameters: -c / --copy (copies transcription to keyboard) -e / --english (limits the search to the translated words) -h / --help (shows what does the command do) --r / --raw (limits the search to the heonian words) +-r / --raw (limits the search to the heonian words) -v / --verbose (shows the transcription process) ]]) return end -if arg[1] == "a" -or arg[1] == "all" then +if arg[1] == "l" +or arg[1] == "list" then if please_help then print([[ -[a]ll +[l]ist - shows all words in heonian. Parameters: @@ -81,6 +84,7 @@ Parameters: -a / --all (shows more info on the word, if any) -e / --english (limits the search to the translated words) -r / --raw (limits the search to the heonian words) +-i / --id (searches using word id) ]]) else if arg[2] then searchList(arg[2]) @@ -107,3 +111,40 @@ Parameters: return end end + +if arg[1] == "r" +or arg[1] == "remove" then + if please_help then + print([[ + +[r]emove + - removes the word from the lexicon + +Parameters: +-h / --help (shows what does the command do) +]]) + else + if arg[2] then removeWord(arg[2]) + else print("no word to remove") end + return + end +end + +if arg[1] == "a" +or arg[1] == "remove" then + if please_help then + print([[ + +[r]emove + - removes the word from the lexicon + +Parameters: +-h / --help (shows what does the command do) +]]) + else + if arg[2] then addWord(...) + else print("no word to add") end + return + end +end + diff --git a/remove_word.lua b/remove_word.lua new file mode 100644 index 0000000..ced6cf7 --- /dev/null +++ b/remove_word.lua @@ -0,0 +1,44 @@ +return function(query) + results_table = {} + for i=1, #words do + local exit = true + local all = true + for _, v in pairs(arg) do + if v == "-r" or v == "--raw" then + all = false + word = string.gsub(words[i][1],"%p","") + if string.find(word, query) then + exit = false + break + end + end + 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 + if #results_table ~= 0 then + results_table = adjustTableSizes(results_table) + printOutputTable(results_table) + else + print("no words found for <" .. query .. ">") + end +end \ No newline at end of file diff --git a/search_list.lua b/search_list.lua index ced6cf7..a9c7b0b 100644 --- a/search_list.lua +++ b/search_list.lua @@ -1,6 +1,19 @@ return function(query) results_table = {} + local skip_regular = false + for _, v in pairs(arg) do + if v == "-i" or v == "--id" then + skip_regular = true + local id = tonumber(query) + if words[id] then + local word = {id,words[id]} + table.insert(results_table,word) + end + break + end + end for i=1, #words do + if skip_regular then break end local exit = true local all = true for _, v in pairs(arg) do @@ -39,6 +52,10 @@ return function(query) results_table = adjustTableSizes(results_table) printOutputTable(results_table) else - print("no words found for <" .. query .. ">") + if skip_regular then + print("no word found for id #" .. query) + else + print("no words found for query <" .. query .. ">") + end end end \ No newline at end of file diff --git a/words.lua b/words.lua index 19a9717..eb0b860 100644 --- a/words.lua +++ b/words.lua @@ -55,7 +55,7 @@ table.insert(t,{"do.me","dust","noun","","",""}) table.insert(t,{"dra","indicates question","marker","","",""}) table.insert(t,{"dsho.ei","fate","noun","","fern's name",""}) table.insert(t,{"dsho.ei.an","shared destiny, together","modifier","fate + path","fern's name","walking the same path -> sharing the same fate -> together"}) -table.insert(t,{"dsho.ei.an.un","romantic partner, (fated)","noun","fate + path + being","fern's name",""}) +table.insert(t,{"dsho.ei.an.un","fated partner","noun","fate + path + being","fern's name",""}) table.insert(t,{"du.tan","smoke","noun","","",""}) table.insert(t,{"duch","seed","noun","","",""}) table.insert(t,{"e","which","pronoun","","",""})