Anonimo

Modulo:DTSem: differenze tra le versioni

Da Wikitrek.
m
nessun oggetto della modifica
mNessun oggetto della modifica
mNessun oggetto della modifica
 
(106 versioni intermedie di uno stesso utente non sono mostrate)
Riga 58: Riga 58:
function p.SeasonsQty(ShortName)
function p.SeasonsQty(ShortName)
local QueryResult
local QueryResult
local Max
local Max = 0
local PrefixText
local PrefixText
Riga 72: Riga 72:
-- 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 81: Riga 81:
--- Function to extract recurring characters and list them
--- Function to extract recurring characters and list them
--  
--  
-- @param ShortName The short name of the series as in P24
-- @param frame Context from MediaWiki
-- @return Integer Number of seasons
-- @return String Bullet list of characters and episodes
function p.RecurringListFromCategory(frame)
function p.RecurringListFromCategory(frame)
local Results = {}
local Results = {}
Riga 88: Riga 88:
local CategoryText
local CategoryText
local Pages
local Pages
local PagesList = {}
local Series
local SeriesShort
local SeriesShort
Riga 98: Riga 100:
SeriesShort = mw.wikibase.getEntity(Item.claims['P16'][1].mainsnak.datavalue.value.id).claims['P24'][1].mainsnak.datavalue.value
SeriesShort = mw.wikibase.getEntity(Item.claims['P16'][1].mainsnak.datavalue.value.id).claims['P24'][1].mainsnak.datavalue.value
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 111: Riga 114:
if Pages == nil then
if Pages == nil then
         return "''Nessun risultato''"
         return "''Nessun risultato''"
     end
     else
    for _, Page in ipairs(Pages.results) do
    table.insert(PagesList, Page.fulltext)
    end
    return p.RecurringList(PagesList, Series)   
end
--return table.concat(Results, string.char(10))
end
--- Function to extract recurring characters from all pages and list them
--
-- @param frame Context from MediaWiki
-- @return String Bullet list of characters and episodes
function p.RecurringListFull(frame)
local Results = {}
local Item
local InstanceText
local Pages
local Series
local SeriesShort
local Characters = {}
local PagesList = {}
if not Item then
Item = mw.wikibase.getEntity(frame.args['Item'])
end
if not Item then
Item = mw.wikibase.getEntity('Q1')
end
SeriesShort = mw.wikibase.getEntity(Item.claims['P16'][1].mainsnak.datavalue.value.id).claims['P24'][1].mainsnak.datavalue.value
Series = mw.wikibase.getLabel(Item.claims['P16'][1].mainsnak.datavalue.value.id)
if SeriesShort == "Serie Classica" or SeriesShort == "Serie Originale" or SeriesShort == "Serie Animata" then
InstanceText = '[[Istanza::Episodio della ' .. SeriesShort .. "]]"
else
InstanceText = '[[Istanza::Episodio di ' .. SeriesShort .. "]]"
end
--[==[
Pages = mw.smw.ask(InstanceText .. "|?Personaggio|order=asc|sort=Numero di produzione")
if Pages == nil then
        return "''Nessun risultato'' (<code>" .. mw.text.nowiki(InstanceText) .. "</code>, )"
    else
    --local myResult = ""
        for num, row in pairs(Pages) do
            --myResult = myResult .. '* This is result #' .. num .. '\n'
            mw.smw.set("Test=" .. num)
            for property, data in pairs( row ) do
            if property == "Personaggio"  then
            if type(data) == 'table' then
            for _, Character in pairs(data) do
            if Characters[Character] == nil then
            --table.insert(Characters, Character)
            end
            end
            else
            -- This should never happens
            table.insert(Characters, "NEXT ONE ->")
            if Characters[data] == nil then
            table.insert(Characters, data)
            end
            end
            end
            end
        end
end
]==]
NewPages = mw.smw.getQueryResult(InstanceText .. "|?Personaggio|limit=500|order=asc|sort=Numero di produzione")
for _, Episode in ipairs(NewPages.results) do
for _, Character in ipairs(Episode.printouts.Personaggio) do
local CharText = Character.fulltext
if not Characters[CharText] then
table.insert(Characters, CharText)
Characters[CharText] = true
end
end
end


