Module:Lexeme-en

From Wikidata
Jump to navigation Jump to search
Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules

Documentation for this module may be created at Module:Lexeme-en/doc

Code

local lb = require('Module:LexemeBuilder')
local p = {}
local text = lb.MultilingualText

function p.noun(word,plural)
	if type(word)=='table' then
		if word.parent and word.parent.args and word.parent.args[1] then
			word=word.parent
		end
		word,plural=word.args[1],word.args[2]
	end
	local entity=lb.newLexeme("Q1860", "Q1084", text({en=word}))
	if not plural or plural=='' then
    	plural=word.."s"
    	plural=string.gsub(plural,"([^aeiou])ys$","%1ies" )
    	plural=string.gsub(plural,"ss$","ses" )
    	plural=string.gsub(plural,"zs$","zes" )
    	plural=string.gsub(plural,"chs$","ches" )
    	plural=string.gsub(plural,"shs$","shes" )
    end
	entity=lb.addForm(entity,lb.newForm(text({en=word}),"Q110786"))
	entity=lb.addForm(entity,lb.newForm(text({en=plural}),"Q146786"))
	return lb.Export(entity)
end

function p.verb(word,pat,pap,prp,prs)
	if type(word)=='table' then
		if word.parent and word.parent.args and word.parent.args[1] then
			word=word.parent
		end
		word,prp,pat,pap,prs=word.args[1],word.args[2],word.args[3],word.args[4],word.args[5]
	end
	local entity=lb.newLexeme("Q1860", "Q24905", text({en=word}))
	if not pat or pat=='' then
    	pat=word.."ed"
    	pat=string.gsub(pat,"eed$","ed" )
    	pat=string.gsub(pat,"([^aeiou])yed$","%1ied" )
    	pat=string.gsub(pat,"^([^aeiou]+)([aeiou])([ptmngrcb])ed$","%1%2%3%3ed" )
    	pat=string.gsub(pat,"cced$","cked" )
    end
	if not pap or pap=='' then
    	pap=pat
    end
	if not prp or prp=='' then
    	prp=word.."ing"
    	prp=string.gsub(prp,"([^aeiou])eing$","%1ing" )
    	prp=string.gsub(prp,"^([^aeiou]+)([aeiou])([ptmngrcb])ing$","%1%2%3%3ing" )
    end
	if not prs or prs=='' then
    	prs=word.."s"
    	prs=string.gsub(prs,"([^aeiou])ys$","%1ies" )
    	prs=string.gsub(prs,"ss$","ses" )
    	prs=string.gsub(prs,"zs$","zes" )
    	prs=string.gsub(prs,"chs$","ches" )
    	prs=string.gsub(prs,"shs$","shes" )
    	prs=string.gsub(prs,"os$","oes" )
    end
	entity=lb.addForm(entity,lb.newForm(text({en=word}),"Q3910936"))
	entity=lb.addForm(entity,lb.newForm(text({en=prs}),{"Q3910936","Q51929447"}))
	entity=lb.addForm(entity,lb.newForm(text({en=pat}),"Q1392475"))
	entity=lb.addForm(entity,lb.newForm(text({en=pap}),"Q1230649"))
	entity=lb.addForm(entity,lb.newForm(text({en=prp}),"Q10345583"))
	return lb.Export(entity)
end
return p