Module:Sandbox/AbstractWikipedia/Functions/he

Module documentation
local p = {}

local l = require("Module:Sandbox/AbstractWikipedia/Lexemes")
local wd = require("Module:Sandbox/AbstractWikipedia/Wikidata")
local f = require("Module:Sandbox/AbstractWikipedia/Functions")

function p.Copula()
	local copula = l.newLexeme("הוא/היא", "verb")
	copula.addForm("הוא", { number = "singular", gender = "masculine"})
	copula.addForm("היא", { number = "singular", gender = "feminine"})
	copula.addForm("היה", { number = "singular", gender = "masculine", tense = "past"})
	copula.addForm("הייתה", { number = "singular", gender = "feminine", tense = "past"})
	-- Add more forms as needed
	return copula
end

-- Generates a pronoun lexeme; currently only third person.
-- If a q_id is given, the generated pronoun will correspond to that item,
-- otherwise a gender-variable pronoun is provided.
function p.Pronoun ( q_id )
	if q_id then 
		local gender = wd.getHumanGender(q_id)
		local lexeme 
		if gender == "masculine" then
			lexeme = f.Lexeme("L483496")  -- הוא
		elseif gender == "feminine" then
			lexeme = f.Lexeme("L483507") -- היא
		elseif gender == "other" then
			lexeme = f.Lexeme("L492143") -- הם
		else
			lexeme = f.Lexeme("L492094") -- זה
		end
		if (wd.isDead(q_id)) then
			-- We add a past tense feature for lexeme of dead people, as they are
			-- normally spoken about in the past tense. This can exposed to the
			-- verb by using the "tsubj relation".
			lexeme.addFeature("nominal_tense", "past")
		end
		lexeme.log()
		return lexeme
	else
		return f.GenderedLexeme("L483496", "L483507")  -- הוא / היא
	end
end

local month_name = {
	"ינואר",
	"פברואר",
	"מרץ",
	"אפריל",
	"מאי",
	"יוני",
	"יולי",
	"אוגוסט",
	"ספטמבר",
	"אוקטובר",
	"נובמבר",
	"דצמבר"
}


function p.Date ( date )
	local result = ''
	if date.day and tonumber(date.day) > 0 then
		result = result .. date.day
	end
	if date.month and tonumber(date.month) > 0 and tonumber(date.month) <=12 then
		if #result > 0 then
			result = result .. ' ב'
		end
		result = result .. month_name[tonumber(date.month)] .. ' '
	end
	if date.year and tonumber(date.year) ~= 0 then
		result = result .. date.year
	end
	return l.newLexeme ( result, "noun" )
end

-- Just a shortcat to the lexeme L718736 (preposition ב).
-- Due to BIDI, it is more convenient to use this rather then
-- hardcoding it in the template.
function p.In()
	return f.Lexeme("L718736")
end

-- Definite article (replaces the use of L7396)
function p.Art()
	local art = l.newLexeme("Definite article", "article", { definiteness = "definite"} )
	art.addForm("ה")
	return art	
end


-- An optional article, depending on the definiteness value of the slot
function p.OptArt()
	local art = l.newLexeme("Optional article", "article")
	art.addForm("", { definiteness = "indefinite"} )
	art.addForm("ה", { definiteness = "definite"})
	return art	
end


local ordinal_lexemes = { "L68024", "L219760", "L219694", "L218631", "L210998", "L219607", "L219209", "L219722", "L220459", "L216359" }

-- Constructs an ordinal lexeme out of number
function p.Ordinal ( number )
	numeric_value = math.floor(tonumber(number))
	if numeric_value > 0 and numeric_value < 11 then
		return f.Lexeme(ordinal_lexemes[numeric_value])
	end
	-- Ordinals above 10 in Hebrew are identical to cardinal numbers
	return l.newLexeme(tostring(number), "adjective")
end
	
return p