Module:Polola: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Nyima (talk | contribs)
No edit summary
Nyima (talk | contribs)
No edit summary
 
Line 1: Line 1:
local p = {}
local p = {}


-- Segédfüggvény a szóközök eltávolítására
-- Helper function to trim whitespaces
local function trim(s)
local function trim(s)
     return s:match("^%s*(.-)%s*$")
     return s:match("^%s*(.-)%s*$")
end
end


-- A Polola nyelv gyökereinek és nyelvtani elemeinek elemzése
-- Parse function for Polola language grammar and structures
function p.parse(frame)
function p.parse(frame)
     -- Ha sablonból hívják meg, az 'expr' paramétert olvassa be
     -- Read 'expr' parameter from template or direct call
     local input = frame.args.expr or frame:getParent().args.expr or ""
     local input = frame.args.expr or frame:getParent().args.expr or ""
     if trim(input) == "" then
     if trim(input) == "" then
         return "<span style='color:red;'>Hiba: Nem adtál meg kifejezést!</span>"
         return "<span style='color:red;'>Error: No expression provided!</span>"
     end
     end


     local result = {}
     local result = {}
      
      
     -- Biztonságos minták (az összetett karakterek % jellel vannak levédve)
     -- Safe tokenization using escaped pattern matching
     -- Így a Lua nem hiszi azt, hogy a zárójel vagy a pluszjel egy belső programozási utasítás
     -- % character escapes operators like +, *, /, and brackets () so they don't cause capture errors
    local safe_input = input
     for token in string.gmatch(input, "([^%s%+%*%/]+)") do
   
         -- Clean brackets from the token safely
    -- Itt történik a tokenek feldolgozása sorban
    -- A kód végigmegy a bemeneten és elemzi a Polola struktúrát
     for token in string.gmatch(safe_input, "([^%s%+%*%/]+)") do
         -- Megkeressük a zárójeleket és a speciális Polola karaktereket
         local clean_token = token:gsub("%(", ""):gsub("%)", "")
         local clean_token = token:gsub("%(", ""):gsub("%)", "")
          
          
         -- Kiszűrjük a számokat (kvantorokat, pl. sfg3 -> 3 darab sfg)
         -- Separate the base word from numeric quantifiers (e.g., sfg3 -> base: sfg, quantifier: 3)
         local base_word, quantifier = clean_token:match("^([a-z]+)(%d*)$")
         local base_word, quantifier = clean_token:match("^([a-z]+)(%d*)$")
          
          
         if base_word then
         if base_word then
             local meaning = ""
             local meaning = ""
             -- Egyszerű Polola szótár alapú fordítási logika
             -- Basic Polola vocabulary translation logic
             if string.sub(base_word, 1, 1) == "l" then
             if string.sub(base_word, 1, 1) == "l" then
                 meaning = "távoli/rejtett dolog (" .. base_word .. ")"
                 meaning = "distant/hidden concept (" .. base_word .. ")"
             elseif string.sub(base_word, 1, 1) == "s" then
             elseif string.sub(base_word, 1, 1) == "s" then
                 meaning = "közeli/jelenlévő dolog (" .. base_word .. ")"
                 meaning = "present/near concept (" .. base_word .. ")"
             else
             else
                 meaning = "általános fogalom (" .. base_word .. ")"
                 meaning = "general concept (" .. base_word .. ")"
             end
             end
              
              
            -- Append quantifier info if present
             if quantifier and quantifier ~= "" then
             if quantifier and quantifier ~= "" then
                 meaning = meaning .. " [" .. quantifier .. "x ismétlődés]"
                 meaning = meaning .. " [quantifier: " .. quantifier .. "x]"
             end
             end
             table.insert(result, meaning)
             table.insert(result, meaning)
Line 47: Line 44:
     end
     end


     -- Ha a bemenetben zárójelek vagy operátorok voltak, azt jelezzük a kimeneten a struktúra miatt
     -- Check for complex structural operators
     local structure_info = ""
     local structure_info = ""
     if input:match("%(") or input:match("%+") or input:match("%*") then
     if input:match("%(") or input:match("%+") or input:match("%*") or input:match("%/") then
         structure_info = "<br/><small><i>Struktúra: Összetett logikai/asszociatív kapcsolat észleve.</i></small>"
         structure_info = "<br/><small><i>Structure: Complex logical/associative relation detected.</i></small>"
     end
     end


     -- Összeállítjuk a végső megjelenítést
     -- Return final formatted output
     if #result == 0 then
     if #result == 0 then
         return "Polola szintaxis: " .. input .. " → Értelmezhetetlen token."
         return "Polola syntax: " .. input .. " → Uninterpretable expression."
     else
     else
         return "Polola szintacia: <b>" .. input .. "</b><br/>Eredmény: " .. table.concat(result, ", ") .. structure_info
         return "Polola syntax: <b>" .. input .. "</b><br/>Interpretation: " .. table.concat(result, ", ") .. structure_info
     end
     end
end
end


return p
return p

Latest revision as of 08:34, 3 July 2026



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