Modulo:DTSem: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
External formatter uri
mNessun oggetto della modifica
(External formatter uri)
 
(20 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
Max = QueryResult[1]["Stagione"]
     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 102: Riga 155:
Series = mw.wikibase.getLabel(Item.claims['P16'][1].mainsnak.datavalue.value.id)
Series = mw.wikibase.getLabel(Item.claims['P16'][1].mainsnak.datavalue.value.id)
if ShortName == "Serie Classica" or ShortName == "Serie Animata" then
if SeriesShort == "Serie Classica" or SeriesShort == "Serie Animata" then
CategoryText = '[[Category:Personaggi della ' .. SeriesShort .. "]]"
CategoryText = '[[Category:Personaggi della ' .. SeriesShort .. "]]"
else
else
Riga 148: Riga 201:
Series = mw.wikibase.getLabel(Item.claims['P16'][1].mainsnak.datavalue.value.id)
Series = mw.wikibase.getLabel(Item.claims['P16'][1].mainsnak.datavalue.value.id)
if ShortName == "Serie Classica" or ShortName == "Serie Animata" then
if SeriesShort == "Serie Classica" or SeriesShort == "Serie Originale" or SeriesShort == "Serie Animata" then
InstanceText = '[[Istanza::Episodio della ' .. SeriesShort .. "]]"
InstanceText = '[[Istanza::Episodio della ' .. SeriesShort .. "]]"
else
else
InstanceText = '[[Istanza::Episodio di ' .. SeriesShort .. "]]"
InstanceText = '[[Istanza::Episodio di ' .. SeriesShort .. "]]"
end
end
--[==[
Pages = mw.smw.ask(InstanceText .. "|?Personaggio|order=asc|sort=Numero di produzione")
Pages = mw.smw.ask(InstanceText .. "|?Personaggio|order=asc|sort=Numero di produzione")
if Pages == nil then
if Pages == nil then
         return "''Nessun risultato''"
         return "''Nessun risultato'' (<code>" .. mw.text.nowiki(InstanceText) .. "</code>, )"  
     else
     else
     --local myResult = ""
     --local myResult = ""
Riga 182: Riga 235:
         end
         end
end
end
]==]
NewPages = mw.smw.getQueryResult(InstanceText .. "|?Personaggio |order=asc|sort=Numero di produzione")
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
for _, Character in ipairs(Episode.printouts.Personaggio) do
for _, Character in ipairs(Episode.printouts.Personaggio) do
if Characters[Character] == nil then
local CharText = Character.fulltext
table.insert(Characters, Character)
if not Characters[CharText] then
table.insert(Characters, CharText)
Characters[CharText] = true
end
end
end
end
end
end
table.sort(Characters)
if type(Characters) == 'table' and Characters ~= nil then
if type(Characters) == 'table' and Characters ~= nil then
for _, Page in ipairs(Characters) do
for _, Page in ipairs(Characters) do
     table.insert(PagesList, Page.fulltext)
     table.insert(PagesList, Page)
     end
     end
Riga 215: Riga 272:
function p.RecurringList(Pages, Series, MinOccurr)
function p.RecurringList(Pages, Series, MinOccurr)
local Results = {}
local Results = {}
if not MinOccurr or MinOccur < 1 then
if not MinOccurr or MinOccurr < 1 then
MinOccurr = 1
MinOccurr = 1
end
end
Riga 229: 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
Riga 253: Riga 310:
         table.insert(Results, "* '''[[" .. Page .. "]]''' (" .. #Episodes .. "): " .. table.concat(List, ", "))
         table.insert(Results, "* '''[[" .. Page .. "]]''' (" .. #Episodes .. "): " .. table.concat(List, ", "))
         else
         else
         table.insert(Results, "* NULL or ZERO Episodes - " .. mw.text.nowiki('[[Serie::' .. Series .. ']][[Personaggio::' .. Page .. ']]|sort=Numero di produzione|order=asc'))
         -- Episode is NULL or number of episodes is LESS the set value
        --table.insert(Results, "* NULL or ZERO Episodes - " .. mw.text.nowiki('[[Serie::' .. Series .. ']][[Personaggio::' .. Page .. ']]|sort=Numero di produzione|order=asc'))
         end
         end
     end
     end

Menu di navigazione