Module:Grammar: Difference between revisions

95 bytes removed ,  01:27, 16 February 2021
prevent parsing html
mNo edit summary
(prevent parsing html)
 
(19 intermediate revisions by one other user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo
local pronouns = require'Module:Grammar/PronounsTable'
local genders = require'Module:Grammar/GenderTable'
local conjugate = require'Module:Grammar/Conjugate'
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]
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
if pronouns[pronoun] == nil then
error ("There was no pronoun set named " .. (pronoun or "(no pronoun)").. "!")
end


if (frame.args[3] ~= nil and frame.args[3] ~= '') then
progentable = {
  pronoun = frame.args[3]
    ["subjective"] = pronouns[pronoun]["subjective"],
else
    ["objective"] = pronouns[pronoun]["objective"],
  pronounresult = cargo.query('Genders','defaultpronouns',{where='Gender="' .. gender .. '" AND _pageName="Gender and Pronouns"',limit='1'})
    ["possessive"] = pronouns[pronoun]["possessive"],
  if not next(pronounresult) then
    ["substantivepossessive"] = pronouns[pronoun]["substantivepossessive"],
      return "can't find a pronoun!"
    ["reflexive"] = pronouns[pronoun]["reflexive"],
  else
    ["pseudoplural"] = pronouns[pronoun]["pseudoplural"],
      pronoun = pronounresult[1]['defaultpronouns']
    ["plural"] = pronouns[pronoun]["plural"] or genders[gender]["plural"],
  end
    ["personterm"] = pronouns[pronoun]["personterm"] or genders[gender]["personterm"],
    ["immaturepersonterm"] = pronouns[pronoun]["immaturepersonterm"] or genders[gender]["immaturepersonterm"],
    ["formaladdressterm"] = pronouns[pronoun]["formaladdressterm"] or genders[gender]["formaladdressterm"],
    ["offspringterm"] = pronouns[pronoun]["offspringterm"] or genders[gender]["offspringterm"],
    ["siblingterm"] = pronouns[pronoun]["siblingterm"] or genders[gender]["siblingterm"],
    ["parentterm"] = pronouns[pronoun]["parentterm"] or genders[gender]["parentterm"]
              }
local bmakeplural = false
parsedtext = string.gsub(frame.args[1], '=([^=<>"]+)=', parse)
return parsedtext
end
end


parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
function p.progenize(field, gender, pronoun)
for a, b, c in string.gmatch(f, "(%w*)[:%.]?(['%w]*)(:?%w*)") do
    return progentable[field]
  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 == "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
end


function p.parse(field, gender, pronoun)
function p.isplural(gender,pronoun)
   
     if (pronoun~=nil) then
    fields = field
      return pronouns[pronoun]['pseudoplural']
     if (string.find(field, "term", -4) ~= nil) then
    table = 'Genders'
    args = {where='Gender="' .. gender .. '" AND _pageName="Gender and Pronouns"', limit='1'}
    else
    table = 'Pronouns'
    args = {
        where='pronoun="' .. pronoun .. '" AND _pageName="Gender and Pronouns"',
        limit='1'
    }
     end
     end
     local result= cargo.query(table,fields,args)
     if progentable["pseudoplural"] == '1' or progentable["plural"] == '1' then
    if not next(result) then
      return '1'
        return nil
     else
     else
return result
      return '0'
     end
     end
end
end


function p.isplural(gender,pronoun)
function parse(f)
    fields= "pseudoplural"
for a, b, c in string.gmatch(f, "(%w*)[:%.]?(['%w]*)(:?%w*)") do
    args = {
if b == nil or b == "" then
        where='pronoun="' .. pronoun .. '" AND _pageName="Gender and Pronouns"',
    if a == "article" then
        limit='1'
      return "a "
    }
    elseif a == "pluralize" then
    local result= cargo.query('Pronouns',fields,args)
      bmakeplural = true
    local resulttwo= cargo.query('Genders','plural',{where='Gender="'..gender..'" AND _pageName="Gender and Pronouns"',
      return ""
        limit='1'})
    else
    if not next(result) then
      return "="..a.."="
        if not next(resulttwo) then
    end
            return nil
else
        else  
local capitalized = ((b:gsub("^%l", string.upper)) == string.gsub(b,"(^%w)","%1"))
            return resulttwo[1]['plural']
returnstring = ""
        end
b = string.lower(b)
    else
if (a == "name") then
        if not next(resulttwo) then
    returnstring = "(player's name)"
          return result[1]['pseudoplural']
elseif (a == "player") then
        else
    returnstring = "(player's " .. b .. ")"
          if (result[1]['pseudoplural'] == '1' or resulttwo[1]['plural'] == '1') then
elseif (a == "pronouns") then
    return '1'
    if (b == "indicativeproximal") then
          else
      if (p.isplural(gender,pronoun) == '0') then
            return '0'
          returnstring = "this"
          end
      else
        end
          returnstring = "these"
    end
      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
function p.test()
text="=pluralize==pronouns.personTerm="
gender = "male"
pronoun = ""


function p.test(frame)
local f = {["args"] = {[1]= text, [2] = gender, [3] = pronoun }}
local strippedstring = "j"
return p.Main(f)
local argument = frame.args[1]
for s in string.gmatch(argument, "=([^=]+)=") do
strippedstring = strippedstring .. s
end
return strippedstring
end
end


return p
return p