Module:Grammar: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 18: Line 18:


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


       local results = p.isplural(gender,pronoun)
       local results = p.isplural(gender,pronoun)
Line 39: Line 47:
       if (results == '0') then
       if (results == '0') then
         if (b == "are") then
         if (b == "are") then
             return "is"
             returnresults= "is"
         else
         else
             return b .. "s"
             returnresults= b .. "s"
         end
         end
       else  
       else  
         return b
         returnresults = b
      end
       end
       end
   else
   else
       return f
      returnresults = f
  end
  if (capitalized == true) then
       return (returnresults:gsub("^%l", string.upper))
  else
      return returnresults
   end
   end
  return "error"
   end
   end
end)
end)
Line 95: Line 108:
           return result[1]['pseudoplural']
           return result[1]['pseudoplural']
         else  
         else  
           if (result[1]['pseudoplural'] == '1' or resulttwo[1]['plural'] == '1') then
           if (result[1]['pseudoplural'] == true or resulttwo[1]['plural'] == true) then
    return '1'
    return '1'
           else
           else

Revision as of 01:46, 31 July 2019


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

function p.Main(frame)

gender = frame.args[2]

if (frame.args[3] ~= nil and frame.args[3] ~= '') then
   pronoun = frame.args[3]
else 
   pronounresult = cargo.query('Genders','defaultpronouns',{where='Gender="' .. gender .. '" AND _pageName="Gender and Pronouns"',limit='1'})
   if not next(pronounresult) then
      return "can't find a pronoun!"
   else 
      pronoun = pronounresult[1]['defaultpronouns']
   end
end

parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
 for a, b, c in string.gmatch(f, "(%w*)[:%.](%w*)(:?%w*)") do
   local capitalized = (string.gsub(b, "(^%w)", string.upper("%1")) == 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)) then
              returnstring = "these"
          else
              returnstring = "this"
          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
          returnstring = b
      else

      local results = p.isplural(gender,pronoun)
      
      if (results == '0') then
         if (b == "are") then
            returnresults= "is"
         else
            returnresults= b .. "s"
         end
      else 
         returnresults = b
      end
      end
   else
      returnresults = f
   end
   if (capitalized == true) then
      return (returnresults:gsub("^%l", string.upper))
   else 
      return returnresults
   end
  end
end)
return parsedtext
end

function p.parse(field, gender, pronoun)
    
    fields = field
    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
    local result= cargo.query(table,fields,args)
    if not next(result) then
        return nil
    else
	return result
    end
end

function p.isplural(gender,pronoun)
    fields= "pseudoplural"
    args = {
        where='pronoun="' .. pronoun .. '" AND _pageName="Gender and Pronouns"',
        limit='1'
    }
    local result= cargo.query('Pronouns',fields,args)
    local resulttwo= cargo.query('Genders','plural',{where='Gender="'..gender..'" AND _pageName="Gender and Pronouns"',
        limit='1'})
    if not next(result) then
        if not next(resulttwo) then
             return nil
        else 
             return resulttwo[1]['plural']
        end
    else
        if not next(resulttwo) then
          return result[1]['pseudoplural']
        else 
          if (result[1]['pseudoplural'] == true or resulttwo[1]['plural'] == true) 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