Module:Grammar: Difference between revisions
Jump to navigation
Jump to search
(split conjugate into its own module so both grammar and htmlparse can use) |
mNo edit summary |
||
Line 17: | Line 17: | ||
pronoun = pronounresult | pronoun = pronounresult | ||
end | end | ||
end | |||
if pronouns[pronoun] == nil then | |||
error ("There was no pronoun set named " .. (pronoun or "(no pronoun)").. "!") | |||
end | end | ||
Line 66: | Line 69: | ||
end | end | ||
elseif (a == "verb") then | elseif (a == "verb") then | ||
if (c == nil or c == '') then | if (c == nil or c == '') then --[if no :afterpronoun] | ||
returnstring = conjugate.singularverb(b) | returnstring = conjugate.singularverb(b) | ||
elseif (p.isplural( | elseif (p.isplural() == '0') then --[if not plural, singularize] | ||
returnstring = conjugate.singularverb(b) | returnstring = conjugate.singularverb(b) | ||
else | else | ||
Line 93: | Line 96: | ||
function p.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 101: | Line 107: | ||
function p.test() | function p.test() | ||
text=" | text="Before you =verb:recline= =article==pronouns.personTerm= clothed in leafy raiment, so svelte and still you mistake =pronouns.objective= for the fallen branch of a sickly tree until you meet the gaze of =pronouns.possessive= cerulean eyes. Upon closer scrutiny, you discern the hilts of =pronouns.possessive= twin swords, Caslainard and Polluxus, rising through the foliage of =pronouns.possessive= cloak and over =pronouns.possessive= shoulders. =pronouns.Possessive= sylvan sashes, of which =pronouns.subjective= =verb:wear:afterpronoun= several, are strewn with the ears, claws, and horns of creatures unfamiliar to you, and as you examine them, =pronouns.subjective= =verb:scrutinize:afterpronoun= you wearing an expression that bears qualities of both a smirk and a scowl yet that is not quite either." | ||
gender = "male" | gender = "male" | ||
pronoun = " | pronoun = "" | ||
local f = {["args"] = {[1]= text, [2] = gender, [3] = pronoun }} | local f = {["args"] = {[1]= text, [2] = gender, [3] = pronoun }} |
Revision as of 17:18, 1 October 2019
local p = {}
local pronouns = require'Module:Grammar/PronounsTable'
local genders = require'Module:Grammar/GenderTable'
local conjugate = require'Module:Grammar/Conjugate'
local progentable = {}
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
if pronouns[pronoun] == nil then
error ("There was no pronoun set named " .. (pronoun or "(no pronoun)").. "!")
end
progentable = {
["subjective"] = pronouns[pronoun]["subjective"],
["objective"] = pronouns[pronoun]["objective"],
["possessive"] = pronouns[pronoun]["possessive"],
["substantivepossessive"] = pronouns[pronoun]["substantivepossessive"],
["reflexive"] = pronouns[pronoun]["reflexive"],
["pseudoplural"] = pronouns[pronoun]["pseudoplural"],
["plural"] = pronouns[pronoun]["plural"] or genders[gender]["plural"],
["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"]
}
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)
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 (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)
return progentable[field]
end
function p.isplural(gender,pronoun)
if (pronoun~=nil) then
return pronouns[pronoun]['pseudoplural']
end
if progentable["pseudoplural"] == '1' or progentable["plural"] == '1' then
return '1'
else
return '0'
end
end
function p.test()
text="Before you =verb:recline= =article==pronouns.personTerm= clothed in leafy raiment, so svelte and still you mistake =pronouns.objective= for the fallen branch of a sickly tree until you meet the gaze of =pronouns.possessive= cerulean eyes. Upon closer scrutiny, you discern the hilts of =pronouns.possessive= twin swords, Caslainard and Polluxus, rising through the foliage of =pronouns.possessive= cloak and over =pronouns.possessive= shoulders. =pronouns.Possessive= sylvan sashes, of which =pronouns.subjective= =verb:wear:afterpronoun= several, are strewn with the ears, claws, and horns of creatures unfamiliar to you, and as you examine them, =pronouns.subjective= =verb:scrutinize:afterpronoun= you wearing an expression that bears qualities of both a smirk and a scowl yet that is not quite either."
gender = "male"
pronoun = ""
local f = {["args"] = {[1]= text, [2] = gender, [3] = pronoun }}
return p.Main(f)
end
return p