Modul:Reference score: Forskjell mellom sideversjoner
Hopp til navigering
Hopp til søk
(Ny side: local i18n = mw.loadData( 'Module:References/i18n' ) local langPriority = { -- primary language nb=1, -- important languages nn=2, da=3, sv=4, fo=5, is=6, -- main languages en=7,…) |
Ingen redigeringsforklaring |
||
Linje 1: | Linje 1: | ||
local i18n = mw.loadData( 'Module:References/i18n' ) |
local i18n = mw.loadData( 'Module:References/i18n' ) |
||
local conf = mw.loadData( 'Module:References/conf' ) |
|||
local |
local highScore = 5 |
||
⚫ | |||
-- primary language |
|||
⚫ | |||
nb=1, |
|||
⚫ | |||
-- important languages |
|||
nn=2, da=3, sv=4, fo=5, is=6, |
|||
-- main languages |
|||
en=7, de=8, fr=9, it=10, es=11, pt=12, pl=13, ru=14, ja=15, zh=16 |
|||
} |
|||
local domainPriority = { |
|||
-- primary domain |
|||
no=1, |
|||
-- important domains |
|||
dk=2, se=3, fo=4, is=5, |
|||
-- main domains |
|||
eu=6, de=7, fr=8, it=9, es=10, pt=11, pl=12, ru=13, ja=14, zh=15, |
|||
com=16, org=17, net=18 |
|||
} |
|||
⚫ | |||
⚫ | |||
local h = {} |
local h = {} |
||
-- Can be tested in the console with |
-- Can be tested in the console with |
||
-- `=p. |
-- `=p.categories()` |
||
-- `=p. |
-- `=p.categories(0)` |
||
-- `=p. |
-- `=p.categories(1)` |
||
-- `=p. |
-- `=p.categories(2)` |
||
function h. |
function h.categories( num ) |
||
local |
local t = {} |
||
if num then |
if num then |
||
⚫ | |||
⚫ | |||
⚫ | |||
if num == 1 then |
if num == 1 then |
||
⚫ | |||
wiki = wiki .. mw.ustring.format('[[Category:%s]]', |
|||
⚫ | |||
elseif num > 1 then |
elseif num > 1 then |
||
⚫ | |||
wiki = wiki .. mw.ustring.format('[[Category:%s]]', |
|||
⚫ | |||
end |
end |
||
end |
end |
||
return |
return t |
||
end |
end |
||
Linje 63: | Linje 45: | ||
-- `=p.prioritize(mw.wikibase.getAllStatements('Q20', 'P31')[2].references)` |
-- `=p.prioritize(mw.wikibase.getAllStatements('Q20', 'P31')[2].references)` |
||
-- `=p.prioritize(mw.wikibase.getAllStatements('Q66363708', 'P31')[2].references)` |
-- `=p.prioritize(mw.wikibase.getAllStatements('Q66363708', 'P31')[2].references)` |
||
function h. |
function h.score( list ) |
||
local t = {} |
local t = {} |
||
for i=1,lowScore do |
|||
t[i] = false |
|||
end |
|||
for _,v in ipairs( list ) do |
for _,v in ipairs( list ) do |
||
-- do not include any "imported from" |
-- do not include any "imported from" |
||
if not v. |
if v.snaks and not( v.snaks.P143 or v.snaks.P3452 ) then |
||
--mw.logObject(v.snaks) |
|||
⚫ | |||
--do return end |
|||
⚫ | |||
-- try language of "title" |
-- try language of "title" |
||
if v. |
if v.snaks.P1476 then |
||
for _,w in ipairs(v. |
for _,w in ipairs(v.snaks.P1476) do |
||
if w.snaktype == 'value' |
if w.snaktype == 'value' |
||
and w.datatype == 'monolingualtext' |
|||
and w.datavalue.type == 'monolingualtext' then |
|||
local score = conf.languageScore[w.datavalue.value.language] |
|||
if score then |
|||
⚫ | |||
-- note that higher number means lower prority |
|||
keep = (keep < score) and keep or score |
|||
⚫ | |||
end |
end |
||
end |
end |
||
Linje 84: | Linje 71: | ||
end |
end |
||
-- try root domain of "reference url" |
-- try root domain of "reference url" |
||
if v. |
if v.snaks.P854 then |
||
for _,w in ipairs(v. |
for _,w in ipairs(v.snaks.P854) do |
||
if w.snaktype == 'value' |
if w.snaktype == 'value' |
||
and w.datatype == 'url' |
|||
and w.datavalue.type == 'string' then |
|||
local uri = mw.uri.new( w.datavalue.value ) |
|||
local root = string.match( uri.path, '%.[^.]+$' ) |
|||
local score = conf.domainScore[root] |
|||
if score then |
|||
-- note that higher number means lower prority |
|||
-- note that higher number means lower prority |
|||
keep = (keep < score) and keep or score |
|||
⚫ | |||
end |
end |
||
end |
end |
||
end |
end |
||
end |
end |
||
-- try reference to entity |
|||
⚫ | |||
⚫ | |||
⚫ | |||
for _,w in ipairs(u) do |
|||
if w.snaktype == 'value' |
|||
and w.datatype == 'wikibase-item' |
|||
and w.datavalue.type == 'wikibase-entityid' then |
|||
local score = conf.entityScore[w.datavalue.value.id] |
|||
if score then |
|||
⚫ | |||
keep = (keep < score) and keep or score |
|||
⚫ | |||
⚫ | |||
end |
|||
end |
|||
⚫ | |||
⚫ | |||
-- note that higher number means lower prority |
-- note that higher number means lower prority |
||
keep = (keep < |
keep = (keep < midScore) and keep or midScore |
||
end |
end |
||
table.insert( t, keep, v ) |
table.insert( t, keep, v ) |
||
end |
end |
||
end |
end |
||
return t |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
-- Can be somewhat tested by |
|||
-- =mw.dumpObject(p.compact(p.score(mw.wikibase.getAllStatements('Q40826', 'P569')[1].references))) |
|||
function h.compact( list, limit ) |
|||
limit = limit or maxRefs |
|||
local t = {} |
|||
local counter = 0 |
|||
for _,v in ipairs( list ) do |
|||
if v then |
|||
counter = counter + 1 |
|||
if limit and counter <= limit then |
|||
⚫ | |||
elseif not limit then |
|||
table.insert( t, v ) |
|||
end |
|||
end |
|||
end |
end |
||
return |
return t |
||
end |
end |
||
function h.renderReferences( frame ) |
function h.renderReferences( frame ) |
||
local wiki = '' |
|||
--return h. ..h.renderCategories( ) |
|||
for _,v in ipairs( h.categories( num ) ) do |
|||
⚫ | |||
end |
|||
return wiki |
|||
end |
end |
||
Sideversjonen fra 27. aug. 2019 kl. 23:57
Dokumentasjon for denne modulen kan opprettes på Modul:Reference score/dok
local i18n = mw.loadData( 'Module:References/i18n' ) local conf = mw.loadData( 'Module:References/conf' ) local highScore = 5 local midScore = 15 local lowScore = 25 local maxRefs = 4 local h = {} -- Can be tested in the console with -- `=p.categories()` -- `=p.categories(0)` -- `=p.categories(1)` -- `=p.categories(2)` function h.categories( num ) local t = {} if num then table.insert( mw.message.newRawMessage( i18n['category-pages-using-references-from-statement'] ):plain() ) if num == 1 then table.insert( mw.message.newRawMessage( i18n['category-pages-using-single-reference-from-statement'] ):plain() ) elseif num > 1 then table.insert( mw.message.newRawMessage( i18n['category-pages-using-multiple-references-from-statement'], num ):plain() ) end end return t end function h.standardFormat(frame, prop) local found = false local hits = 0 local refs = '' for i,v in ipairs( prop.references or {} ) do if v.snaks and not v.snaks.P143 then found = found or true hits = hits + 1 -- hash will merge similar entries refs = refs .. frame:extensionTag( 'ref', mw.wikibase.formatValues( v.snaks ), { name = v.hash } ) end end return mw.wikibase.formatValue( prop.mainsnak ) .. refs .. cats end -- Can be tested in the console with -- `=p.prioritize(mw.wikibase.getAllStatements('Q20', 'P31')[2].references)` -- `=p.prioritize(mw.wikibase.getAllStatements('Q66363708', 'P31')[2].references)` function h.score( list ) local t = {} for i=1,lowScore do t[i] = false end for _,v in ipairs( list ) do -- do not include any "imported from" if v.snaks and not( v.snaks.P143 or v.snaks.P3452 ) then --mw.logObject(v.snaks) --do return end local keep = lowScore -- try language of "title" if v.snaks.P1476 then for _,w in ipairs(v.snaks.P1476) do if w.snaktype == 'value' and w.datatype == 'monolingualtext' and w.datavalue.type == 'monolingualtext' then local score = conf.languageScore[w.datavalue.value.language] if score then -- note that higher number means lower prority keep = (keep < score) and keep or score end end end end -- try root domain of "reference url" if v.snaks.P854 then for _,w in ipairs(v.snaks.P854) do if w.snaktype == 'value' and w.datatype == 'url' and w.datavalue.type == 'string' then local uri = mw.uri.new( w.datavalue.value ) local root = string.match( uri.path, '%.[^.]+$' ) local score = conf.domainScore[root] if score then -- note that higher number means lower prority keep = (keep < score) and keep or score end end end end -- try reference to entity for _,u in pairs(v.snaks) do for _,w in ipairs(u) do if w.snaktype == 'value' and w.datatype == 'wikibase-item' and w.datavalue.type == 'wikibase-entityid' then local score = conf.entityScore[w.datavalue.value.id] if score then -- note that higher number means lower prority keep = (keep < score) and keep or score end end end end -- some properties that usually imply somewhat quality if v.snaks.P92 or v.snaks.P248 then -- note that higher number means lower prority keep = (keep < midScore) and keep or midScore end table.insert( t, keep, v ) end end return t end -- Can be somewhat tested by -- =mw.dumpObject(p.compact(p.score(mw.wikibase.getAllStatements('Q40826', 'P569')[1].references))) function h.compact( list, limit ) limit = limit or maxRefs local t = {} local counter = 0 for _,v in ipairs( list ) do if v then counter = counter + 1 if limit and counter <= limit then table.insert( t, v ) elseif not limit then table.insert( t, v ) end end end return t end function h.renderReferences( frame ) local wiki = '' for _,v in ipairs( h.categories( num ) ) do wiki = wiki .. mw.ustring.format('[[Category:%s]]', v ) end return wiki end return h