Bots, Editors (Semantic MediaWiki), trusted
13,033
edits
(New module for the Theosophist/Authors page, after Module:Path authors) |
m (Split the author index into three lists: established authors, unidentified signatures and unsigned material; the query now covers every contents entry, not only those with an author) |
||
| Line 39: | Line 39: | ||
local rows, offset = {}, 0 | local rows, offset = {}, 0 | ||
for batch = 1, 100 do | for batch = 1, 100 do | ||
local query = '{{#ask:[[Theosophist item | local query = '{{#ask:[[Theosophist item ID::+]]' | ||
.. '|?Theosophist item author=a|+sep=' .. AS | .. '|?Theosophist item author=a|+sep=' .. AS | ||
.. '|?Theosophist item ID=id|?Theosophist item title=t' | .. '|?Theosophist item ID=id|?Theosophist item title=t' | ||
| Line 45: | Line 45: | ||
.. '|?Theosophist item month=m|?Theosophist item year=y' | .. '|?Theosophist item month=m|?Theosophist item year=y' | ||
.. '|?Theosophist item links to text=links|+sep=; ' | .. '|?Theosophist item links to text=links|+sep=; ' | ||
.. '|?Theosophist item author signed=as' | |||
.. '|mainlabel=-|link=none|headers=hide|named args=yes' | .. '|mainlabel=-|link=none|headers=hide|named args=yes' | ||
.. '|format=template|template=Theosophist authors raw row' | .. '|format=template|template=Theosophist authors raw row' | ||
| Line 52: | Line 53: | ||
for _, record in ipairs(split(text, RS)) do | for _, record in ipairs(split(text, RS)) do | ||
local f = split(record, FS) | local f = split(record, FS) | ||
if #f == | if #f == 10 and trim(f[2]) ~= '' then | ||
table.insert(rows, {a=trim(f[1]), id=f[2], t=f[3], v=f[4], n=f[5], pg=f[6], m=f[7], y=f[8], links=f[9]}) | table.insert(rows, {a=trim(f[1]), id=f[2], t=f[3], v=f[4], n=f[5], pg=f[6], | ||
m=f[7], y=f[8], links=f[9], as=trim(f[10])}) | |||
count = count + 1 | count = count + 1 | ||
end | end | ||
| Line 63: | Line 65: | ||
end | end | ||
local function group(rows) | -- keyfn (необязательна) возвращает строку, по которой группировать запись; | ||
-- по умолчанию группируем по полю author. | |||
local function group(rows, keyfn) | |||
local map, order = {}, {} | local map, order = {}, {} | ||
for _, r in ipairs(rows) do | for _, r in ipairs(rows) do | ||
local seen = {} | local seen = {} | ||
for _, raw in ipairs(authors(r.a)) do | for _, raw in ipairs(authors(keyfn and keyfn(r) or r.a)) do | ||
raw = trim(raw) | raw = trim(raw) | ||
local target = raw:match('^%[%[([^]|]+)|[^]]+%]%]$') or raw:match('^%[%[([^]]+)%]%]$') | local target = raw:match('^%[%[([^]|]+)|[^]]+%]%]$') or raw:match('^%[%[([^]]+)%]%]$') | ||
| Line 83: | Line 87: | ||
table.sort(order, function(a,b) return mw.ustring.lower(a) < mw.ustring.lower(b) end) | table.sort(order, function(a,b) return mw.ustring.lower(a) < mw.ustring.lower(b) end) | ||
return map, order | return map, order | ||
end | |||
-- Запись оглавления ссылается на выпуск, а не на отдельную строку: | |||
-- якоря nN создаёт {{Theosophist number}} на странице оглавления тома. | |||
local function location(r) | |||
local details = 'vol. ' .. r.v .. ', no. ' .. r.n .. ', ' .. r.m .. ' ' .. r.y .. ', pp. ' .. r.pg | |||
if not r.pg:find('-', 1, true) then details = details:gsub(', pp%. ', ', p. ') end | |||
return '[[Theosophist/Vol' .. r.v .. '#n' .. r.n .. '|' .. details .. ']]' | |||
end | |||
local function entry(r) | |||
local links = trim(r.links) ~= '' and ('; ' .. r.links) or '' | |||
return '<li><i>' .. r.t .. '</i> <span style="color:grey; font-size:85%;">(' | |||
.. location(r) .. ')' .. links .. '</span></li>' | |||
end | |||
-- Три состояния авторства записи оглавления: | |||
-- author -- установленное имя: ссылка на карточку словаря, или же простой | |||
-- текст, если карточки ещё нет; | |||
-- author signed -- печатная подпись, буквально как напечатана (под | |||
-- заголовком или в конце материала); | |||
-- author signed = UNSIGNED -- материал напечатан без всякой подписи. Помета | |||
-- в квадратных скобках -- не печатный текст, а утверждение редакции, как | |||
-- и описательные заголовки в квадратных скобках. | |||
local UNSIGNED = '[unsigned]' | |||
local function has_card(value) | |||
return value:find('[[', 1, true) ~= nil | |||
end | |||
-- Строка, по которой материал опознаётся, когда карточки автора нет: | |||
-- печатная подпись, а если её нет -- простой текст поля author. | |||
local function signature(r) | |||
local as = trim(r.as) | |||
if as ~= '' and as ~= UNSIGNED then return as end | |||
local a = trim(r.a) | |||
if a ~= '' and not has_card(a) then return a end | |||
return '' | |||
end | |||
local function select_rows(frame, kind) | |||
local out = {} | |||
for _, r in ipairs(fetch(frame)) do | |||
if kind == 'carded' and has_card(trim(r.a)) then | |||
table.insert(out, r) | |||
elseif kind == 'signature' and not has_card(trim(r.a)) and signature(r) ~= '' then | |||
table.insert(out, r) | |||
elseif kind == 'unsigned' and trim(r.as) == UNSIGNED then | |||
table.insert(out, r) | |||
end | |||
end | |||
return out | |||
end | end | ||
function p.list(frame) | function p.list(frame) | ||
local map, order = group( | local map, order = group(select_rows(frame, 'carded')) | ||
local out = {} | local out = {} | ||
for _, name in ipairs(order) do | for _, name in ipairs(order) do | ||
| Line 101: | Line 157: | ||
end) | end) | ||
for _, r in ipairs(author.items) do | for _, r in ipairs(author.items) do | ||
table.insert(out, entry(r)) | |||
table.insert(out, | |||
end | end | ||
table.insert(out, '</ol>') | table.insert(out, '</ol>') | ||
end | end | ||
return table.concat(out, '\n') | |||
end | |||
-- Подписи, псевдонимы, инициалы и описательные обозначения, за которыми не | |||
-- стоит лица с карточкой словаря: подпись есть, но она ничего не | |||
-- устанавливает. Группируются так же, как авторы с карточками. | |||
function p.unidentified(frame) | |||
local map, order = group(select_rows(frame, 'signature'), signature) | |||
local out = {} | |||
for _, name in ipairs(order) do | |||
local author = map[name] | |||
table.insert(out, '<h3>' .. author.label .. '</h3>\n<ol>') | |||
table.sort(author.items, function(a, b) | |||
if a.t == b.t then return a.id < b.id end | |||
return mw.ustring.lower(a.t) < mw.ustring.lower(b.t) | |||
end) | |||
for _, r in ipairs(author.items) do | |||
table.insert(out, entry(r)) | |||
end | |||
table.insert(out, '</ol>') | |||
end | |||
return table.concat(out, '\n') | |||
end | |||
-- Материал, напечатанный без всякой подписи (author signed = UNSIGNED), | |||
-- независимо от того, установлен ли автор из других источников. | |||
-- Группируется по томам, внутри тома -- по ID, то есть по выпускам и страницам. | |||
function p.unsigned(frame) | |||
local rows = select_rows(frame, 'unsigned') | |||
table.sort(rows, function(a, b) return a.id < b.id end) | |||
local out, current = {}, nil | |||
for _, r in ipairs(rows) do | |||
if r.v ~= current then | |||
if current then table.insert(out, '</ol>') end | |||
current = r.v | |||
table.insert(out, '<h3>Volume ' .. r.v .. '</h3>\n<ol>') | |||
end | |||
table.insert(out, entry(r)) | |||
end | |||
if current then table.insert(out, '</ol>') end | |||
return table.concat(out, '\n') | return table.concat(out, '\n') | ||
end | end | ||
| Line 114: | Line 206: | ||
function p.debug(frame) | function p.debug(frame) | ||
local rows = fetch(frame) | local rows = fetch(frame) | ||
local _, | local carded, signed, unsigned, blank = 0, 0, 0, 0 | ||
return 'Total | for _, r in ipairs(rows) do | ||
if has_card(trim(r.a)) then carded = carded + 1 end | |||
if not has_card(trim(r.a)) and signature(r) ~= '' then signed = signed + 1 end | |||
if trim(r.as) == UNSIGNED then unsigned = unsigned + 1 end | |||
if trim(r.a) == '' and trim(r.as) == '' then blank = blank + 1 end | |||
end | |||
return 'Total contents entries: ' .. #rows .. '; with a dictionary entry: ' .. carded | |||
.. '; signature without an entry: ' .. signed .. '; marked unsigned: ' .. unsigned | |||
.. '; neither author nor signature recorded: ' .. blank | |||
end | end | ||
return p | return p | ||