Module:WikidataIB/sandbox1: Difference between revisions

Content deleted Content added
getValueAndQuals consolidated into getValue
sync with sandbox
Line 48:
-- some languages, e.g. Bosnian use a period as a suffix after each number in a date
["datenumbersuffix"] = "",
["list separator"] = ", ",
["abbr"] =
{
Line 295 ⟶ 296:
-- any double-quotes " are stripped out, so that spaces may be passed
-- e.g. |sep=" - "
local sepdefault = i18n[",list separator" -- **internationalise later**]
local separator = args.sep or ""
separator = string.gsub(separator, '"', '')
Line 621 ⟶ 622:
-------------------------------------------------------------------------------
-- _getvalue is the common function for getValue, getPreferredValue, and getNormalValue
--
local function _getvalue(frame, entity, props, filter, propertyID, qualID)
 
-- table 'out' is going to to store the return value(s):
-- qual is a string containing the property ID of the qualifier(s) to be returned
-- if qual == "ALL" then all qualifiers returned
-- if qual == "DATES" then qualifiers P580 (start time) and P582 (end time) returned
-- if nothing or an empty string is passed set it nil -> no qualifiers returned
local qualID = mw.text.trim(frame.args.qual or ""):upper()
if qualID == "" then qualID = nil end
 
-- create a filter function
--
-- rank is a parameter passed, which indicates "preferred" or "normal"
--
local rank = (frame.args.rank or ""):lower()
if v.rank:sub(1,1) == "normalp" then
if v.rank == "preferred" then
elseif rank:sub(1,1) == "n" then
rank = "normal"
else
rank = ""
end
 
local function filter(claim)
return errorOrEntitytrue
end
 
if notrank success> "" then
local prefflagrankflag = false
for k, v in pairs(props) do
if v.rank == rank then
prefflag rankflag = true
break
end
end
local function filter(claim)
return claim.rank == "normal"rank or prefflagrankflag == false
end
end
 
-- table 'out' is going to to storestores the return value(s):
local out = propertyvalueandquals(props, frame.args, filter, qualID)
 
-- format the table of values and return it as a string:
return assembleoutput(out, frame.args, entity.id, propertyID)
Line 652 ⟶ 692:
return errorOrEntity
end
 
-- qual is a string containing the property ID of the qualifier(s) to be returned
-- if qual == "ALL" then all qualifiers returned
-- if qual == "DATES" then qualifiers P580 (start time) and P582 (end time) returned
-- if nothing or an empty string is passed set it nil -> no qualifiers returned
local qualID = mw.text.trim(frame.args.qual or ""):upper()
if qualID == "" then qualID = nil end
 
local function filter(claim)
return true
end
return _getvalue(frame, errorOrEntity, props, filter, propertyID, qualID)
end
 
Line 673 ⟶ 706:
--
p.getPreferredValue = function(frame)
local propertyID = mw.text.trim(frame.args[1].rank or= "preferred")
return p.getValue(frame)
 
local success, errorOrEntity, props = parseInput(frame, frame.args[2], propertyID)
if not success then
return errorOrEntity
end
local prefflag = false
for k, v in pairs(props) do
if v.rank == "preferred" then
prefflag = true
break
end
end
local function filter(claim)
return claim.rank == "preferred" or prefflag == false
end
return _getvalue(frame, errorOrEntity, props, filter, propertyID)
end
 
Line 699 ⟶ 717:
--
p.getNormalValue = function(frame)
local propertyID = mw.text.trim(frame.args[1].rank or= "normal")
return p.getValue(frame)
 
local success, errorOrEntity, props = parseInput(frame, frame.args[2], propertyID)
if not success then
return errorOrEntity
end
local prefflag = false
for k, v in pairs(props) do
if v.rank == "normal" then
prefflag = true
break
end
end
local function filter(claim)
return claim.rank == "normal" or prefflag == false
end
return _getvalue(frame, errorOrEntity, props, filter, propertyID)
end