Jump to content

Module:Wd and Module:Wd/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
m remove unused local "refHash" and narrow lifetime/scope of "valuesArray"
 
bugfix
 
Line 103: Line 103:
subjectNamedAs = "P1810",
subjectNamedAs = "P1810",
wikidataProperty = "P1687",
wikidataProperty = "P1687",
publishedIn = "P1433"
publishedIn = "P1433",
lastUpdate = "P5017"
}
}


Line 1,823: Line 1,824:
-- for each citation type, there will be an associative array that associates lists of rendered properties
-- for each citation type, there will be an associative array that associates lists of rendered properties
-- to citation-template parameters
-- to citation-template parameters
local groupedProcessedProperties = {}
local candidateParams = {}
-- like above, but only associates one rendered property to each parameter; if the above variable
-- like above, but only associates one rendered property to each parameter; if the above variable
-- contains more strings for a parameter, the strings will be assigned to numbered params (e.g. "author1")
-- contains more strings for a parameter, the strings will be assigned to numbered params (e.g. "author1")
Line 1,831: Line 1,832:
local referenceEmpty = true -- will be set to false if at least one parameter is left unremoved
local referenceEmpty = true -- will be set to false if at least one parameter is left unremoved


local version = 11 -- increment this each time the below logic is changed to avoid conflict errors
local version = 12 -- increment this each time the below logic is changed to avoid conflict errors


if not statement.snaks then
if not statement.snaks then
Line 1,879: Line 1,880:
end
end
-- TODO reimplement using prioritization
-- don't include "subject named as", but use it as the title when "title" is not present but a URL is
-- don't include "subject named as", but use it as the title when "title" is not present but a URL is
if statement.snaks[aliasesP.subjectNamedAs] then
if statement.snaks[aliasesP.subjectNamedAs] then
Line 1,887: Line 1,889:
end
end
-- initialize groupedProcessedProperties and citeParams
-- initialize candidateParams and citeParams
for _, citeType in ipairs(citeTypes) do
for _, citeType in ipairs(citeTypes) do
groupedProcessedProperties[citeType] = {}
candidateParams[citeType] = {}
citeParams[citeType] = {}
citeParams[citeType] = {}
end
end


-- fill groupedProcessedProperties
-- fill candidateParams
for refProperty in pairs(statement.snaks) do
for _, citeType in ipairs(citeTypes) do
local candidateParamPriorities = {}
-- add the parameter to each matching type of citation

for _, citeType in ipairs(citeTypes) do
-- TODO ordered addition into candidateParams
for refProperty in pairs(statement.snaks) do
if citeErrors[citeType] then
break
end
repeat -- just a simple wrapper to emulate "continue"
repeat -- just a simple wrapper to emulate "continue"
-- skip if there already have been errors
if citeErrors[citeType] then
break
end
-- set mappingKey and prefix
-- set mappingKey and prefix
local mappingKey
local mappingKey
Line 1,920: Line 1,922:
-- skip properties with empty parameter name
-- skip properties with empty parameter name
if paramName == "" then
if paramName == "" then
break -- skip this property for this value of citeType
break
end
end
referenceEmpty = false

-- handle unknown properties in the reference
-- handle unknown properties in the reference
if not paramName then
if not paramName then
referenceEmpty = false
local error_message = errorText("unknown-property-in-ref", refProperty)
local error_message = errorText("unknown-property-in-ref", refProperty)
assert(error_message) -- Should not be nil
assert(error_message) -- Should not be nil
Line 1,950: Line 1,951:
break
break
end
end
referenceEmpty = false
-- add an entry to groupedProcessedProperties
-- add an entry to candidateParams and candidateParamPriorities
if not groupedProcessedProperties[citeType][paramName] then
if not candidateParams[citeType][paramName] then
groupedProcessedProperties[citeType][paramName] = {}
candidateParams[citeType][paramName] = {}
candidateParamPriorities[paramName] = {}
end
end
local thisParamPriority = -1
local thisParamPrioritization = citeConfig[citeType]["prioritization"][paramName]
if thisParamPrioritization then
for i_priority, i_property in ipairs() do
if i_property == refProperty then
thisParamPriority = i_priority
end
end
end
for _, propertyValue in pairs(processedProperty) do
for _, propertyValue in pairs(processedProperty) do
table.insert(groupedProcessedProperties[citeType][paramName], prefix .. propertyValue)
table.insert(candidateParams[citeType][paramName], prefix .. propertyValue)
table.insert(candidateParamPriorities[paramName], thisParamPriority)
end
end
until true
until true
Line 1,983: Line 1,999:
referenceEmpty = false
referenceEmpty = false
if not groupedProcessedProperties[citeType][paramName] then
if not candidateParams[citeType][paramName] then
groupedProcessedProperties[citeType][paramName] = {}
candidateParams[citeType][paramName] = {}
end
end
for _, propertyValue in pairs(additionalProcessedProperties[refProperty]) do
for _, propertyValue in pairs(additionalProcessedProperties[refProperty]) do
table.insert(groupedProcessedProperties[citeType][paramName], propertyValue)
table.insert(candidateParams[citeType][paramName], propertyValue)
end
end
until true
until true
Line 1,995: Line 2,011:
-- fill citeParams
-- fill citeParams
for _, citeType in ipairs(citeTypes) do
for _, citeType in ipairs(citeTypes) do
for paramName, paramValues in pairs(groupedProcessedProperties[citeType]) do
for paramName, paramValues in pairs(candidateParams[citeType]) do
if #paramValues == 1 or not isValueInTable(paramName, citeConfig[citeType]["numbered-params"] or {}) then
if #paramValues == 1 or not isValueInTable(paramName, citeConfig[citeType]["numbered-params"] or {}) then
citeParams[citeType][paramName] = paramValues[1]
citeParams[citeType][paramName] = paramValues[1]