Modul:Koordinaten: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
VolkoV (Diskussion | Beiträge) (Automatisch synchronisiert.) |
VolkoV (Diskussion | Beiträge) K (Automatisch synchronisiert.) |
||
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 3: | Zeile 3: | ||
function robusttrim(s) | function robusttrim(s) | ||
if s==nil then return '' end | if s==nil then return '' end | ||
local p= | local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','') | ||
p= | p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','') | ||
return mw.text.trim(p) | return mw.text.trim(p) | ||
end | end | ||
| Zeile 12: | Zeile 12: | ||
local t={} | local t={} | ||
local i=1 | local i=1 | ||
for str in | for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do | ||
t[i]=str | t[i]=str | ||
i=i+1 | i=i+1 | ||
Aktuelle Version vom 17. Mai 2021, 15:08 Uhr
Dokumentation und Testfälle unter Modul:Koordinaten/Doku.
local p = {}
function robusttrim(s)
if s==nil then return '' end
local p=mw.ustring.gsub(s,'%[%[SMW::on%]%]','')
p=mw.ustring.gsub(p,'%[%[SMW::off%]%]','')
return mw.text.trim(p)
end
function split(inputstr,sep)
if sep==nil then sep="%s" end
local t={}
local i=1
for str in mw.ustring.gmatch(inputstr,"([^"..sep.."]+)") do
t[i]=str
i=i+1
end
if i==1 then t[1]=inputstr end
return t
end
function holeViewbox(frame,ort)
if ort=='' then return '' end
local a=frame:callParserFunction(
'#show',ort,
'?Viewbox'
)
return a
end
function holeHandlungsorte(frame,geschichte)
if geschichte=='' then return '' end
local a=frame:callParserFunction(
'#ask','[['..geschichte..']]',
'mainlabel=-',
'?Handlungsort ist#=',
'sep=€'
)
return a
end
function viewboxToKoordinaten(viewbox)
if viewbox=="" then return "" end
local result=""
local width=10000000
for k,token in pairs(split(viewbox,",")) do
local subtokens={}
local i=0
for k,subtoken in pairs(split(token,"%s")) do
subtokens[i]=tonumber(subtoken)
i=i+1
end
if subtokens[3] then
if subtokens[3]<width then
width=subtokens[3]
local x=subtokens[0]+subtokens[2]/2
local y=subtokens[1]+subtokens[3]/2
result=x..";"..y
end
end
end
return result
end
function erzeugeKoordinaten(frame,geschichte,elementtyp)
if geschichte=='' then return '' end
local orte=holeHandlungsorte(frame,geschichte)
local ortet=split(orte,'€')
local result=""
for key,ort in pairs(ortet) do
view=holeViewbox(frame,ort)
koord=viewboxToKoordinaten(view)
if(koord~="") then
result=result.."\n\n"..elementtyp..':'..geschichte..";0!14;;"..koord
end
end
return result
end
function p.Koordinaten()
local frame=mw.getCurrentFrame()
local geschichte=robusttrim(frame.args[1])
if(geschichte=='') then return '' end
local elementtyp=frame:callParserFunction('#var','Elementtyp')
if(elementtyp=='') then elementtyp='Hauptdarsteller' end
local gbp=frame:callParserFunction('FULLPAGENAME',geschichte)
return erzeugeKoordinaten(frame,gbp,elementtyp)
end
return p