Module:Polola

From Linguifex
Revision as of 18:20, 2 July 2026 by Nyima (talk | contribs) (Created page with "local p = {} local deictic = { s = "present / visible / local", l = "distant / hidden / abstract" } local ontology = { d = "object (inanimate matter)", f = "living being (biological entity)", r = "energy (radiation / physical process)", g = "abstract thing (concept / thought)" } local dynamics = { g = "moving / changing / active", h = "stationary / static / at rest" } local operators = { ["+"] = " '''[OR]''' ", ["*"] = " '''[AN...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


local p = {}

local deictic = {
    s = "present / visible / local",
    l = "distant / hidden / abstract"
}

local ontology = {
    d = "object (inanimate matter)",
    f = "living being (biological entity)",
    r = "energy (radiation / physical process)",
    g = "abstract thing (concept / thought)"
}

local dynamics = {
    g = "moving / changing / active",
    h = "stationary / static / at rest"
}

local operators = {
    ["+"] = " '''[OR]''' ",
    ["*"] = " '''[AND]''' ",
    ["-"] = " '''[NOT / EXCLUDING]:''' ",
    ["/"] = " '''[IN RELATION TO / DEPENDING ON]:''' ",
    ["%"] = " '''[SUBSET / REMAINDER OF]:''' ",
    ["("] = " ( ",
    [")"] = " ) ",
    [")("] = " '''[XOR / EXCLUSIVE OR]''' ",
    ["0"] = " '''[FALSE / VOID]''' ",
    ["1"] = " '''[TRUE / EXISTENCE]''' "
}

local function translate_word(word)
    if #word ~= 3 then return word end
    local c = string.sub(word, 1, 1)
    local o = string.sub(word, 2, 2)
    local d = string.sub(word, 3, 3)
    if deictic[c] and ontology[o] and dynamics[d] then
        return string.format("<span style='color:#0066cc;'>&lt;%s %s %s&gt;</span>", deictic[c], dynamics[d], ontology[o])
    end
    return word
end

function p.parse(frame)
    local expr = frame.args.expr or frame:getParent().args.expr or ""
    if expr == "" then return "''No Polola expression provided!''" end
    expr = string.gsub(expr, ")%s*(", " )( ")
    for op in string.gmatch("+*-/%()", ".") do
        expr = string.gsub(expr, "%" .. op, " " .. op .. " ")
    end
    local result = {}
    for token in string.gmatch(expr, "%S+") do
        local word, num = string.match(token, "^([sl][dfrg][gh])(%d+)$")
        if word and num then
            table.insert(result, string.format("'''%s units of''' %s", num, translate_word(word)))
        elseif operators[token] then
            table.insert(result, operators[token])
        else
            table.insert(result, translate_word(token))
        end
    end
    return table.concat(result, "")
end

return p