Module:Grammar: Difference between revisions

131 bytes removed ,  01:27, 16 February 2021
prevent parsing html
No edit summary
(prevent parsing html)
 
(9 intermediate revisions by one other user not shown)
Line 2: Line 2:
local pronouns = require'Module:Grammar/PronounsTable'
local pronouns = require'Module:Grammar/PronounsTable'
local genders = require'Module:Grammar/GenderTable'
local genders = require'Module:Grammar/GenderTable'
local conjugate = require'Module:Grammar/Conjugate'
local progentable = {}
local progentable = {}
function p.Main(frame)
function p.Main(frame)
gender = frame.args[2]


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


progentable = {
progentable = {
     ["subjective"] = pronouns[pronoun]["subjective"],
     ["subjective"] = pronouns[pronoun]["subjective"],
     ["objective"] = pronouns[pronoun]["objective"],
     ["objective"] = pronouns[pronoun]["objective"],
Line 33: Line 38:
     ["parentterm"] = pronouns[pronoun]["parentterm"] or genders[gender]["parentterm"]
     ["parentterm"] = pronouns[pronoun]["parentterm"] or genders[gender]["parentterm"]
               }
               }
 
local bmakeplural = false
parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
parsedtext = string.gsub(frame.args[1], '=([^=<>"]+)=', parse)
for a, b, c in string.gmatch(f, "(%w*)[:%.]?(['%w]*)(:?%w*)") do
return parsedtext
  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 = parse(b)
        if results == nil then
  returnstring = "No results!"
        end
          returnstring = results
      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 = 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
end


local function parse(field, gender, pronoun)
function p.progenize(field, gender, pronoun)
     return progentable[field]
     return progentable[field]
end
end


local function isplural(gender,pronoun)
function p.isplural(gender,pronoun)
    if (pronoun~=nil) then
      return pronouns[pronoun]['pseudoplural']
    end
     if progentable["pseudoplural"] == '1' or progentable["plural"] == '1' then
     if progentable["pseudoplural"] == '1' or progentable["plural"] == '1' then
       return '1'
       return '1'
Line 127: Line 58:
end
end


local function test(frame)
function parse(f)
local strippedstring = "j"
for a, b, c in string.gmatch(f, "(%w*)[:%.]?(['%w]*)(:?%w*)") do
local argument = frame.args[1]
if b == nil or b == "" then
for s in string.gmatch(argument, "=([^=]+)=") do
    if a == "article" then
strippedstring = strippedstring .. s
      return "a "
    elseif a == "pluralize" then
      bmakeplural = true
      return ""
    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.progenize(b)
      if results == nil then
returnstring = "No results!"
      end
      returnstring = results
    end
elseif (a == "verb") then
    if (c == nil or c == '') then --[if no :afterpronoun]
      returnstring = conjugate.singularverb(b)
    elseif (p.isplural() == '0') then --[if not plural, singularize]
      returnstring = conjugate.singularverb(b)
    else
      returnstring = b
    end
else
    returnstring = f
end
-- If pluralize is true, pluralize result
if bmakeplural == true then
    returnstring = conjugate.pluralize(returnstring)
    bmakeplural = false
end
if (capitalized == true) then
    return (returnstring:gsub("^%l", string.upper))
else
    return returnstring
end
end
end
end
end
return strippedstring
function p.test()
text="=pluralize==pronouns.personTerm="
gender = "male"
pronoun = ""
 
local f = {["args"] = {[1]= text, [2] = gender, [3] = pronoun }}
return p.Main(f)
end
end


return p
return p