Content deleted Content added
Adamant.pwn (talk | contribs) +issn |
Adamant.pwn (talk | contribs) temporary save Tag: Reverted |
||
Line 66:
]=]
local function tokenizeName(fullName)
local start = '^%s*' -- matches beginning of the string + arbitrary number of spaces
local finish = '%s*$' -- matches end of the string + arbitrary number of spaces
local comma = '\,%s+' -- matches comma + single or more spacing character
local space = '%s+' -- matches single or more spacing character
local name = '(%a[%a\-\']*)\.?' -- matches single name, have to start with letter, can contain apostrophe and hyphen, may end with dot
local surname = '(%a[%a\-\']*)' -- same as name, but can't end with dot
local f, i = mw.ustring.match(fullName, start .. surname .. comma .. name .. finish)
if f then
mw.log('tokenizeName: «' .. fullName .. '»: have «Fa, Im» match')
return {f, mw.ustring.sub( i, 1, 1 ) .. '.'}
end
local f, i, o = mw.ustring.match(fullName, start .. surname .. comma .. name .. space .. name .. finish)
if f then
mw.log( 'tokenizeName: «' .. fullName .. '»: have «Fa, Im Ot» match')
return {f, mw.ustring.sub( i, 1, 1 ) .. '. '
.. mw.ustring.sub( o, 1, 1 ) .. '.'}
end
local f1, f2, i = mw.ustring.match(fullName, start .. surname .. space .. surname .. comma .. name .. finish)
if f1 then
mw.log('tokenizeName: «' .. fullName .. '»: have «Fa Fa, Im» match')
return {f1 .. ' ' .. f2, mw.ustring.sub( i, 1, 1 ) .. '.'}
end
local particles = {'', 'de', 'van', 'von', 'de la', 'du', 'da', 'do', 'das', 'dos', 'e', 'van de', 'van der', 'van d\'', 'y', 'zu', 'of', 'di', 'al', 'el'}
-- Try matching k names + particle + surname
for k = 1, 5 do
for _, particle in ipairs(particles) do
if particle ~= '' then
particle = particle .. space
end
local pattern = start .. string.rep(name .. space, k) .. particle .. surname .. finish
local matched = {mw.ustring.match(fullName, pattern)}
if #matched ~= 0 then
mw.log('tokenizeName: «' .. fullName .. '»: have «Im (x' .. k .. ') ' .. particle .. ' Fa» match')
for i = 1, k do
matched[i] = mw.ustring.sub(matched[i], 1, 1)
end
return {matched[k + 1], table.concat(matched, '. ', 1, k) .. '.'}
end
end
end
mw.log('Unmatched any pattern: «' .. fullName .. '»')
return {fullName}
end
local function normalizeName( fullName )
if not fullName then return fullName end
local tokenized = tokenizeName(fullName)
if #tokenized == 1 then
return tokenized[1]
else
return tokenized[1] .. ', ' .. tokenized[2]
end
end
local function get_name_list (nl_type, args, qid, wdl)
Line 119 ⟶ 180:
local label = mw.wikibase.label(qnumber)
if label then
label = normalizeName(mw.text.nowiki(label))
else
label = qnumber
Line 166 ⟶ 227:
-- Fallback to name-only authors / editors
for k, v in pairs(fallback) do
local label = normalizeName(v.mainsnak.datavalue["value"])
local position = maxpos + 1 -- Default to 'next' author.
-- use P1545 (series ordinal) instead of default position.
|