Module:SMW: Difference between revisions

From devsummit
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:SMW
local p = {}
local p = {}


-- Return results
function p.sessionTable(frame)
function p.ask(frame)


     if not mw.smw then
     local sessions = mw.smw.getQueryResult( "[[Category:Sessions]]" )
         return "mw.smw module not found"
 
    if sessions == nil then
         return "no sessions found"
     end
     end


     if frame.args[1] == nil then
     local statements = {};
         return "no parameter found"
    for k1,v1 in pairs( sessions.results ) do
        statements[v1.fulltext] = {}
         local queryResult = mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v1.fulltext .. "]]" )
        local count = 0
    for k2,v2 in pairs ( queryResult.results ) do
    statements[v1.fulltext][v2.fulltext] = true
    count = count + 1
end
statements[v1.fulltext]['count'] = count
     end
     end
 
   
     local queryResult = mw.smw.getQueryResult( frame.args )
     local result = "\n{| class='wikitable\n|\n"
 
    for k1,v1 in pairs( sessions.results ) do
    if queryResult == nil then
        result = result .. "![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
        return "(no values)"
     end
     end
 
     for k1,v1 in pairs( sessions.results ) do
     if type( queryResult ) == "table" then
        result = result .. "|-\n![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
        local myResult = ""
        for k2,v2 in pairs( sessions.results ) do
        for k,v in pairs( queryResult.results ) do
        result = result .. "| style='text-align:center;'|"
            if  v.fulltext and v.fullurl then
        if v1.fulltext == v2.fulltext then
                myResult = myResult .. "[[" .. v.fulltext .. "]]" .. "<br/>"
        result = result .. "X"
            else
    else
                myResult = myResult .. k .. " | no page title for result set available (you probably specified ''mainlabel=-')"
    local count = 0
            end
    for k3,v3 in pairs( statements[v1.fulltext] ) do
        end
    if ( statements[v2.fulltext][k3] == true ) then
        return myResult
    count = count + 1
end
end
result = result .. count
    end
    result = result .. "\n"
    end
     end
     end
    result = result .. "|}"


     return queryResult
     return result
end
end


return p
return p

Latest revision as of 11:54, 27 November 2017

Documentation for this module may be created at Module:SMW/doc

local p = {}

function p.sessionTable(frame)

    local sessions = mw.smw.getQueryResult( "[[Category:Sessions]]" )

    if sessions == nil then
        return "no sessions found"
    end

    local statements = {};
    for k1,v1 in pairs( sessions.results ) do
        statements[v1.fulltext] = {}
        local queryResult = mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v1.fulltext .. "]]" )
        local count = 0
    	for k2,v2 in pairs ( queryResult.results ) do
    		statements[v1.fulltext][v2.fulltext] = true
    		count = count + 1
		end
		statements[v1.fulltext]['count'] = count
    end
    
    local result = "\n{| class='wikitable\n|\n"
    for k1,v1 in pairs( sessions.results ) do
        result = result .. "![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
    end
    for k1,v1 in pairs( sessions.results ) do
        result = result .. "|-\n![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
        for k2,v2 in pairs( sessions.results ) do
        	result = result .. "| style='text-align:center;'|"
        	if v1.fulltext == v2.fulltext then
        		result = result .. "X"
    		else
    			local count = 0
    			for k3,v3 in pairs( statements[v1.fulltext] ) do
    				if ( statements[v2.fulltext][k3] == true ) then
    					count = count + 1
					end
				end
				result = result .. count
    		end
    		result = result .. "\n"
    	end
    end
    result = result .. "|}"

    return result
end

return p