Module:auto cat: Difference between revisions

Jump to navigation Jump to search
I DID IT!!! (Made %p for part of speech functional)
No edit summary
Tag: Reverted
(I DID IT!!! (Made %p for part of speech functional))
Tag: Reverted
Line 54: Line 54:
-- Expands a pattern containing %l (and optionally %u), adding versions
-- Expands a pattern containing %l (and optionally %u), adding versions
-- of the pattern for each possible language
-- of the pattern for each possible language
local function hydrate_pattern_l(out_patterns, p_lua, p_categories, also_u)
local function hydrate_pattern_l(out_patterns, p_lua, p_categories, also_u, also_p)
     for _, l_data in pairs(d_languages) do
     for _, l_data in pairs(d_languages) do
        if also_u then
    if also_p then
            for _, l2_data in pairs(d_languages) do
    for _, pos in ipairs(d_pos) do
                if l2_data.code ~= l_data.code then
    if also_u then
                    local p_out_cats = {}
            for _, l2_data in pairs(d_languages) do
                    for _, p_cat in ipairs(p_categories) do
                if l2_data.code ~= l_data.code then
                        table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%u"] = l2_data.name}))
                    local p_out_cats = {}
                    end
                    for _, p_cat in ipairs(p_categories) do
                    table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["%%u"] = sanitize(l2_data.name)}), p_out_cats))
                    table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%u"] = l2_data.name, ["^%%p"] = capitalize(pos), ["%%p"] = pos}))
                end
                    end
            end
                    table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["%%u"] = sanitize(l2_data.name), ["^%%p"] = capitalize(pos), ["%%p"] = pos}), p_out_cats))
        else
                end
            local p_out_cats = {}
            end
            for _, p_cat in ipairs(p_categories) do
        else
                table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name}))
            local p_out_cats = {}
            end
            for _, p_cat in ipairs(p_categories) do
            table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name)}), p_out_cats))
            table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["^%%p"] = capitalize(pos), ["%%p"] = pos}))
            end
            table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["^%%p"] = capitalize(pos), ["%%p"] = pos}), p_out_cats))
        end
    end
    else
        if also_u then
            for _, l2_data in pairs(d_languages) do
                if l2_data.code ~= l_data.code then
                    local p_out_cats = {}
                    for _, p_cat in ipairs(p_categories) do
                    table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name, ["%%u"] = l2_data.name}))
                    end
                    table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name), ["%%u"] = sanitize(l2_data.name)}), p_out_cats))
                end
            end
        else
            local p_out_cats = {}
            for _, p_cat in ipairs(p_categories) do
            table.insert(p_out_cats, replace(p_cat, {["%%l"] = l_data.name}))
            end
            table.insert(out_patterns, to_pattern(replace(p_lua, {["%%l"] = sanitize(l_data.name)}), p_out_cats))
        end
         end
         end
     end
     end
Line 87: Line 109:


local function hydrate_pattern_p(out_patterns, p_lua, p_categories)
local function hydrate_pattern_p(out_patterns, p_lua, p_categories)
     for _, p_pos in ipairs(d_pos) do
     for _, pos in ipairs(d_pos) do
     local p_out_cats = {}
     local p_out_cats = {}
         for _, p_cat in ipairs(p_categories) do
         for _, p_cat in ipairs(p_categories) do
             table.insert(p_out_cats, replace(p_cat, {["^%%p"] = capitalize(p_pos), ["%%p"] = p_pos}))
             table.insert(p_out_cats, replace(p_cat, {["^%%p"] = capitalize(pos), ["%%p"] = pos}))
         end
         end
         table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%p"] = capitalize(p_pos), ["%%p"] = p_pos}), p_out_cats))
         table.insert(out_patterns, to_pattern(replace(p_lua, {["^%%p"] = capitalize(pos), ["%%p"] = pos}), p_out_cats))
end
end
end
end
Line 102: Line 124:
         local p_lua = replace(sanitize(p_template), {["%%s"] = "(..-)"})
         local p_lua = replace(sanitize(p_template), {["%%s"] = "(..-)"})
         if mw.ustring.find(p_template, "%%l") ~= nil then
         if mw.ustring.find(p_template, "%%l") ~= nil then
             hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil)
             hydrate_pattern_l(out_patterns, p_lua, p_categories, mw.ustring.find(p_template, "%%u") ~= nil, mw.ustring.find(p_template, "%%p") ~= nil)
         elseif mw.ustring.find(p_template, "%%c") ~= nil then
         elseif mw.ustring.find(p_template, "%%c") ~= nil then
hydrate_pattern_c(out_patterns, p_lua, p_categories)
hydrate_pattern_c(out_patterns, p_lua, p_categories)

Navigation menu