„Modul:WikibaseL“ – Versionsunterschied
Erscheinungsbild
KKeine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
local util = require('Module:Wikibase') | local util = require('Module:Wikibase') | ||
local cfg = require('Module:Wikibase/config') | |||
local p = {} | local p = {} | ||
local function isNo(v) | |||
if v == nil then return false end | |||
local value = tostring(v):lower() | |||
return value == 'nein' or value == '0' or value == 'no' or value == 'false' | |||
end | |||
-- SMW-Konfiguration des Lexems; ohne L-Abschnitt bleibt die einfache Anzeige. | |||
local function getSmwConfig() | |||
return cfg and cfg.smw and cfg.smw.L | |||
end | |||
local function buildSmw(lemma, subtitle) | |||
local c = getSmwConfig() | |||
if not c then return '' end | |||
return util.smwAnnotate({ | |||
[c.propArt] = c.valArt or 'L', | |||
[c.propLabel] = lemma or '', | |||
[c.propDesc] = subtitle or '', | |||
}) | |||
end | |||
local function buildVisibleSmwTable(lemma, subtitle) | |||
local c = getSmwConfig() | |||
if not c then return '' end | |||
local t = mw.html.create('table') | |||
t:addClass('aew-wb-smwtable') | |||
local function row(key, value) | |||
if not value or value == '' then return end | |||
local tr = t:tag('tr') | |||
tr:tag('th'):wikitext(key) | |||
tr:tag('td'):wikitext(value) | |||
end | |||
row(c.propArt, c.valArt or 'L') | |||
row(c.propLabel, lemma or '') | |||
row(c.propDesc, subtitle or '') | |||
return tostring(t) | |||
end | |||
local function getLexicalCategoryLabel(entityId) | local function getLexicalCategoryLabel(entityId) | ||
| Zeile 14: | Zeile 53: | ||
local function getSenseGloss(entityId, senseParam) | local function getSenseGloss(entityId, senseParam) | ||
-- | -- Bedeutungsverarbeitung ist noch nicht implementiert. | ||
return nil | return nil | ||
end | end | ||
| Zeile 67: | Zeile 106: | ||
local sub = computeSubtitle(args, entityId) | local sub = computeSubtitle(args, entityId) | ||
if sub and sub ~= '' and shouldSetShortdesc(args) then | |||
util.setShortdesc(frame, sub) | |||
end | |||
-- Wie bei WikibaseQ: Annotationen unabhängig von show und set erzeugen. | |||
-- set steuert weiterhin ausschließlich SHORTDESC. | |||
local smw = buildSmw(lemma, sub) | |||
if not isNo(args.show) then | |||
local tableHtml = buildVisibleSmwTable(lemma, sub) | |||
if tableHtml ~= '' then | |||
return smw .. link .. '<br />' .. tableHtml | |||
end | |||
end | |||
if sub and sub ~= '' then | if sub and sub ~= '' then | ||
return smw .. link .. '<br />' .. util.trim(sub) | |||
end | end | ||
return link | return smw .. link | ||
end | end | ||
Version vom 11. Oktober 2026, 06:20 Uhr
Die Dokumentation für dieses Modul kann unter Modul:WikibaseL/Doku erstellt werden
local util = require('Module:Wikibase')
local cfg = require('Module:Wikibase/config')
local p = {}
local function isNo(v)
if v == nil then return false end
local value = tostring(v):lower()
return value == 'nein' or value == '0' or value == 'no' or value == 'false'
end
-- SMW-Konfiguration des Lexems; ohne L-Abschnitt bleibt die einfache Anzeige.
local function getSmwConfig()
return cfg and cfg.smw and cfg.smw.L
end
local function buildSmw(lemma, subtitle)
local c = getSmwConfig()
if not c then return '' end
return util.smwAnnotate({
[c.propArt] = c.valArt or 'L',
[c.propLabel] = lemma or '',
[c.propDesc] = subtitle or '',
})
end
local function buildVisibleSmwTable(lemma, subtitle)
local c = getSmwConfig()
if not c then return '' end
local t = mw.html.create('table')
t:addClass('aew-wb-smwtable')
local function row(key, value)
if not value or value == '' then return end
local tr = t:tag('tr')
tr:tag('th'):wikitext(key)
tr:tag('td'):wikitext(value)
end
row(c.propArt, c.valArt or 'L')
row(c.propLabel, lemma or '')
row(c.propDesc, subtitle or '')
return tostring(t)
end
local function getLexicalCategoryLabel(entityId)
local ok, entity = pcall(mw.wikibase.getEntity, entityId)
if not ok or type(entity) ~= 'table' then return nil end
local lc = entity.lexicalCategory
if type(lc) == 'table' then lc = lc.id or lc.value end
if type(lc) ~= 'string' or lc == '' then return nil end
local ok2, label = pcall(mw.wikibase.getLabel, lc)
if ok2 and type(label) == 'string' and label ~= '' then return label end
return lc
end
local function getSenseGloss(entityId, senseParam)
-- Bedeutungsverarbeitung ist noch nicht implementiert.
return nil
end
local function computeSubtitle(args, entityId)
local s = args.subtitle
if s and s ~= '' then
s = tostring(s)
local low = s:lower()
if low == 'nein' or low == '0' then return nil end
if low == 'sense' then
local sp = args.S or '1'
return getSenseGloss(entityId, sp)
end
-- "S1" / "1" als Direktangabe
if low:match('^s%d+$') or low:match('^%d+$') then
return getSenseGloss(entityId, low)
end
if low ~= 'ja' and low ~= 'auto' then
return util.trim(s) -- eigener Untertitel
end
end
-- Default: Wortart
return getLexicalCategoryLabel(entityId)
end
local function shouldSetShortdesc(args)
local set = args.set
if not set or set == '' then return true end
set = tostring(set):lower()
if set == 'nein' or set == '0' then return false end
return true
end
function p.link(frame)
local args = util.getArgs(frame)
local entityId = util.detectEntityId(args)
if not entityId then return '' end
local lemma = args.label or util.getEntityLabelOrLemma(entityId) or entityId
local line1 = string.format('%s %s', entityId, lemma)
return util.buildEntityLink(entityId, line1, args.target)
end
function p.render(frame)
local args = util.getArgs(frame)
local entityId = util.detectEntityId(args)
if not entityId then return '' end
local lemma = args.label or util.getEntityLabelOrLemma(entityId) or entityId
local line1text = string.format('%s %s', entityId, lemma)
local link = util.buildEntityLink(entityId, line1text, args.target)
local sub = computeSubtitle(args, entityId)
if sub and sub ~= '' and shouldSetShortdesc(args) then
util.setShortdesc(frame, sub)
end
-- Wie bei WikibaseQ: Annotationen unabhängig von show und set erzeugen.
-- set steuert weiterhin ausschließlich SHORTDESC.
local smw = buildSmw(lemma, sub)
if not isNo(args.show) then
local tableHtml = buildVisibleSmwTable(lemma, sub)
if tableHtml ~= '' then
return smw .. link .. '<br />' .. tableHtml
end
end
if sub and sub ~= '' then
return smw .. link .. '<br />' .. util.trim(sub)
end
return smw .. link
end
function p.shortdesc(frame)
local args = util.getArgs(frame)
local entityId = util.detectEntityId(args)
if not entityId then return '' end
local sub = computeSubtitle(args, entityId)
if not sub or sub == '' then return '' end
return util.setShortdesc(frame, sub)
end
return p