Module:Pronoun

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 19:26, 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 = {}

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

-- Determines the correct form of "to be" based on the pronoun
local function formToBe(pronoun)
    if pronoun:lower() == "he" or pronoun:lower() == "she" or pronoun:lower() == "it" then
        return "is"
    else
        return "are"
    end
end

-- Capitalizes a word if the original was capitalized
local function matchCase(original, word)
    if original:sub(1,1):match("%u") then
        return word:sub(1,1):upper() .. word:sub(2)
    else
        return word
    end
end

-- Adjusts the verb based on the pronoun, maintaining specific capitalization
local function adjustVerb(originalPronoun, originalVerb)
    local pronoun = originalPronoun:lower() -- Use lowercase for logic
    local verb = originalVerb:lower() -- Use lowercase for logic
    
    local resultVerb = verb -- Default to the original verb form

    -- Continuous tense (verbs ending in 'ing')
    if verb:sub(-3) == "ing" then
        resultVerb = formToBe(originalPronoun) .. " " .. originalVerb
    else
        -- Simple present tense adjustments
        if pronoun == "he" or pronoun == "she" or pronoun == "it" then
            resultVerb = specialCases[verb] or (verb .. (verb:match("s$") and "" or "s"))
        elseif pronoun == "they" and (verb:match("es$") or verb:match("s$")) then
            -- Adjusting for plural (typically just removing the 's', but some verbs may be irregular)
            resultVerb = specialCases[verb] or verb:sub(1, -2)
        end
        resultVerb = matchCase(originalVerb, resultVerb) -- Adjust the case based on the original input
    end
    
    return originalPronoun .. " " .. resultVerb
end

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

return p