Module:Grammar

Revision as of 22:39, 30 July 2019 by Teamtoto (talk | contribs)

local p = {}
local cargo = mw.ext.cargo

function p.Main(frame)
for stripped in string.gmatch(frame.args[1], "=([^=]+)=") do
for a, b in string.gmatch(stripped, "(%w*)[:%.](%w*):?%w*") do
  if (a == "player") then
     return "(player's " .. b .. ")"
  elseif (a == "pronouns") then
     local results = p.parse(b, frame.args[2])
     if not results then 
	return "No results!"
     end
     return results[1][b]
  elseif (a == "verb") then
     local pron = frame.args[2]
     local results = p.isplural(pron)
     if not results then 
	return "No results!"
     end
     if (results[1]['pseudoplural'] == '0') then
       if (b == "are") then
          return "is"
       else
         return b .. "s"
       end
     else 
     return b
     end
  else
     return "ERROR"
  end
return "error"
end
end
end

function p.parse(field, pronoun)
    fields = field
    args = {
        where='pronoun="' .. pronoun .. '" AND _pageName="Gender and Pronouns"',
        limit='1'
    }
    local result= cargo.query('Pronouns',fields,args)
    if not next(result) then
        return nil
    else
	return result
    end
end

function p.isplural(pronoun)
    fields= "pseudoplural"
    args = {
        where='pronoun="' .. pronoun .. '" AND _pageName="Gender and Pronouns"',
        limit='1'
    }
    local result= cargo.query('Pronouns',fields,args)
    if not next(result) then
        return nil
    else
	return result
    end
end

function p.test(frame)
local strippedstring = "j"
local argument = frame.args[1]

return argument
end

return p