Module:Pronoun

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 19:38, 18 March 2024 by Vish (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Pronoun/doc

local p = {}

-- Checks if a verb needs an 'es' ending (for third-person singular simple present tense)
local function needsEsEnding(verb)
    return verb:match("[oschx]$") or verb:match("sh$") or verb:match("ss$")
end

-- Special cases for verb conjugation that don't follow the regular 's' or 'es' pattern
local specialCases = {
    go = "goes",
}

-- Determines if the string is fully uppercase
local function isAllCaps(s)
    return s:upper() == s
end

-- Correctly applies 'is' or 'are' for continuous verbs based on pronoun, retaining input case
local function applyContinuousVerb(pronoun, verb)
    if pronoun:lower() == "they" then
        return pronoun .. " are " .. verb
    else
        return pronoun .. " is " .. verb
    end
end

-- Adjusts the verb based on the pronoun, verb tense, and input capitalization
local function adjustVerb(originalPronoun, originalVerb)
    local pronoun = originalPronoun:lower() -- Use lowercase for logic
    local verb = originalVerb:lower() -- Use lowercase for logic

    local result = ""
    -- Continuous tense (verbs ending in 'ing')
    if verb:sub(-3) == "ing" then
        result = applyContinuousVerb(originalPronoun, originalVerb)
    else
        -- Simple present tense for singular third-person
        if pronoun == "he" or pronoun == "she" or pronoun == "it" then
            verb = specialCases[verb] or verb -- Apply special case if exists
            if not verb:match("s$") then
                verb = verb .. (needsEsEnding(verb) and "es" or "s")
            end
        elseif pronoun == "they" then
            -- Adjusting back from special cases if needed
            for base, conjugated in pairs(specialCases) do
                if verb == conjugated then
                    verb = base
                end
            end
            -- Remove 'es' or 's' if present
            if verb:match("es$") then
                verb = verb:sub(1, -3)
            elseif verb:match("s$") then
                verb = verb:sub(1, -2)
            end
        end
        result = originalPronoun .. " " .. verb
    end

    -- Preserve original case without converting to title case or uppercase, unless fully uppercase
    if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
        result = result:upper()
    end

    return result
end

function p.main(frame)
    local originalPronoun = frame.args[1]
    local originalVerb = frame.args[2]
    return adjustVerb(originalPronoun, originalVerb) -- Adjust and return result
end

return p