Modul:Test: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
imported>Juergen.Kett |
imported>Juergen.Kett |
||
| Zeile 5: | Zeile 5: | ||
p.entity = nil; | p.entity = nil; | ||
p.claims = nil; | p.claims = nil; | ||
| + | p.keys = {}; | ||
| + | p.index = 1; | ||
| + | |||
| + | p.property = nil; | ||
| + | p.value = nil; | ||
| + | p.qualifier = nil; | ||
function p.initEntity(qid) | function p.initEntity(qid) | ||
p.entity = mw.wikibase.getEntity(qid) | p.entity = mw.wikibase.getEntity(qid) | ||
| − | p.claims = | + | p.claims = p.entity["claims"] |
| − | + | -- p.i, p.v = next(p.claims, nil) | |
| + | -- mw.logObject(p.entity) | ||
| + | p.keys = {} | ||
| + | p.index=1 | ||
| + | local i = 1 | ||
| + | for k in pairs(p.claims) do | ||
| + | p.keys[i]=k | ||
| + | i = i + 1 | ||
| + | end | ||
| + | mw.logObject(p.keys) | ||
end | end | ||
| − | p. | + | function p.nextStatement() |
| − | + | p.property = p.keys[p.index] | |
| − | + | mw.log(p.property) | |
| − | + | if p.property then | |
| + | claim = p.claims[p.property] | ||
| + | p.value = claim[1]["mainsnak"] | ||
| + | mw.logObject(p.value) | ||
| + | p.index = p.index + 1 | ||
| + | end | ||
end | end | ||
| − | |||
p.getStatement = function (frame) | p.getStatement = function (frame) | ||
| Zeile 32: | Zeile 51: | ||
end | end | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
function p.Eigenschaft(frame) | function p.Eigenschaft(frame) | ||
Version vom 28. Mai 2020, 23:50 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Test/Doku erstellt werden
-- Das Modul enthält einige Testfunktionen, um das Skripting mit Lua zu erproben
local p = {};
p.entity = nil;
p.claims = nil;
p.keys = {};
p.index = 1;
p.property = nil;
p.value = nil;
p.qualifier = nil;
function p.initEntity(qid)
p.entity = mw.wikibase.getEntity(qid)
p.claims = p.entity["claims"]
-- p.i, p.v = next(p.claims, nil)
-- mw.logObject(p.entity)
p.keys = {}
p.index=1
local i = 1
for k in pairs(p.claims) do
p.keys[i]=k
i = i + 1
end
mw.logObject(p.keys)
end
function p.nextStatement()
p.property = p.keys[p.index]
mw.log(p.property)
if p.property then
claim = p.claims[p.property]
p.value = claim[1]["mainsnak"]
mw.logObject(p.value)
p.index = p.index + 1
end
end
p.getStatement = function (frame)
local pid = frame.args.pid
local qid = frame.args.qid
local entity = mw.wikibase.getEntity(qid)
return entity:formatPropertyValues(pid)
end
p.getLabel = function (frame)
local pid = frame.args.pid
local label = mw.wikibase.getLabel(pid)
return label
end
function p.Eigenschaft(frame)
local pid = frame.args.pid
local qid = frame.args.qid
local entity = mw.wikibase.getEntity(qid)
local snaks = entity['claims'][pid][1]['qualifiers']
local test = mw.wikibase.formatValues( snaks )
return 'P-ID: ' .. pid .. ' Q-ID: ' .. qid .. ' Test: ' .. test
end
return p