Module:Grammar/Conjugate

From Caves of Qud Wiki
< Module:Grammar
Revision as of 16:00, 19 September 2019 by Teamtoto (talk | contribs) (Created page with "local p = {} function p.pluralize(str, apostrophe) apostrophe = apostrophe or '' local irregularplurals = {} if (str:sub(-1) == 's') then return (str .. apostrophe)...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

local p = {}

function p.pluralize(str, apostrophe)
apostrophe = apostrophe or ''
local irregularplurals = {}

if (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, -1) == 'y') and apostrophe == '' then
        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
        return (str ..  'es')
    else
        return (str.. apostrophe .. 's')
    end
end

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

function p.singularverb(string)
  local irregularsingulars = {
     ["are"] = 'is',
     ["have"] = 'has',
     ["'re"] = "'s",
     ["don't"] = "doesn't",
     ["'ve"] = "'s"
  }
  local result = irregularsingulars[string]
  if result ~= nil and result ~= '' then
    return result
  else 
    return string
  end
end

return p