Module:Grammar

Revision as of 16:32, 12 September 2019 by Teamtoto (talk | contribs)

local p = {}
local pronouns = require'Module:Grammar/PronounsTable'
local genders = require'Module:Grammar/GenderTable'

local cargo = mw.ext.cargo

--[TODO: do something about oboroqoru's He/Him/His/His/Himself/god/godling/lord/Son/Brother/Father pronouns]--
function p.Main(frame)

gender = frame.args[2]

if (frame.args[3] ~= nil and frame.args[3] ~= '') then
   pronoun = frame.args[3]
else 
   pronounresult = genders[gender]['defaultpronouns']
   if (pronounresult == nil) then
      error ("can't find a pronoun for gender" .. (gender or "(no gender)") .. "!")
   else 
      pronoun = pronounresult
   end
end

parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
 for a, b, c in string.gmatch(f, "(%w*)[:%.]?(['%w]*)(:?%w*)") do
   if b == nil or b == "" then
       if a == "article" then
         return "a "
       else
         return "="..a.."="
       end
   else
   local capitalized = ((b:gsub("^%l", string.upper)) == string.gsub(b,"(^%w)","%1"))
   returnstring = ""
   b = string.lower(b)
   if (a == "name") then
      returnstring = "(player's name)"
   elseif (a == "player") then
      returnstring = "(player's " .. b .. ")"
   elseif (a == "pronouns") then
      if (b == "indicativeproximal") then
          if (p.isplural(gender,pronoun) == '0') then
              returnstring = "this"
          else
              returnstring = "these"
          end
      else 
        local results = p.parse(b, gender, pronoun)
        if not results then 
	  returnstring = "No results!"
        end
          returnstring = results[1][b]
      end
   elseif (a == "verb") then
      if (c == nil or c == '') then
         if (b == "are") then
            returnstring= "is"
         elseif (b == "have") then
            returnstring= "has"
         elseif (b == "'re") then
            returnstring= "'s"
         elseif (b =="don't") then
            returnstring= "doesn't"
         elseif (b== "'ve") then
            returnstring="'s"
         else
            returnstring= b .. "s"
         end
      else

      local results = p.isplural(gender,pronoun)
      
      if (results == '0') then
         if (b == "are") then
            returnstring= "is"
         elseif (b == "have") then
            returnstring= "has"
         elseif (b == "'re") then
            returnstring= "'s"
         elseif (b == "don't") then
            returnstring= "doesn't"
         elseif (b== "'ve") then
            returnstring="'s"
         else
            returnstring= b .. "s"
         end
      else 
         returnstring= b
      end
      end
   else
      returnstring= f
   end
   if (capitalized == true) then
      return (returnstring:gsub("^%l", string.upper))
   else 
      return returnstring
   end
  end
  end
end)
return parsedtext
end

function p.parse(field, gender, pronoun)
    fields = field

    local result
    if (string.find(field, "term", -4) ~= nil) then
     result = genders[gender][fields]
    else 
     result = pronouns[pronoun][fields]
    end
    return result
end

function p.isplural(gender,pronoun)
    local result = pronouns[pronoun]['pseudoplural']
    local resulttwo = genders[gender]['plural']

    if (result == nil) then
        return resulttwo or nil
    else
        if (resulttwo == nil) then
          return result[1]['pseudoplural']
        else 
          if (result == 1 or resulttwo == 1) then
	     return '1'
          else
             return '0'
          end
        end
    end
end

function p.test(frame)
local strippedstring = "j"
local argument = frame.args[1]
for s in string.gmatch(argument, "=([^=]+)=") do
 strippedstring = strippedstring .. s
end
return strippedstring
end

return p