Pengguna:Renamed user 5cb535d47ac833448f09633576bf74ba/Indonesian Wiktionary - Wikidata Lexeme Integration

Template

sunting

Templat:Wl

{| class=wikitable
!Makna
!Kelas
|-
|{{#invoke:Wl|meaning|{{{1}}}}}
|{{Q|{{#invoke:Wl|lexcat|{{{1}}}}}}}
|}

Module

sunting

Modul:Wl

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 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 singularPlural( lexeme_id, item_id )
	local lexeme = mw.wikibase.getEntity( lexeme_id )
	local form = formWithSingleGrammaticalFeature( lexeme, item_id )
	if form == nil then
		return "''no such form''"
	end
	local representation = representationInLanguage( form, 'id' )
	return termSpan( representation )
end

function getMeanings ( current_lexeme )
    meanings = mw.html.create( 'ol' )
    for i, sense in pairs(current_lexeme:getSenses()) do
        gloss_text = ''
        glosses = sense:getGlosses()
        for j, gloss in pairs(glosses) do
            if gloss[2] == 'id' then
                gloss_text = gloss[1]
            end
        end
        meanings:tag('li'):wikitext(gloss_text)
    end
    return meanings 
end


function p.singular( frame )
	return singularPlural( frame.args[1], 'Q598521' )
end

function p.plural( frame )
	return singularPlural( frame.args[1], 'Q598522' )
end

function p.meaning( frame )
	current_lexeme = mw.wikibase.getEntity(frame.args[1])
	meanings = getMeanings ( current_lexeme )
	return tostring(meanings) 
end

function p.lexcat(frame)
	current_lexeme = mw.wikibase.getEntity(frame.args[1])
	return tostring(current_lexeme:getLexicalCategory())
end

return p

Result

sunting
{{Wl|L479448}}
Makna Kelas
Galat skrip: tidak ada modul tersebut "Wl". [(QGalat skrip: tidak ada modul tersebut "Wl".)]