Модуль:Wdl-ru-noun
Для документации этого модуля может быть создана страница Модуль:Wdl-ru-noun/Документация
local p = {}
-- Return the first form of the lexeme which has exactly the given grammatical feature.
local function formWithSingleGrammaticalFeature( lexeme, item_id )
for i, form in pairs( lexeme:getForms() ) do
local grammaticalFeatures = form:getGrammaticalFeatures()
if #grammaticalFeatures == 1 and grammaticalFeatures[1] == item_id then
return form
end
end
return nil
end
-- Return the first form of the lexeme which has exactly the given 2 grammatical features.
local function formWithDoubleGrammaticalFeature( lexeme, id1, id2 )
for i, form in pairs( lexeme:getForms() ) do
local grammaticalFeatures = form:getGrammaticalFeatures()
if #grammaticalFeatures == 2 and (grammaticalFeatures[1] == id1 and grammaticalFeatures[2] == id2 or grammaticalFeatures[2] == id1 and grammaticalFeatures[1] == id2) then
return form
end
end
return nil
end
-- Return the representation of the form in the given language code,
-- or the first representation otherwise.
local function representationInLanguage( form, language_code )
local representation, language = form:getRepresentation( language_code )
if representation then
return { representation, language }
else
return form:getRepresentations()[1]
end
end
local function termSpan( term )
local text = term[1]
local lang = term[2]
local dir = mw.language.new( lang ):getDir()
local span = mw.html.create( 'span' )
span:attr( 'lang', lang ) -- TODO T310581
:attr( 'dir', dir )
:wikitext( text )
return tostring( span )
end
local function NumberCase( lexeme_id, item_id1, item_id2 )
local lexeme = mw.wikibase.getEntity( lexeme_id )
local form = formWithDoubleGrammaticalFeature( lexeme, item_id1, item_id2 )
if form == nil then
return "''нет формы''"
end
local representation = representationInLanguage( form, 'ru' )
return termSpan( representation )
end
function p.singular( frame )
if frame.args[1] == 'nominative' then return NumberCase( frame.args[2], 'Q110786', 'Q131105' )
elseif frame.args[1] == 'genetive' then return NumberCase( frame.args[2], 'Q110786', 'Q146233' )
elseif frame.args[1] == 'accusative' then return NumberCase( frame.args[2], 'Q110786', 'Q146078' )
elseif frame.args[1] == 'dative' then return NumberCase( frame.args[2], 'Q110786', 'Q145599' )
elseif frame.args[1] == 'instrumentative' then return NumberCase( frame.args[2], 'Q110786', 'Q192997' )
elseif frame.args[1] == 'prepositive' then return NumberCase( frame.args[2], 'Q110786', 'Q2114906' )
elseif frame.args[1] == 'locaive' then return NumberCase( frame.args[2], 'Q110786', 'Q202142' )
elseif frame.args[1] == 'partitive' then return NumberCase( frame.args[2], 'Q110786', 'Q857325' )
elseif frame.args[1] == 'numeric' then return NumberCase( frame.args[2], 'Q110786', 'Q12273953' )
end
end
function p.plural( frame )
if frame.args[1] == 'nominative' then return NumberCase( frame.args[2], 'Q146786', 'Q131105' )
elseif frame.args[1] == 'genetive' then return NumberCase( frame.args[2], 'Q146786', 'Q146233' )
elseif frame.args[1] == 'accusative' then return NumberCase( frame.args[2], 'Q146786', 'Q146078' )
elseif frame.args[1] == 'dative' then return NumberCase( frame.args[2], 'Q146786', 'Q145599' )
elseif frame.args[1] == 'instrumentative' then return NumberCase( frame.args[2], 'Q146786', 'Q192997' )
elseif frame.args[1] == 'prepositive' then return NumberCase( frame.args[2], 'Q146786', 'Q2114906' )
elseif frame.args[1] == 'locaive' then return NumberCase( frame.args[2], 'Q146786', 'Q202142' )
elseif frame.args[1] == 'partitive' then return NumberCase( frame.args[2], 'Q146786', 'Q857325' )
elseif frame.args[1] == 'numeric' then return NumberCase( frame.args[2], 'Q146786', 'Q12273953' )
end
end
return p