Module:Pronoun: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 8:
-- 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
-- Adjusts the verb based on the pronoun, verb tense, and maintains original capitalization
local function adjustVerbisAllCaps(originalPronoun, verbs)
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 originalPronounpronoun .. " are " .. originalVerbverb
else
return pronoun .. " is " .. verb
end
end
 
-- Adjusts the verb based on the pronoun, verb tense, and maintains originalinput capitalization
local function adjustVerb(originalPronoun, originalVerb)
local pronoun = originalPronoun:lower() -- Use lowercase for logic
local verb = verboriginalVerb and originalVerb:lower() or "" -- Use lowercase for logic, check for nil
local originalVerb = verb -- Preserve the original verb for later comparison
verb = verb:lower() -- Use lowercase for logic
 
local result = ""
-- Continuous tense (verbs ending in 'ing')
-- Check if verb:sub(-3)a ==verb "ing"is thenprovided
if pronoun == "he" or pronoun == "she" or pronounverb == "it" then
-- No verb provided, return originalPronounpronoun .. "as is " .. originalVerb
elseif pronounresult == "they" thenoriginalPronoun
return originalPronoun .. " are " .. originalVerb
end
else
-- SimpleHandle presentverb tense for singular third-personlogic
if pronounverb:sub(-3) == "he" or pronoun == "she" or pronoun == "iting" then
result = applyContinuousVerb(originalPronoun, originalVerb)
verb = specialCases[verb] or verb -- Apply special case if exists
endelse
if not verb:match("s$") then
-- Simple present tense iffor needsEsEnding(verb)singular thenthird-person
if pronoun == "he" or pronoun == "she" verbor pronoun == verb .. "esit" then
elseif if verb:match( == "s$has") then
verb = verb:sub(1, -3)= "has"
else
verb = specialCases[verb] ..or "s"verb -- Apply special case if exists
if not verb:match("s$") then
verb = verb .. (needsEsEnding(verb) and "es" or "s")
verb = verb:sub(1, -2) end
end
endelseif pronoun == "they" then
elseif pronoun if verb == "theyhas" then
-- For 'they', ensure verb is in base form, adjusting special casesverb as= needed"have"
for base, conjugated in pairs(specialCases) doelse
if verb == conjugatedspecialCases[verb] thenor verb
if verb:match("es$") = base -- revert special case to base formthen
verb = verb:sub(1, -3)
elseif verb:match("s$") then
verb = verb:sub(1, -2)
end
end
end
result = originalPronoun .. " " .. verb
-- Remove 'es' or 's' if present (from a previously conjugated form)
if verb:match("es$") thenend
 
verb = verb:sub(1, -3)
-- Preserve the original case without converting everything to uppercase
elseif verb:match("s$") then
if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then
verb = verb:sub(1, -2)
result = result:upper() -- Only convert to uppercase if both inputs were uppercase
end
end
-- Recombine with original pronoun, using modified verb if it was changed
return originalPronoun .. " " .. (verb == originalVerb:lower() and originalVerb or verb)
end
 
return result
end
 
function p.main(frame)
local originalPronoun = frame.args[1]
local verboriginalVerb = frame.args[2] -- This can be nil or empty
return adjustVerb(originalPronoun, verboriginalVerb) -- Adjust and return the result
end