Fix date and publisher for ja, books, use Cite news, disable ISSN
- fix publication date to year-only for books, journal articles - suppress publisher for news, journal articles - use P31 instance of, use Cite news for news articles - disable displaying of ISSN
This commit is contained in:
parent
d0298adb5d
commit
f32596a4f8
2 changed files with 69 additions and 6 deletions
|
|
@ -88,7 +88,7 @@ local function makelink(v, out, link, maxpos, wdl)
|
||||||
local sitelink = mw.wikibase.getSitelink(qnumber)
|
local sitelink = mw.wikibase.getSitelink(qnumber)
|
||||||
if qnumber == "Q2818964" then sitelink = nil end -- suppress link to "Various authors"
|
if qnumber == "Q2818964" then sitelink = nil end -- suppress link to "Various authors"
|
||||||
if v.qualifiers and v.qualifiers.P1932 then
|
if v.qualifiers and v.qualifiers.P1932 then
|
||||||
label = v.qualifiers.P1932[1].datavalue.value
|
label = v.qualifiers.P1932[1].datavalue.value -- object named as
|
||||||
else
|
else
|
||||||
label = mw.wikibase.getLabel(qnumber)
|
label = mw.wikibase.getLabel(qnumber)
|
||||||
if label then
|
if label then
|
||||||
|
|
@ -293,6 +293,50 @@ local function wrap_nowiki(str, disable)
|
||||||
return mw.text.nowiki(str or '')
|
return mw.text.nowiki(str or '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns the first string sequence of 3 or more digits in a date string, or nil
|
||||||
|
local function yearFromDate(datestr)
|
||||||
|
if datestr then
|
||||||
|
return string.match(datestr, '%d%d%d+')
|
||||||
|
end
|
||||||
|
return datestr
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Attempt to determine heuristically if we're citing a news article
|
||||||
|
local function isNewsArticle(qid, args)
|
||||||
|
local newsitems = {
|
||||||
|
'Q5707594', -- news article
|
||||||
|
'Q30070590', -- magazine article
|
||||||
|
-- TODO: somehow use WHERE {?item (wdt:P31|wdt:P31/wdt:P279*) wd:Q5707594.}
|
||||||
|
-- main subclasses of news article:
|
||||||
|
'Q87849013', -- AP article
|
||||||
|
'Q2144639', -- feature story
|
||||||
|
'Q139172839', -- top story
|
||||||
|
'Q18339884', -- cover story
|
||||||
|
'Q3326038', -- critical review
|
||||||
|
'Q4202018', -- interview
|
||||||
|
'Q309481', -- obituary
|
||||||
|
'Q108970988', -- column
|
||||||
|
'Q2602337', -- op-ed
|
||||||
|
'Q59908', -- opinion piece
|
||||||
|
}
|
||||||
|
-- most of the time a cheap lookup to a single value will work
|
||||||
|
if args['instance-of'] and in_array(args['instance-of'], newsitems) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
-- otherwise check multiple non-deprecated values
|
||||||
|
local instance_of = mw.wikibase.getBestStatements(qid, 'P31')
|
||||||
|
if instance_of and instance_of[1] then
|
||||||
|
for k, v in pairs(instance_of) do
|
||||||
|
if v.mainsnak.snaktype == "value" and v.mainsnak.datatype == "wikibase-item" then
|
||||||
|
if in_array(v.mainsnak.datavalue.value.id, newsitems) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
-- sort sequence table whose values are key-value pairs by key
|
-- sort sequence table whose values are key-value pairs by key
|
||||||
local function comp_key(a, b)
|
local function comp_key(a, b)
|
||||||
local param_a, enum_a = a[1]:match ('(%D+)(%d+)$'); -- get param name and enumerator from <a>
|
local param_a, enum_a = a[1]:match ('(%D+)(%d+)$'); -- get param name and enumerator from <a>
|
||||||
|
|
@ -594,13 +638,28 @@ local function _cite_q (citeq_args)
|
||||||
|
|
||||||
-- code to make a guess what template to use from the supplied parameters
|
-- code to make a guess what template to use from the supplied parameters
|
||||||
-- (first draft for proof-of-concept)
|
-- (first draft for proof-of-concept)
|
||||||
if citeq_args.isbn then
|
local pubyear = yearFromDate(citeq_args['publication-date'])
|
||||||
template = template or "book"
|
local is_news = isNewsArticle(qid, citeq_args)
|
||||||
citeq_args.asin = nil -- suppress ASIN if ISBN exists
|
if is_news then
|
||||||
|
template = template or "news"
|
||||||
|
-- some items use P123 (publisher) as the newspaper instead of P1433 (published in)
|
||||||
|
if citeq_args.publisher and not citeq_args.journal then
|
||||||
|
citeq_args.journal = citeq_args.publisher
|
||||||
|
citeq_args.publisher = nil
|
||||||
|
end
|
||||||
elseif citeq_args.journal then
|
elseif citeq_args.journal then
|
||||||
template = template or "journal"
|
template = template or "journal"
|
||||||
|
citeq_args['publication-date'] = pubyear or citeq_args['publication-date']
|
||||||
|
-- articles can be published in books/proceedings, otherwise suppress publisher
|
||||||
|
if not citeq_args.isbn then
|
||||||
|
citeq_args.publisher = nil
|
||||||
|
end
|
||||||
elseif is_thesis then
|
elseif is_thesis then
|
||||||
template = template or "thesis"
|
template = template or "thesis"
|
||||||
|
elseif citeq_args.isbn then
|
||||||
|
template = template or "book"
|
||||||
|
citeq_args.asin = nil -- suppress ASIN if ISBN exists
|
||||||
|
citeq_args['publication-date'] = pubyear or citeq_args['publication-date']
|
||||||
elseif citeq_args.website then
|
elseif citeq_args.website then
|
||||||
template = template or "web"
|
template = template or "web"
|
||||||
end
|
end
|
||||||
|
|
@ -709,6 +768,9 @@ local function _cite_q (citeq_args)
|
||||||
-- Disable CiteSeerX IDs for now
|
-- Disable CiteSeerX IDs for now
|
||||||
citeq_args.citeseerx = nil
|
citeq_args.citeseerx = nil
|
||||||
|
|
||||||
|
-- remove any remaining non-CS1 fields
|
||||||
|
citeq_args['instance-of'] = nil
|
||||||
|
|
||||||
-- render the template
|
-- render the template
|
||||||
local lc_template = template and template:lower() or "citation"
|
local lc_template = template and template:lower() or "citation"
|
||||||
local output
|
local output
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ local simple_properties_t = {
|
||||||
hdl = {id = "P1184", maxvals = 1}, -- take care of |hdl-access=?
|
hdl = {id = "P1184", maxvals = 1}, -- take care of |hdl-access=?
|
||||||
ismn = {id = "P1208", maxvals = 1},
|
ismn = {id = "P1208", maxvals = 1},
|
||||||
journal = {id = "P1433", maxvals = 1},
|
journal = {id = "P1433", maxvals = 1},
|
||||||
|
['instance-of'] = {id = "P31", qidonly=true, maxvals = 5}, -- transient, non-CS1
|
||||||
thesis_degree = {id = "P13338", maxvals = 1}, -- transient, non-CS1
|
thesis_degree = {id = "P13338", maxvals = 1}, -- transient, non-CS1
|
||||||
thesis_submitted_to = {id = "P4101", maxvals = 1}, -- transient, non-CS1
|
thesis_submitted_to = {id = "P4101", maxvals = 1}, -- transient, non-CS1
|
||||||
retracted_by = {id = "P5824", qidonly=true, maxvals = 1}, -- transient, non-CS1
|
retracted_by = {id = "P5824", qidonly=true, maxvals = 1}, -- transient, non-CS1
|
||||||
|
|
@ -82,7 +83,7 @@ local simple_properties_t = {
|
||||||
asin = {id = "P5749", maxvals = 1}, -- What about |asin-tld=? (WD examples resolve to .com at present, but may change)
|
asin = {id = "P5749", maxvals = 1}, -- What about |asin-tld=? (WD examples resolve to .com at present, but may change)
|
||||||
['article-number'] = {id = "P2322", maxvals = 1, populate_from_journal = true},
|
['article-number'] = {id = "P2322", maxvals = 1, populate_from_journal = true},
|
||||||
isbn = {id = "P212", maxvals = 1, populate_from_journal = true}, -- ISBN 13
|
isbn = {id = "P212", maxvals = 1, populate_from_journal = true}, -- ISBN 13
|
||||||
issn = {id = "P236", maxvals = 1, populate_from_journal = true}, -- distinguish from |eissn= for electronic issues?
|
-- issn = {id = "P236", maxvals = 1, populate_from_journal = true}, -- distinguish from |eissn= for electronic issues?
|
||||||
-- jfm = {id = "P?", maxvals = 1}, -- Jahrbuch über die Fortschritte der Mathematik (not Zbl)
|
-- jfm = {id = "P?", maxvals = 1}, -- Jahrbuch über die Fortschritte der Mathematik (not Zbl)
|
||||||
-- sbn = {id = "P?", maxvals = 1}, -- Standard Book Number (predecessor of ISBN, not ICCU)
|
-- sbn = {id = "P?", maxvals = 1}, -- Standard Book Number (predecessor of ISBN, not ICCU)
|
||||||
-- message-id = {id = "P?", maxvals = 1}, -- Usenet message ID
|
-- message-id = {id = "P?", maxvals = 1}, -- Usenet message ID
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue