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 1: Line 1:
local p = {}
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
-- Special cases for verb conjugation that don't follow the regular 's' or 'es' pattern
local specialCases = {
local specialCases = {
go = "goes",
go = "goes",
-- Add more special cases as necessary
}
}


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


-- Adjusts the verb based on the pronoun, verb tense, and input capitalization
-- 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 function adjustVerb(originalPronoun, originalVerb)
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 resultVerb = verb -- Default to the original verb form


local result = ""
-- Continuous tense (verbs ending in 'ing')
-- Continuous tense (verbs ending in 'ing')
if verb:sub(-3) == "ing" then
if verb:sub(-3) == "ing" then
resultVerb = formToBe(originalPronoun) .. " " .. originalVerb
local aux = pronoun == "they" and "are" or "is"
result = originalPronoun .. " " .. aux .. " " .. originalVerb
else
else
-- Simple present tense adjustments
-- 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
resultVerb = specialCases[verb] or (verb .. (verb:match("s$") and "" or "s"))
verb = specialCases[verb] or verb -- Apply special case if exists
elseif pronoun == "they" and (verb:match("es$") or verb:match("s$")) then
if not verb:match("s$") then
-- Adjusting for plural (typically just removing the 's', but some verbs may be irregular)
verb = verb .. (needsEsEnding(verb) and "es" or "s")
end
resultVerb = specialCases[verb] or verb:sub(1, -2)
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
end
result = originalPronoun .. " " .. verb
resultVerb = matchCase(originalVerb, resultVerb) -- Adjust the case based on the original input
end

-- Adjust for mixed capitalization (Title Case)
if not isAllCaps(originalPronoun) then
result = result:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end)
end

-- Adjust the result for all caps
if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
result = result:upper()
end
end
return originalPronoun .. " " .. resultVerb
return result
end
end


Line 52: Line 66:
local originalPronoun = frame.args[1]
local originalPronoun = frame.args[1]
local originalVerb = frame.args[2]
local originalVerb = frame.args[2]
return adjustVerb(originalPronoun, originalVerb) -- Adjust and return the result
return adjustVerb(originalPronoun, originalVerb) -- Adjust and return result
end
end



Revision as of 19:27, 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",
}

-- Determines if the string is fully uppercase
local function isAllCaps(s)
    return s:upper() == s
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
        local aux = pronoun == "they" and "are" or "is"
        result = originalPronoun .. " " .. aux .. " " .. 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

    -- Adjust for mixed capitalization (Title Case)
    if not isAllCaps(originalPronoun) then
        result = result:gsub("(%a)([%w_']*)", function(first, rest) return first:upper()..rest:lower() end)
    end

    -- Adjust the result for all caps
    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