Module:MathModDB

From MaRDI portal
Revision as of 13:33, 6 June 2025 by TA4Shehu (talk | contribs)

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

-- Required modules for SPARQL queries and HTML table generation
-- Module for executing SPARQL queries
local sparql = require('SPARQL')
-- MediaWiki library for logging and utilities
local mw = require('mw')
local json = require("mw.text") 

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

function p.getMathModDBStatistics()

	-- Table to store statistics
	local MathModDBStatistics = {}

	----------------Research Fields---------------------------------------------
	--   Q60231 refers to academic discipline 
	-- Q6534265 refers to MathModDB community
	local sparqlQuery = [[
	SELECT ?Research_Fields
	WHERE {
    	?item wdt:P31   wd:Q60231;
        	  wdt:P1495 wd:Q6534265 .
	}
    ]]
    
	-- Executing the SPARQL query and retrieving results in JSON format
	local jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research fields
	local totalResearchFields = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    local url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Research_field"
    local totalResearchFieldsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalResearchFields))
    table.insert(MathModDBStatistics, "| Research Fields: " .. totalResearchFieldsWithUrl)
    

	----------------Research Problems-------------------------------------------  
	-- Q6032837 refers to research problem   
	-- Q6534265 refers to MathModDB community 
	local sparqlQuery = [[
	SELECT ?Research_Problems
	WHERE {
		?item wdt:P31 wd:Q6032837;
        	  wdt:P1495 wd:Q6534265 .
	}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research problems
	local totalResearchProblems = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Research_problem"
    local totalResearchProblemsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalResearchProblems))
    table.insert(MathModDBStatistics, "| Research Problems: " .. totalResearchProblemsWithUrl)
    
    ----------------Mathematical Models-----------------------------------------  
	-- Q68663 refers to mathematical model
	-- Q6534265 refers to MathModDB community
	local sparqlQuery = [[
	SELECT ?Mathematical_Models
	WHERE {
    ?item wdt:P31 wd:Q68663;
          wdt:P1495 wd:Q6534265 .
	}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research problems
	local totalMathModels = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Model"
    local totalMathModelsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalMathModels))
    table.insert(MathModDBStatistics, "| Mathematical Models: " .. totalMathModelsWithUrl)



----------------Computational Tasks---------------------------------------------  
	-- Q6534247 refers to computational task
	-- Q6534265 refers to MathModDB community
	local sparqlQuery = [[
	SELECT ?Computational_Tasks 
	WHERE {
    	?item wdt:P31 wd:Q6534247;
    	      wdt:P1495 wd:Q6534265 .
	}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research problems
	local totalCompTasks = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Task"
    local totalCompTasksWithUrl = string.format('[%s %s]', tostring(url), tostring(totalCompTasks))
    table.insert(MathModDBStatistics, "| Computational Tasks: " .. totalCompTasksWithUrl)
    
----------------Mathematical Formulations---------------------------------------  
	-- Q6481152 refers to mathematical formulation
	-- Q6534265 refers to MathModDB community
	local sparqlQuery = [[
	SELECT ?Mathematical_Formulations 
	WHERE {
    	?item wdt:P31 wd:Q6481152;
        	  wdt:P1495 wd:Q6534265 .
	}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research problems
	local totalMathFormulations = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Formula"
    local totalMathFormulationsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalMathFormulations))
    table.insert(MathModDBStatistics, "| Mathematical Formulations: " .. totalMathFormulationsWithUrl)


---------------------------Quantities-------------------------------------------  
	-- Q6534237 refers to quantity            
	-- Q6534265 refers to MathModDB community

	local sparqlQuery = [[
	SELECT ?Quantities 
	WHERE {
    	?item wdt:P31 wd:Q6534237;
        	  wdt:P1495 wd:Q6534265 .
	}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research problems
	local totalQuantities = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Quantity"
    local totalQuantitiesWithUrl = string.format('[%s %s]', tostring(url), tostring(totalQuantities))
    table.insert(MathModDBStatistics, "| Quantities: " .. totalQuantitiesWithUrl)

---------------------------Quantity Kinds---------------------------------------  
	-- Q6534245 refers to quantity kind
	-- Q6534265 refers to MathModDB community

	local sparqlQuery = [[
	SELECT ?Quantity_Kinds 
	WHERE {
    	?item wdt:P31 wd:Q6534245;
        	  wdt:P1495 wd:Q6534265 .
	}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	-- Get the number of research problems
	local totalQuantityKinds = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Quantity"
    local totalQuantityKindsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalQuantityKinds))
    table.insert(MathModDBStatistics, "| Quantity Kinds: " .. totalQuantityKindsWithUrl)


    -- Construct the Wikitext table
    	local wikitextTable = [[
{| class="wikitable" style="table-layout: fixed; width: 300px;"
]] .. table.concat(MathModDBStatistics, "\n|-\n") .. "\n|}"
    	return wikitextTable


end

return p