Module:Pronoun: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
} |
} |
||
-- Determines if the input is fully uppercase |
|||
⚫ | |||
local function |
local function isAllCaps(s) |
||
return s:upper() == s |
|||
end |
|||
⚫ | |||
local function adjustVerb(originalPronoun, originalVerb) |
|||
local pronoun = originalPronoun:lower() -- Use lowercase for logic |
local pronoun = originalPronoun:lower() -- Use lowercase for logic |
||
local |
local verb = originalVerb:lower() -- Use lowercase for logic |
||
verb = verb:lower() -- Use lowercase for logic |
|||
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 |
||
local aux = pronoun == "they" and "are" or "is" |
|||
result = originalPronoun .. " " .. aux .. " " .. originalVerb |
|||
elseif pronoun == "they" then |
|||
⚫ | |||
⚫ | |||
else |
else |
||
-- Simple present tense for singular third-person |
-- Simple present tense for singular third-person |
||
Line 29: | Line 31: | ||
verb = specialCases[verb] or verb -- Apply special case if exists |
verb = specialCases[verb] or verb -- Apply special case if exists |
||
if not verb:match("s$") then |
if not verb:match("s$") then |
||
verb = verb .. (needsEsEnding(verb) and "es" or "s") |
|||
verb = verb .. "es" |
|||
else |
|||
verb = verb .. "s" |
|||
end |
|||
end |
end |
||
elseif pronoun == "they" then |
elseif pronoun == "they" then |
||
-- |
-- Adjusting back from special cases if needed |
||
for base, conjugated in pairs(specialCases) do |
for base, conjugated in pairs(specialCases) do |
||
if verb == conjugated then |
if verb == conjugated then |
||
verb = base |
verb = base |
||
end |
end |
||
end |
end |
||
-- Remove 'es' or 's' if present |
-- Remove 'es' or 's' if present |
||
if verb:match("es$") then |
if verb:match("es$") then |
||
verb = verb:sub(1, -3) |
verb = verb:sub(1, -3) |
||
Line 49: | Line 47: | ||
end |
end |
||
end |
end |
||
⚫ | |||
-- Recombine with original pronoun, using modified verb if it was changed |
|||
⚫ | |||
return originalPronoun .. " " .. (verb == originalVerb:lower() and originalVerb or verb) |
|||
-- Adjust the result for all caps |
|||
if isAllCaps(originalPronoun) and isAllCaps(originalVerb) then |
|||
result = result:upper() |
|||
end |
end |
||
return result |
|||
end |
end |
||
function p.main(frame) |
function p.main(frame) |
||
local originalPronoun = frame.args[1] |
local originalPronoun = frame.args[1] |
||
local |
local originalVerb = frame.args[2] |
||
return adjustVerb(originalPronoun, |
return adjustVerb(originalPronoun, originalVerb) -- Adjust and return result |
||
end |
end |
||
Revision as of 19:23, 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 input 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 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