Module:Wd and Module:Wd/sandbox: Difference between pages
Appearance
(Difference between pages)
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 |
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 = |
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 |
-- initialize candidateParams and citeParams |
||
for _, citeType in ipairs(citeTypes) do |
for _, citeType in ipairs(citeTypes) do |
||
candidateParams[citeType] = {} |
|||
citeParams[citeType] = {} |
citeParams[citeType] = {} |
||
end |
end |
||
-- fill |
-- fill candidateParams |
||
for |
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 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
repeat -- just a simple wrapper to emulate "continue" |
repeat -- just a simple wrapper to emulate "continue" |
||
-- skip if there already have been errors |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- 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 |
||
⚫ | |||
-- 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 |
||
⚫ | |||
⚫ | |||
-- add an entry to |
-- add an entry to candidateParams and candidateParamPriorities |
||
if not |
if not candidateParams[citeType][paramName] then |
||
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( |
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 |
if not candidateParams[citeType][paramName] then |
||
candidateParams[citeType][paramName] = {} |
|||
end |
end |
||
for _, propertyValue in pairs(additionalProcessedProperties[refProperty]) do |
for _, propertyValue in pairs(additionalProcessedProperties[refProperty]) do |
||
table.insert( |
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( |
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] |