Module:Pronoun: Difference between revisions

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Jump to navigation Jump to search
Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 6: Line 6:
end
end


-- Special cases for verb conjugation that don't follow the regular 's' or 'es' pattern, including 'has' to 'have'
-- Special cases for verb conjugation that don't follow the regular 's' or 'es' pattern
local specialCases = {
local specialCases = {
go = "goes",
go = "goes",
Line 30: Line 30:
local pronoun = originalPronoun:lower() -- Use lowercase for logic
local pronoun = originalPronoun:lower() -- Use lowercase for logic
local verb = originalVerb:lower() -- Use lowercase for logic
local verb = originalVerb:lower() -- Use lowercase for logic

local result = ""
local result = ""
-- Continuous tense (verbs ending in 'ing')
-- Continuous tense (verbs ending in 'ing')
Line 36: Line 36:
result = applyContinuousVerb(originalPronoun, originalVerb)
result = applyContinuousVerb(originalPronoun, originalVerb)
else
else
-- Simple present tense for singular third-person
if pronoun == "he" or pronoun == "she" or pronoun == "it" then
if pronoun == "he" or pronoun == "she" or pronoun == "it" then
if specialCases[verb] then
verb = specialCases[verb] or verb -- Apply special case if exists
verb = specialCases[verb]
if not verb:match("s$") then
elseif not verb:match("s$") then
verb = verb .. (needsEsEnding(verb) and "es" or "s")
verb = verb .. (needsEsEnding(verb) and "es" or "s")
end
end
elseif pronoun == "they" then
elseif pronoun == "they" then
-- Directly handling the 'has' to 'have' conversion
verb = specialCases[verb] or verb -- Check if there's a special plural case
if verb:match("es$") or verb:match("s$") then
if verb == "has" then
verb = verb:sub(1, -3) -- Assuming 'es' ending for simplicity, adjust as needed
verb = "have"
else
-- Adjusting back from special cases if needed
verb = specialCases[verb] or verb
-- 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
end
end
end
Line 51: Line 60:
end
end


-- Adjust for uppercase input
-- Preserve the original case for title case and uppercase inputs
if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
result = result:upper()
result = result:upper()
elseif originalPronoun == "They" and verb == "go" then
else
-- Reapply the original case for the verb if no conjugation change was needed
-- Specific case to ensure "They Go" remains properly cased
result = originalPronoun .. " " .. (verb == "go" and "Go" or verb)
if verb == originalVerb:lower() then
verb = originalVerb
end
result = originalPronoun .. " " .. verb
end
end



Revision as of 20:02, 18 March 2024

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",
    has = "have",
}

-- 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
            -- Directly handling the 'has' to 'have' conversion
            if verb == "has" then
                verb = "have"
            else
                -- Adjusting back from special cases if needed
                verb = specialCases[verb] or verb
                -- 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
        end
        result = originalPronoun .. " " .. verb
    end

    -- Preserve the original case for title case and uppercase inputs
    if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
        result = result:upper()
    elseif originalPronoun == "They" and verb == "go" then
        -- Specific case to ensure "They Go" remains properly cased
        result = originalPronoun .. " " .. (verb == "go" and "Go" or verb)
    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 the result
end

return p