From 8fbebbd08b2bb15dd5dd41b49de26c04adc13810 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 5 Nov 2024 20:53:09 +0000 Subject: get vötgil working, allow selecting language MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conlex.lua | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 9 deletions(-) (limited to 'conlex.lua') diff --git a/conlex.lua b/conlex.lua index afee980..bf3ff8c 100755 --- a/conlex.lua +++ b/conlex.lua @@ -1,4 +1,6 @@ #!/usr/bin/env lua5.3 +local lpeg = require'lpeg' + local function template(str, args) return (str:gsub("%%(%w+)%%", args)) end @@ -74,24 +76,65 @@ function glossors.sanila(text) table.insert(items, format_def(word, entry)) end - return items + return table.concat(items, "\n") +end + +glossors["vötgil"] = function(text) + local words = load_dict "vötgil.tsv" + local function norm(s) + return s:lower():gsub("Ð","ð"):gsub("Ö","ö"):gsub("0","ö"):gsub("9","ð") + end + + local letter = lpeg.R("az","AZ") + lpeg.S"09" + "ö" + "Ö" + 'ð' + 'Ð' + local word = (letter*letter*letter) / function (w) + return format_def(w, words[norm(w)]) + end * lpeg.Cp() + + local i = 1 + local out = "" + while i < #text do + local item, ni = lpeg.match(word, text, i) + if item then + out = out .. item + i = ni + else + out = out .. text:sub(i,i) + i = i + 1 + end + end + return out end local function engloss(langue, text) - local items = glossors[langue](text) + local text = glossors[langue](text) return template([[
%text%
-
]], {text=table.concat(items, "\n")}) +
+
< return
+ ]], {text=text,path=os.getenv"SCRIPT_NAME"}) end local function enform() - return [[ + local options = {} + for k in pairs(glossors) do + table.insert(options, template('', {x=k})) + end + table.sort(options) + return template([[
- + + +
-
]] + +]], { + options=table.concat(options, "\n"), + + }) end local function response(content) @@ -101,14 +144,20 @@ local function response(content) end local function main() - local text = nil + local langue, text local qs = os.getenv"QUERY_STRING" - if qs then text = parse_qs(qs).q end + if qs then + local pqs = parse_qs(qs) + langue = pqs.langue + text = pqs.q + end if not text then response(enform()) + elseif not glossors[langue] then + response("unknown langue "..langue) else - response(engloss('sanila', text)) + response(engloss(langue, text)) end end -- cgit v1.2.3