localp={}-- Return the first form of the lexeme which has exactly the given grammatical feature.localfunctionformWithSingleGrammaticalFeature(lexeme,item_id)fori,forminpairs(lexeme:getForms())dolocalgrammaticalFeatures=form:getGrammaticalFeatures()if#grammaticalFeatures==1andgrammaticalFeatures[1]==item_idthenreturnformendendreturnnilend-- Return the representation of the form in the given language code,-- or the first representation otherwise.localfunctionrepresentationInLanguage(form,language_code)localrepresentation,language=form:getRepresentation(language_code)ifrepresentationthenreturn{representation,language}elsereturnform:getRepresentations()[1]endendlocalfunctiontermSpan(term)localtext=term[1]locallang=term[2]localdir=mw.language.new(lang):getDir()localspan=mw.html.create('span')span:attr('lang',lang)-- TODO T310581:attr('dir',dir):wikitext(text)returntostring(span)endlocalfunctionsingularPlural(lexeme_id,item_id)locallexeme=mw.wikibase.getEntity(lexeme_id)localform=formWithSingleGrammaticalFeature(lexeme,item_id)ifform==nilthenreturn"''no such form''"endlocalrepresentation=representationInLanguage(form,'id')returntermSpan(representation)endfunctiongetMeanings(current_lexeme)meanings=mw.html.create('ol')fori,senseinpairs(current_lexeme:getSenses())dogloss_text=''glosses=sense:getGlosses()forj,glossinpairs(glosses)doifgloss[2]=='id'thengloss_text=gloss[1]endendmeanings:tag('li'):wikitext(gloss_text)endreturnmeaningsendfunctionp.singular(frame)returnsingularPlural(frame.args[1],'Q598521')endfunctionp.plural(frame)returnsingularPlural(frame.args[1],'Q598522')endfunctionp.meaning(frame)current_lexeme=mw.wikibase.getEntity(frame.args[1])meanings=getMeanings(current_lexeme)returntostring(meanings)endfunctionp.lexcat(frame)current_lexeme=mw.wikibase.getEntity(frame.args[1])returntostring(current_lexeme:getLexicalCategory())endreturnp