67 141
contributi
mNessun oggetto della modifica |
(External formatter uri) |
||
(7 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
-- <nowiki> | |||
-------------------------------------------------------------------------------- | |||
-- This module handles generic semantic functions to support modules | |||
-- Comments are compatible with LDoc https://github.com/lunarmodules/ldoc | |||
-- | |||
-- @module p | |||
-- @author Luca Mauri [[Utente:Lucamauri]] | |||
-- @keyword: wikitrek | |||
-- Keyword: wikitrek | -- Keyword: wikitrek | ||
-------------------------------------------------------------------------------- | |||
local p = {} | local p = {} | ||
Riga 52: | Riga 61: | ||
return string.char(10) .. AllLabels | return string.char(10) .. AllLabels | ||
end | end | ||
-------------------------------------------------------------------------------- | |||
-- Take parameters out of the frame and pass them to p._buildUniversalIncipit(). | |||
-- Return the result. | |||
-- | |||
-- @param {Frame} Info from MW session | |||
-- @return {string} The full incipit wikitext | |||
-------------------------------------------------------------------------------- | |||
function p.URIFromatterFromDT(frame) | |||
local Item | |||
local Type | |||
Item = mw.wikibase.getEntity() | |||
if not Item then | |||
Item = mw.wikibase.getEntity(frame.args['Item']) | |||
end | |||
if not Item then | |||
Item = mw.wikibase.getEntity('Q1') | |||
end | |||
if (not Item['claims']) or (not Item['claims']['P5']) then | |||
return "ERROR" | |||
else | |||
Type = Item['claims']['P5'][1].mainsnak.datavalue.value | |||
return "[[External formatter uri::" .. Type .. "|''" .. Type .. "'']]" | |||
end | |||
end | |||
-------------------------------------------------------------------------------- | |||
-- Generic value parser from arbitrary Item and Property | |||
-- Return the result. | |||
-- | |||
-- @param {Item} The Entity | |||
-- @param {Property} String containing the property identifier and number | |||
-- @return {string} Value of the mainsnak | |||
-------------------------------------------------------------------------------- | |||
function p.GenericFromDT(Item, Property) | |||
if (not Item['claims']) or (not Item['claims'][Property]) then | |||
return "ERROR" | |||
else | |||
return Item['claims'][Property][1].mainsnak.datavalue.value | |||
end | |||
end | |||
--- Function to calculate the number of seasons of a series | --- Function to calculate the number of seasons of a series | ||
-- | -- | ||
Riga 58: | Riga 111: | ||
function p.SeasonsQty(ShortName) | function p.SeasonsQty(ShortName) | ||
local QueryResult | local QueryResult | ||
local Max | local Max = 0 | ||
local PrefixText | local PrefixText | ||
Riga 72: | Riga 125: | ||
-- See https://github.com/SemanticMediaWiki/SemanticScribunto/blob/master/docs/mw.smw.ask.md#result | -- See https://github.com/SemanticMediaWiki/SemanticScribunto/blob/master/docs/mw.smw.ask.md#result | ||
-- for return value example | -- for return value example | ||
if QueryResult == nil or Max < 0 then | if QueryResult == nil or Max < 0 then | ||
return 0 | return 0 | ||
else | else | ||
Max = QueryResult[1]["Stagione"] | |||
return Max | return Max | ||
end | end | ||
Riga 183: | Riga 236: | ||
end | end | ||
]==] | ]==] | ||
NewPages = mw.smw.getQueryResult(InstanceText .. "|?Personaggio|limit= | NewPages = mw.smw.getQueryResult(InstanceText .. "|?Personaggio|limit=500|order=asc|sort=Numero di produzione") | ||
for _, Episode in ipairs(NewPages.results) do | for _, Episode in ipairs(NewPages.results) do | ||
Riga 233: | Riga 286: | ||
--Count = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|format=count') | --Count = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|format=count') | ||
--Episodes = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|sort=Numero di produzione|order=asc') | --Episodes = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|sort=Numero di produzione|order=asc') | ||
Episodes = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page .. ']]|sort=Numero di produzione|order=asc') | Episodes = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page .. ']]|limit=100|sort=Numero di produzione|order=asc') | ||
if (Episodes ~= nil) and (#Episodes > MinOccurr - 1) then | if (Episodes ~= nil) and (#Episodes > MinOccurr - 1) then |