table.sort(Characters)
if type(Characters) == 'table' and Characters ~= nil then
for _, Page in ipairs(Characters) do
    table.insert(PagesList, Page)
    end
return p.RecurringList(PagesList, Series, 3)
--return #Characters .. " - " .. #Characters .. " - " .. table.concat(PagesList, ", ")
else
return "No table"
end
--return table.concat(Results, string.char(10))
end
--- Helper to extract recurring characters and list them
--
-- @param Pages Table containing characters' pages names
-- @param Series String with name of the Series
-- @param[opt=1] MinOccurr Integer with minimum value of occurencies
-- @return String Bullet list of characters and episodes
function p.RecurringList(Pages, Series, MinOccurr)
local Results = {}
if not MinOccurr or MinOccurr < 1 then
MinOccurr = 1
end
     if type(Pages) == "table" then
     if type(Pages) == "table" then
     for _, Page in ipairs(Pages.results) do
     --for _, Page in ipairs(Pages.results) do
    for _, Page in ipairs(Pages) do
     local Count
     local Count
     local Episodes = {}
     local Episodes = {}
Riga 120: Riga 231:
         -- Page.fulltext represents Page name
         -- Page.fulltext represents Page name
        
        
         Count = mw.smw.ask('[[Serie::' .. SeriesShort .. ']][[Personaggio::' .. Page.fulltext .. ']]|format=count')
         --Count = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|format=count')
         if Count > 0 then
        --Episodes = mw.smw.ask('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|sort=Numero di produzione|order=asc')
         Episodes = mw.smw.ask('[[Serie::' .. SeriesShort .. ']][[Personaggio::' .. Page.fulltext .. ']]|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
        --[=[
         Episodes = mw.smw.getQueryResult('[[Serie::' .. Series .. ']][[Personaggio::' .. Page.fulltext .. ']]|sort=Numero di produzione|order=asc')
        
        
         for _, Episode in ipairs(Episodes) do
         for _, Episode in ipairs(Episodes.results) do
         table.insert(List, Episode.fulltext)
         table.insert(List, "[[" .. Episode.fulltext .. "]]")
         end
         end
        ]=]
        
        
         table.insert(Results, "* [[" .. Page.fulltext .. "]] (" .. Count .. "): " .. table.concat(List, ", "))
        for num, Episode in pairs(Episodes) do
        --myResult = myResult .. '* This is result #' .. num .. '\n'
            for _, Data in pairs(Episode) do
            if type(Data) == 'table' then
            table.insert(List, table.concat(Data))
            else
            table.insert(List, Data)
            end
       
            end
        end
         table.insert(Results, "* '''[[" .. Page .. "]]''' (" .. #Episodes .. "): " .. table.concat(List, ", "))
        else
        -- 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
Riga 135: Riga 265:
     end
     end
--return mw.text.nowiki(CategoryText) .. #Pages
return table.concat(Results, string.char(10))
return table.concat(Results, string.char(10))
end
-- Return results
function p.Ask(frame)
    if not mw.smw then
        return "mw.smw module not found"
    end
    --if frame.args[1] == nil then
    --    return "no parameter found"
    --end
--local queryResult = mw.smw.ask( frame.args )
--local queryResult = mw.smw.ask("[[Serie::Star Trek: Strange New Worlds]][[Personaggio::T'Pring]]|sort=Numero di produzione|order=asc")
local queryResult = mw.smw.ask("[[Istanza::Episodio di Picard]]|?Personaggio|order=asc|sort=Numero di produzione")
   
    if queryResult == nil then
        return "(no values)"
    end
    if type( queryResult ) == "table" then
        local myResult = ""
        for num, row in pairs( queryResult ) do
            myResult = myResult .. '* This is result #' .. num .. '\n'
            for property, data in pairs( row ) do
                local dataOutput = data
                if type( data ) == 'table' then
                    dataOutput = mw.text.listToText( data, ', ', ' and ')
                end
                myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
            end
        end
        return myResult
    end
    return queryResult
end
end
return p
return p