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
 
(10 intermediate revisions by the same user not shown)
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",
["do"] = "does"
-- 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


-- Correctly applies 'is' or 'are' for continuous verbs based on pronoun, retaining input case
-- Capitalizes a word if the original was capitalized
local function matchCase(original, word)
local function applyContinuousVerb(pronoun, verb)
if original:sub(1,1):match("%u") then
if pronoun:lower() == "they" then
return word:sub(1,1):upper() .. word:sub(2)
return pronoun .. " are " .. verb
else
else
return word
return pronoun .. " is " .. verb
end
end
end
end


-- Adjusts the verb based on the pronoun, maintaining specific capitalization
-- Adjusts the verb based on the pronoun, verb tense, and input 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 and originalVerb:lower() or "" -- Use lowercase for logic, check for nil
local resultVerb = verb -- Default to the original verb form


local result = ""
-- Continuous tense (verbs ending in 'ing')
if verb:sub(-3) == "ing" then
-- Check if a verb is provided
if verb == "" then
resultVerb = formToBe(originalPronoun) .. " " .. originalVerb
-- No verb provided, return pronoun as is
result = originalPronoun
else
else
-- Simple present tense adjustments
-- Handle verb logic
if pronoun == "he" or pronoun == "she" or pronoun == "it" then
if verb:sub(-3) == "ing" then
result = applyContinuousVerb(originalPronoun, originalVerb)
resultVerb = specialCases[verb] or (verb .. (verb:match("s$") and "" or "s"))
else
elseif pronoun == "they" and (verb:match("es$") or verb:match("s$")) then
-- Simple present tense for singular third-person
-- Adjusting for plural (typically just removing the 's', but some verbs may be irregular)
resultVerb = specialCases[verb] or verb:sub(1, -2)
if pronoun == "he" or pronoun == "she" or pronoun == "it" then
if verb == "has" then
verb = "has"
else
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
end
elseif pronoun == "they" then
if verb == "has" then
verb = "have"
else
verb = specialCases[verb] or verb
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 without converting everything to uppercase
if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
result = result:upper() -- Only convert to uppercase if both inputs were uppercase
end
end
resultVerb = matchCase(originalVerb, resultVerb) -- Adjust the case based on the original input
end
end

return originalPronoun .. " " .. resultVerb
return result
end
end


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

Latest revision as of 21:32, 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",
    ["do"] = "does"
}

-- 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 and originalVerb:lower() or "" -- Use lowercase for logic, check for nil

    local result = ""
    -- Check if a verb is provided
    if verb == "" then
        -- No verb provided, return pronoun as is
        result = originalPronoun
    else
        -- Handle verb logic
        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
                if verb == "has" then
                    verb = "has"
                else
                    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
                end
            elseif pronoun == "they" then
                if verb == "has" then
                    verb = "have"
                else
                    verb = specialCases[verb] or verb
                    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 without converting everything to uppercase
        if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
            result = result:upper() -- Only convert to uppercase if both inputs were uppercase
        end
    end

    return result
end

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

return p