Module:Grammar/Conjugate: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
improved pluralization for things with "of" in the name (drops of nectar, clumps of grave moss, knight commanders of the holy temple, etc)
Starfungus (talk | contribs)
changes singularverb to properly conjugate verbs like "flash" as in Isahind's description to be "flashes" instead of "flashs"
 
(3 intermediate revisions by one other user not shown)
Line 9: Line 9:
if irregularplurals[str] ~= nil then
if irregularplurals[str] ~= nil then
     return irregularplurals[str]
     return irregularplurals[str]
    elseif (string.find(str, ' of ')) then
        i = string.find(str, ' of ')
        return p.pluralize(string.sub(str, 1, i-1)) .. string.sub(str, i)
    elseif (string.find(str, ' with ')) then
        i = string.find(str, ' with ')
        return p.pluralize(string.sub(str, 1, i-1)) .. string.sub(str, i)
elseif (str:sub(-1) == 's') then
elseif (str:sub(-1) == 's') then
return (str .. apostrophe)  --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
return (str .. apostrophe)  --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
Line 15: Line 21:
elseif (string.sub(str, -1) == 'y') and apostrophe == '' then
elseif (string.sub(str, -1) == 'y') and apostrophe == '' then
     return (string.sub(str, 1, -2) ..  'ies')
     return (string.sub(str, 1, -2) ..  'ies')
     elseif (string.find(str, ' of ')) then
     elseif (string.sub(str, -3) == 'ife') and apostrophe == '' then
        i = string.find(str, ' of ')
         return (string.sub(str, 1, -4) .. 'ives')
         return p.pluralize(string.sub(str, 1, i-1)) .. string.sub(str, i)
elseif (str:sub(-1) == 'z' or str:sub(-2) == 'ch' or str:sub(-2) == 'sh' or str:sub(-1) == 'x') and apostrophe == '' then
elseif (str:sub(-1) == 'z' or str:sub(-2) == 'ch' or str:sub(-2) == 'sh' or str:sub(-1) == 'x') and apostrophe == '' then
         if (str:sub(-6) == 'vortex') then  --special case, capitalize vortex the same way the game does in in-game text like Quantum Jitters description
         if (str:sub(-6) == 'vortex') then  --special case, capitalize vortex the same way the game does in in-game text like Quantum Jitters description
Line 47: Line 52:
     return result
     return result
else
else
if (string:sub(-1) == 'z' or string:sub(-2) == 'ch' or string:sub(-2) == 'sh' or string:sub(-1) == 'x') then
return string .. "es"
end
     return string .. "s"
     return string .. "s"
end
end

Latest revision as of 20:01, 18 May 2025


local p = {}

function p.pluralize(str, apostrophe)
	apostrophe = apostrophe or ''
	local irregularplurals = {
        Man = 'Men',
    	man = 'men'
	}
	if irregularplurals[str] ~= nil then
    	return irregularplurals[str]
    elseif (string.find(str, ' of ')) then
        i = string.find(str, ' of ')
        return p.pluralize(string.sub(str, 1, i-1)) .. string.sub(str, i)
    elseif (string.find(str, ' with ')) then
        i = string.find(str, ' with ')
        return p.pluralize(string.sub(str, 1, i-1)) .. string.sub(str, i)
	elseif (str:sub(-1) == 's') then
		return (str .. apostrophe)   --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
	elseif (string.sub(str, -2) == 'ey') and apostrophe == '' then
    	return (str .. 's')   --for example, "lamprey"
	elseif (string.sub(str, -1) == 'y') and apostrophe == '' then
    	return (string.sub(str, 1, -2) ..  'ies')
    elseif (string.sub(str, -3) == 'ife') and apostrophe == '' then
        return (string.sub(str, 1, -4) .. 'ives')
	elseif (str:sub(-1) == 'z' or str:sub(-2) == 'ch' or str:sub(-2) == 'sh' or str:sub(-1) == 'x') and apostrophe == '' then
        if (str:sub(-6) == 'vortex') then  --special case, capitalize vortex the same way the game does in in-game text like Quantum Jitters description
            return (string.sub(str, 1, -3) .. 'ices')
        end
    	return (str ..  'es')
	else
    	return (str.. apostrophe .. 's')
	end
end

function p.make_possessive(string)
	return p.pluralize(string, "'")
end

function p.singularverb(string)
	--[ Assumes the input string is already a plural verb.]
	local irregularsingulars = {
     ["are"] = 'is',
     ["were"] = 'was',
     ["have"] = 'has',
     ["'re"] = "'s",
     ["don't"] = "doesn't",
     ["'ve"] = "'s",
     ["do"] = "does"
	}
	local result = irregularsingulars[string]
	if result ~= nil and result ~= '' then
    	return result
	else
		if (string:sub(-1) == 'z' or string:sub(-2) == 'ch' or string:sub(-2) == 'sh' or string:sub(-1) == 'x') then
			return string .. "es"
		end
    	return string .. "s"
	end
end

function p.capitalize(str)
	return str:gsub("^%l", string.upper)
end 

return p