Module:Polola: Difference between revisions
Jump to navigation
Jump to search
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..." |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Helper function to trim whitespaces | |||
local function trim(s) | |||
return s:match("^%s*(.-)%s*$") | |||
local function | |||
end | end | ||
-- Parse function for Polola language grammar and structures | |||
function p.parse(frame) | function p.parse(frame) | ||
local | -- Read 'expr' parameter from template or direct call | ||
if | local input = frame.args.expr or frame:getParent().args.expr or "" | ||
if trim(input) == "" then | |||
return "<span style='color:red;'>Error: No expression provided!</span>" | |||
end | end | ||
local result = {} | local result = {} | ||
for token in string.gmatch( | |||
local word, | -- Safe tokenization using escaped pattern matching | ||
if | -- % character escapes operators like +, *, /, and brackets () so they don't cause capture errors | ||
for token in string.gmatch(input, "([^%s%+%*%/]+)") do | |||
-- Clean brackets from the token safely | |||
local clean_token = token:gsub("%(", ""):gsub("%)", "") | |||
table.insert(result, | -- Separate the base word from numeric quantifiers (e.g., sfg3 -> base: sfg, quantifier: 3) | ||
local base_word, quantifier = clean_token:match("^([a-z]+)(%d*)$") | |||
if base_word then | |||
local meaning = "" | |||
-- Basic Polola vocabulary translation logic | |||
if string.sub(base_word, 1, 1) == "l" then | |||
meaning = "distant/hidden concept (" .. base_word .. ")" | |||
elseif string.sub(base_word, 1, 1) == "s" then | |||
meaning = "present/near concept (" .. base_word .. ")" | |||
else | |||
meaning = "general concept (" .. base_word .. ")" | |||
end | |||
-- Append quantifier info if present | |||
if quantifier and quantifier ~= "" then | |||
meaning = meaning .. " [quantifier: " .. quantifier .. "x]" | |||
end | |||
table.insert(result, meaning) | |||
end | end | ||
end | end | ||
return table.concat(result, "") | |||
-- Check for complex structural operators | |||
local structure_info = "" | |||
if input:match("%(") or input:match("%+") or input:match("%*") or input:match("%/") then | |||
structure_info = "<br/><small><i>Structure: Complex logical/associative relation detected.</i></small>" | |||
end | |||
-- Return final formatted output | |||
if #result == 0 then | |||
return "Polola syntax: " .. input .. " → Uninterpretable expression." | |||
else | |||
return "Polola syntax: <b>" .. input .. "</b><br/>Interpretation: " .. table.concat(result, ", ") .. structure_info | |||
end | |||
end | end | ||
return p | return p | ||
Latest revision as of 08:34, 3 July 2026
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local p = {}
-- Helper function to trim whitespaces
local function trim(s)
return s:match("^%s*(.-)%s*$")
end
-- Parse function for Polola language grammar and structures
function p.parse(frame)
-- Read 'expr' parameter from template or direct call
local input = frame.args.expr or frame:getParent().args.expr or ""
if trim(input) == "" then
return "<span style='color:red;'>Error: No expression provided!</span>"
end
local result = {}
-- Safe tokenization using escaped pattern matching
-- % character escapes operators like +, *, /, and brackets () so they don't cause capture errors
for token in string.gmatch(input, "([^%s%+%*%/]+)") do
-- Clean brackets from the token safely
local clean_token = token:gsub("%(", ""):gsub("%)", "")
-- Separate the base word from numeric quantifiers (e.g., sfg3 -> base: sfg, quantifier: 3)
local base_word, quantifier = clean_token:match("^([a-z]+)(%d*)$")
if base_word then
local meaning = ""
-- Basic Polola vocabulary translation logic
if string.sub(base_word, 1, 1) == "l" then
meaning = "distant/hidden concept (" .. base_word .. ")"
elseif string.sub(base_word, 1, 1) == "s" then
meaning = "present/near concept (" .. base_word .. ")"
else
meaning = "general concept (" .. base_word .. ")"
end
-- Append quantifier info if present
if quantifier and quantifier ~= "" then
meaning = meaning .. " [quantifier: " .. quantifier .. "x]"
end
table.insert(result, meaning)
end
end
-- Check for complex structural operators
local structure_info = ""
if input:match("%(") or input:match("%+") or input:match("%*") or input:match("%/") then
structure_info = "<br/><small><i>Structure: Complex logical/associative relation detected.</i></small>"
end
-- Return final formatted output
if #result == 0 then
return "Polola syntax: " .. input .. " → Uninterpretable expression."
else
return "Polola syntax: <b>" .. input .. "</b><br/>Interpretation: " .. table.concat(result, ", ") .. structure_info
end
end
return p