Module:SoftwareLicenseList

From MaRDI portal
Revision as of 14:06, 15 April 2025 by Tconrad (talk | contribs)

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

-- Required module containing helper methods
local helper = require('Module:HelperMethods')

-- Required modules for SPARQL queries and HTML table generation
local sparql = require('SPARQL')
local mwHtml = require('mw.html')

-- Main table to hold all functions
local p = {}

-- Function to build the list
function p.buildLicenseList(frame)
	
    -- Retrieve target1 from frame arguments or return error message if not set
	local target1 = frame.args[1]
    if not target1 or target1 == '' then
        return "No records found"
    end    
    
	jsonResults = helper.getValuesForProperty( target1, "P163" )

	if not jsonResults then
        return "Could not fetch data."
	end
	
	if helper.countElementsInBindings(jsonResults.results.bindings) == 0 then
        return "No records found."
	end

	local licenseList = helper.convertJsonToCommaSeparatedList(jsonResults)
	
	-- mw.log(licenseList) 
	
    return licenseList
end

-- Return the created html table
return p