Module:Grammar/Conjugate: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
m (oops)
(improved pluralization for things with "of" in the name (drops of nectar, clumps of grave moss, knight commanders of the holy temple, etc))
(7 intermediate revisions by 3 users not shown)
Line 2: Line 2:


function p.pluralize(str, apostrophe)
function p.pluralize(str, apostrophe)
apostrophe = apostrophe or ''
apostrophe = apostrophe or ''
local irregularplurals = {}
local irregularplurals = {
 
        Man = 'Men',
if (str:sub(-1) == 's') then
    man = 'men'
        return (str .. apostrophe)  --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
}
    elseif (string.sub(str, -1) == 'y') and apostrophe == '' then
if irregularplurals[str] ~= nil then
        return (string.sub(str, 1, -2) ..  'ies')
    return irregularplurals[str]
     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) == 's') then
         return (str ..  'es')
return (str .. apostrophe)  --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
    else
elseif (string.sub(str, -2) == 'ey') and apostrophe == '' then
        return (str.. apostrophe .. 's')
    return (str .. 's')  --for example, "lamprey"
    end
elseif (string.sub(str, -1) == 'y') and apostrophe == '' then
    return (string.sub(str, 1, -2) ..  'ies')
     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 (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
end


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


function p.singularverb(string)
function p.singularverb(string)
  --[ Assumes the input string is already a plural verb.]
--[ Assumes the input string is already a plural verb.]
  local irregularsingulars = {
local irregularsingulars = {
     ["are"] = 'is',
     ["are"] = 'is',
    ["were"] = 'was',
     ["have"] = 'has',
     ["have"] = 'has',
     ["'re"] = "'s",
     ["'re"] = "'s",
     ["don't"] = "doesn't",
     ["don't"] = "doesn't",
     ["'ve"] = "'s"
     ["'ve"] = "'s",
  }
    ["do"] = "does"
  local result = irregularsingulars[string]
}
  if result ~= nil and result ~= '' then
local result = irregularsingulars[string]
    return result
if result ~= nil and result ~= '' then
  else
    return result
    return string .. "s"
else
  end
    return string .. "s"
end
end
end
function p.capitalize(str)
return str:gsub("^%l", string.upper)
end


return p
return p

Revision as of 19:16, 28 January 2022


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 (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.find(str, ' of ')) then
        i = string.find(str, ' of ')
        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
        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
    	return string .. "s"
	end
end

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

return p