Content deleted Content added
sync with sandbox |
add getValueAndQuals() function |
||
Line 1:
-- DEVELOPING getValueAndQuals()
-- Module to implement use of a blacklist and whitelist for infobox fields
-- Can take a named parameter |qid which is the Wikidata ID for the article
Line 235 ⟶ 237:
-- The name of the field that this function is called from is passed in named parameter |name
local fieldname = args.name or ""
if blacklist then
-- The name is compulsory when blacklist is used, so return nil if it is not supplied
Line 271 ⟶ 273:
-------------------------------------------------------------------------------
--
--
-- It returns a sequence (table) of values representing the values of that property
-- and qualifiers that match the qualifier value supplied.
--
local function
-- onlysourced is a boolean passed to return only values sourced to other than Wikipedia
Line 386 ⟶ 389:
out[#out + 1] = label
end -- test for link required
--[[ If the property has a qualifier of latest date, add that in all cases:
if v.qualifiers then
local quals = v.qualifiers["P1326"] -- latest date qualifier
Line 394 ⟶ 397:
end
end
--]]
------------------------------------
elseif datatype == "time" then -- data type is time:
Line 495 ⟶ 499:
break
end -- of datatype/unknown value/sourced check
-- See if qualifiers are to be returned
if v.qualifiers and qualID then
local qargs = {
["onlysrc"] = false,
["linked"] = parseParam(args.linked, true),
["prefix"] = "",
["postfix"] = "",
["lprefix"] = "",
["lpostfix"] = "",
["wdl"] = args.wdlinks or args.wdl,
["uabbr"] = parseParam(args.unitabbr, false),
["maxvals"] = 0,
}
local function qf(dummy)
return true
end
local qlist = {}
for k1, v1 in v.qualifiers do
if qualID == "ALL" or qualID == v1.id then
qlist = propertyvalueandquals(v1, qargs, qf)
if #qlist > 0 then
-- *** implement assembleoutput later ***
out[#out] = out[#out] .. " (" .. table.concat(qlist, ", ") .. ")"
end
end
end
end
if maxvals > 0 and #out >= maxvals then break end
end -- of for each value loop
Line 565 ⟶ 597:
-------------------------------------------------------------------------------
--
local function _getvalue(frame, entity, props, filter, propertyID)
-- table 'out' is going to to store the return value(s):
local out =
-- format the table of values and return it as a string:
return assembleoutput(out, frame, entity.id, propertyID)
end
-------------------------------------------------------------------------------
-- _getvalueandquals processes public function p.getValueAndQuals
--
local function _getvalueandquals(frame, entity, props, filter, propertyID, qualID)
local out = propertyvalueandquals(props, frame.args, filter, qualID)
return assembleoutput(out, frame, entity.id, propertyID)
end
Line 651 ⟶ 693:
end
return _getvalue(frame, errorOrEntity, props, filter, propertyID)
end
-------------------------------------------------------------------------------
-- getValueAndQuals takes property ID and optional qualifier ID (qual)
-- returns values for a property along with values of matching qualifiers
-- implements getValue functionality
p.getValueAndQuals = function(frame)
if not frame.args[1] then
frame.args = frame:getParent().args
if not frame.args[1] then return i18n.errors["No property supplied"] end
end
local propertyID = mw.text.trim(frame.args[1] or "")
local success, errorOrEntity, props = parseInput(frame, frame.args[2], propertyID)
if not success then
return errorOrEntity
end
-- qualID is a string containing the property ID of the qualifier(s) to be returned
-- if qualID = "ALL" then all qualifiers returned
-- if nothing or an empty string is passed set it nil -> no qualifiers returned
local qualID = parseParam(frame.args.qual, nil)
local function filter(claim)
return true
end
return _getvalueandquals(frame, errorOrEntity, props, filter, propertyID, qualID)
end
Line 754 ⟶ 824:
return true
end
local vals =
for k, v in pairs(vals) do
out[#out + 1] = v
Line 871 ⟶ 941:
end
end
return p
|