Zum Inhalt springen

Modul:Wortbedeutungen

aus AufEinWort, der freien Forschung

Die Dokumentation für dieses Modul kann unter Modul:Wortbedeutungen/Doku erstellt werden

local p = {}

function p.zeig(frame)
    local modi = frame.args[1] or ""
    local num = frame.args[2] or ""
    local title = mw.title.getCurrentTitle()
    local content = title:getContent() or ""

    local sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^|%]]+)")
    if not sprachvorstufe then
        sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^%]]+)%]%]")
    end

    if not sprachvorstufe or sprachvorstufe == "" then
        return "[" .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local other = mw.title.new(sprachvorstufe)
    if not other then
        return "[Seite der " .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local otherContent = other:getContent() or ""
    local sprachstufe = otherContent:match("%[%[Sprachstufe::([^%]]+)%]%]")
    local lastLang = sprachstufe and sprachstufe:match("([a-z]+%.)%s*$") or sprachstufe or "[Sprachstufe nicht gefunden]"

    local output = {}

    if modi:find("N") then
        table.insert(output, lastLang .. " [[" .. sprachvorstufe .. "]]")
    end

    if modi:find("B") then
        local bedeutungen = {}
        for bedeutung in otherContent:gmatch("%[%[Wortbedeutung::([^%]]+)%]%]") do
            table.insert(bedeutungen, bedeutung)
        end
        if #bedeutungen > 0 then
            table.insert(output, "'" .. table.concat(bedeutungen, ", ") .. "'")
        end
    end

    if modi:find("D") then
        local dingbedeutungen = {}
        for bedeutung in otherContent:gmatch("%[%[Dingbedeutung::([^%]]+)%]%]") do
            table.insert(dingbedeutungen, bedeutung)
        end
        if #dingbedeutungen > 0 then
            table.insert(output, "'" .. table.concat(dingbedeutungen, ", ") .. "'")
        end
    end

    return table.concat(output, " ")
end

function p.zeigN(frame)
    local num = frame.args[1] or ""
    local title = mw.title.getCurrentTitle()
    local content = title:getContent() or ""

    local sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^|%]]+)")
    if not sprachvorstufe then
        sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^%]]+)%]%]")
    end

    if not sprachvorstufe or sprachvorstufe == "" then
        return "[" .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local other = mw.title.new(sprachvorstufe)
    if not other then
        return "[Seite der " .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local otherContent = other:getContent() or ""
    local sprachstufe = otherContent:match("%[%[Sprachstufe::([^%]]+)%]%]")

    if sprachstufe and sprachstufe ~= "" then
        local lastLang = sprachstufe:match("([a-z]+%.)%s*$") or sprachstufe
        return lastLang .. " [[" .. sprachvorstufe .. "]]"
    else
        return "[Sprachstufe nicht gefunden in " .. sprachvorstufe .. "]"
    end
end

function p.zeigB(frame)
    local num = frame.args[1] or ""
    local title = mw.title.getCurrentTitle()
    local content = title:getContent() or ""

    local sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^|%]]+)")
    if not sprachvorstufe then
        sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^%]]+)%]%]")
    end

    if not sprachvorstufe or sprachvorstufe == "" then
        return "[" .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local other = mw.title.new(sprachvorstufe)
    if not other then
        return "[Seite der " .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local otherContent = other:getContent() or ""

    local bedeutungen = {}
    for bedeutung in otherContent:gmatch("%[%[Wortbedeutung::([^%]]+)%]%]") do
        table.insert(bedeutungen, bedeutung)
    end

    if #bedeutungen == 0 then
        return "[Keine Wortbedeutung gefunden in " .. sprachvorstufe .. "]"
    else
        return table.concat(bedeutungen, ", ")
    end
end

function p.zeigD(frame)
    local num = frame.args[1] or ""
    local title = mw.title.getCurrentTitle()
    local content = title:getContent() or ""

    local sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^|%]]+)")
    if not sprachvorstufe then
        sprachvorstufe = content:match("%[%[" .. num .. "%-Sprachvorstufe::([^%]]+)%]%]")
    end

    if not sprachvorstufe or sprachvorstufe == "" then
        return "[" .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local other = mw.title.new(sprachvorstufe)
    if not other then
        return "[Seite der " .. num .. "-Sprachvorstufe nicht gefunden]"
    end

    local otherContent = other:getContent() or ""

    local dingbedeutungen = {}
    for bedeutung in otherContent:gmatch("%[%[Dingbedeutung::([^%]]+)%]%]") do
        table.insert(dingbedeutungen, bedeutung)
    end

    if #dingbedeutungen == 0 then
        return "[Keine Dingbedeutung gefunden in " .. sprachvorstufe .. "]"
    else
        return table.concat(dingbedeutungen, ", ")
    end
end

return p