Module:Sandbox/Erutuon/author citation: Difference between revisions

Content deleted Content added
try array-based output (efficiency difference not noticeable), reject input if two author citations are found in a row (if that's possible)
adapt getBotanicalAuthorityFromWikiData from Module:Taxon authority to link author name if it has d:Property:P428 (botanist author abbreviation) on Wikidata
 
(One intermediate revision by the same user not shown)
Line 75:
end
 
-- Currently using IPNI convention of no spaces after initials.
local author_abbrevs = {
["L."] = "Carl Linnaeus",
["Schldl."] = "Diederich Franz Leonhard von Schlechtendal",
["Cham."] = "Adelbert von Chamisso",
["B.Boivin"] = "Joseph Robert Bernard Boivin",
["A.J.Eames"] = "Arthur Johnson Eames",
}
 
function p.standardize_abbrev(abbrev)
return (abbrev:gsub("%.%s+", "."))
end
 
-- Adapted from getBotanicalAuthorityFromWikiData in [[Module:Taxon authority]].
function p.get_botanist_author_abbreviation(name)
local wikidata_id = mw.wikibase.getEntityIdForTitle(name)
 
if not (wikidata_id and mw.wikibase.isValidEntityId(wikidata_id)) then
local title_obj = mw.title.new(name).redirectTarget
if title_obj and title_obj.text then
wikidata_id = mw.wikibase.getEntityIdForTitle(name)
end
end
 
if wikidata_id and mw.wikibase.isValidEntityId(wikidata_id) then -- valid Wikidata id
local item = mw.wikibase.getEntity(wikidata_id)
local statements = item:getBestStatements('P428')[1] -- botanist author abbreviation
if statements ~= nil then
return statements.mainsnak.datavalue.value
end
end
return nil
end
 
function p.link_author_citation(citation)
Line 85 ⟶ 113:
citation,
function (author)
iflocal full_name = author_abbrevs[p.standardize_abbrev(author)] then
if full_name then
return "[[" .. author_abbrevs[author]full_name .. "|" .. author .. "]]"
elseif p.get_botanist_author_abbreviation(author) then
return "[[" .. author .. "]]"
end
end)