Module:Grammar: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 3: | Line 3: | ||
function p.Main(frame) | function p.Main(frame) | ||
gender = frame.args[2] | |||
if (frame.args[3] ~= nil) then | |||
pronoun = frame.args[3] | |||
else | |||
pronoun = cargo.query('Genders','defaultpronouns',{where='Gender="' .. gender .. '" AND _pageName="Gender and Pronouns"',limit='1'}) | |||
end | |||
parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f) | parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f) | ||
for a, b in string.gmatch(string.lower(f), "(%w*)[:%.](%w*):?%w*") do | for a, b, c in string.gmatch(string.lower(f), "(%w*)[:%.](%w*):?(%w*)") do | ||
if (a == "player") then | if (a == "player") then | ||
return "(player's " .. b .. ")" | return "(player's " .. b .. ")" | ||
elseif (a == "pronouns") then | elseif (a == "pronouns") then | ||
local results = p.parse(b, | local results = p.parse(b, gender, pronouns) | ||
if not results then | if not results then | ||
return "No results!" | return "No results!" | ||
Line 14: | Line 23: | ||
return results[1][b] | return results[1][b] | ||
elseif (a == "verb") then | elseif (a == "verb") then | ||
if (c == nil or c == "") then | |||
return b | |||
end | end | ||
if (results | |||
local results = p.isplural(gender,pronoun) | |||
if (results == '0') then | |||
if (b == "are") then | if (b == "are") then | ||
return "is" | |||
else | else | ||
return b .. "s" | return b .. "s" | ||
end | |||
else | else | ||
return b | return b | ||
Line 31: | Line 41: | ||
return "ERROR" | return "ERROR" | ||
end | end | ||
return "error" | |||
end | |||
end) | end) | ||
return parsedtext | return parsedtext | ||
end | end | ||
function p.parse(field, pronoun) | function p.parse(field, gender, pronoun) | ||
fields = field | fields = field | ||
args = { | args = { | ||
Line 51: | Line 62: | ||
end | end | ||
function p.isplural(pronoun) | function p.isplural(gender,pronoun) | ||
fields= "pseudoplural" | fields= "pseudoplural" | ||
args = { | args = { | ||
Line 58: | Line 69: | ||
} | } | ||
local result= cargo.query('Pronouns',fields,args) | 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(result) then | ||
return nil | if not next(resulttwo) then | ||
return nil | |||
else | |||
return resulttwo[1]['plural'] | |||
end | |||
else | else | ||
if not next(resulttwo) then | |||
return result[1]['pseudoplural'] | |||
else | |||
if (result[1]['pseudoplural'] or resulttwo[1]['plural']) then | |||
return 1 | |||
else | |||
return 0 | |||
end | |||
end | |||
end | end | ||
end | end |
Revision as of 23:57, 30 July 2019
local p = {}
local cargo = mw.ext.cargo
function p.Main(frame)
gender = frame.args[2]
if (frame.args[3] ~= nil) then
pronoun = frame.args[3]
else
pronoun = cargo.query('Genders','defaultpronouns',{where='Gender="' .. gender .. '" AND _pageName="Gender and Pronouns"',limit='1'})
end
parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
for a, b, c in string.gmatch(string.lower(f), "(%w*)[:%.](%w*):?(%w*)") do
if (a == "player") then
return "(player's " .. b .. ")"
elseif (a == "pronouns") then
local results = p.parse(b, gender, pronouns)
if not results then
return "No results!"
end
return results[1][b]
elseif (a == "verb") then
if (c == nil or c == "") then
return b
end
local results = p.isplural(gender,pronoun)
if (results == '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)
return parsedtext
end
function p.parse(field, gender, 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(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'] or resulttwo[1]['plural']) 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