Module:Grammar/Conjugate: Difference between revisions

capitalize
mNo edit summary
(capitalize)
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'
    man = 'men'
  }
}
  if irregularplurals[str] ~= nil then
if irregularplurals[str] ~= nil then
    return irregularplurals[str]
    return irregularplurals[str]
  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')
  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 (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
    return (str ..  'es')
    return (str ..  'es')
  else
else
    return (str.. apostrophe .. 's')
    return (str.. apostrophe .. 's')
  end
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',
     ["were"] = 'was',
Line 32: Line 32:
     ["don't"] = "doesn't",
     ["don't"] = "doesn't",
     ["'ve"] = "'s"
     ["'ve"] = "'s"
  }
}
  local result = irregularsingulars[string]
local result = irregularsingulars[string]
  if result ~= nil and result ~= '' then
if result ~= nil and result ~= '' then
    return result
    return result
  else
else
    return string .. "s"
    return string .. "s"
  end
end
end
end
function p.capitalize(str)
str = str.args and str.args[1] or str
return str:gsub("^%l", string.upper)
end


return p
return p