Module:MathModDB: Difference between revisions

From MaRDI portal
No edit summary
No edit summary
 
(24 intermediate revisions by the same user not shown)
Line 14: Line 14:
local MathModDBStatistics = {}
local MathModDBStatistics = {}


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


----------------Research Problems-------------------------------------------   
----------------Research Problems-------------------------------------------   
-- Q6032837 refers to research problem   
-- Q6534292 refers to research problem   
-- Q6534265 refers to MathModDB community  
-- Q6534265 refers to MathModDB community  
local sparqlQuery = [[
local sparqlQuery = [[
SELECT ?Research_Problems
SELECT ?Research_Problems
WHERE {
WHERE {
?item wdt:P31 wd:Q6032837;
?item wdt:P31 wd:Q6534292;
           wdt:P1495 wd:Q6534265 .
           wdt:P1495 wd:Q6534265 .
}
}
Line 101: Line 101:
     table.insert(MathModDBStatistics, "| Computational Tasks: " .. totalCompTasksWithUrl)
     table.insert(MathModDBStatistics, "| Computational Tasks: " .. totalCompTasksWithUrl)
      
      
----------------Mathematical Formulations---------------------------------------   
----------------Mathematical Expressions---------------------------------------   
-- Q6481152 refers to mathematical formulation
-- Q6481152 refers to mathematical expresion
-- Q6534265 refers to MathModDB community
-- Q6534265 refers to MathModDB community
local sparqlQuery = [[
local sparqlQuery = [[
SELECT ?Mathematical_Formulations
SELECT ?Mathematical_Expressions
WHERE {
WHERE {
     ?item wdt:P31 wd:Q6481152;
     ?item wdt:P31 wd:Q6481152;
Line 115: Line 115:
jsonResults = sparql.runQuery(sparqlQuery)
jsonResults = sparql.runQuery(sparqlQuery)
-- Get the number of research problems
-- Get the number of research problems
local totalMathFormulations = #jsonResults.results.bindings  + 1
local totalMathExpressions = #jsonResults.results.bindings  + 1
     -- Construct the Portal URL
     -- Construct the Portal URL
     url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Formula"
     url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Formula"
     local totalMathFormulationsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalMathFormulations))
     local totalMathExpressionsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalMathExpressions))
     table.insert(MathModDBStatistics, "| Mathematical Formulationss: " .. totalMathFormulationsWithUrl)
     table.insert(MathModDBStatistics, "| Mathematical Expressions: " .. totalMathExpressionsWithUrl)




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




----------------total number of individuals in MathModDB------------------------
local totalNumberOfIndividuals = totalAcademicDisciplines + totalResearchProblems + totalMathModels + totalCompTasks + totalMathExpressions + totalQuantities + totalQuantityKinds
table.insert(MathModDBStatistics, "| '''Total number of individuals: " .. totalNumberOfIndividuals .. "'''")
------------------------number of Statements in MathModDB-----------------------
local sparqlQuery = [[
SELECT (COUNT(*) AS ?statements)
WHERE {
# Restrict to items where P1495 = Q6534265
?item wdt:P1495 wd:Q6534265 .
# Count all triples related to those items
?item ?p ?o .
# Filter out statement nodes
FILTER(!STRSTARTS(STR(?o), "https://portal.mardi4nfdi.de/entity/statement/"))
# Exclude predicates in the wikibase: namespace
FILTER(!STRSTARTS(STR(?p), STR(wikibase:)))
# Exclude specific schema predicates
FILTER(?p NOT IN (schema:version, schema:dateModified))
}
]]
-- Executing the SPARQL query and retrieving results in JSON format
jsonResults = sparql.runQuery(sparqlQuery)
local totalStatements = 0
if jsonResults then
totalStatements = jsonResults.results.bindings[0].statements.value
end
table.insert(MathModDBStatistics, "| '''Total number of statements: " .. totalStatements .. "'''")
--------------------------------------------------------------------------------
     -- Construct the Wikitext table
     -- Construct the Wikitext table
     local wikitextTable = [[
     local wikitextTable = [[
{| class="wikitable" style="table-layout: fixed; width: 300px;"
{| class="wikitable" style="table-layout: fixed; width: 300px;"
]] .. table.concat(MathModDBStatistics, "\n|-\n") .. "\n|}"
]] .. table.concat(MathModDBStatistics, "\n|-\n") .. "\n|}"
    return wikitextTable




return wikitextTable
    -- return wikitextTable, totalNumberOfIndividuals
    -- return wikitextTable followed by a sentence that entails the total number of individuals
--local wikitextTableTotalNumberOfIndividuals = wikitextTable .. "\n\n'''Total number of individuals is " .. totalNumberOfIndividuals .. ".'''"
--return wikitextTableTotalNumberOfIndividuals
-- end function getMathModDBStatistics
end
end


return p
return p

Latest revision as of 10:46, 1 December 2025

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 = {}

	----------------Academic Disciplines----------------------------------------
	-- Q60231 refers to academic discipline 
	-- Q6534265 refers to MathModDB community
	local sparqlQuery = [[
	SELECT ?Academic_Disciplines
	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 academic disciplines
	local totalAcademicDisciplines = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    local url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Academic_discipline"
    local totalAcademicDisciplinesWithUrl = string.format('[%s %s]', tostring(url), tostring(totalAcademicDisciplines))
    table.insert(MathModDBStatistics, "| Academic Disciplines: " .. totalAcademicDisciplinesWithUrl)
    

	----------------Research Problems-------------------------------------------  
	-- Q6534292 refers to research problem   
	-- Q6534265 refers to MathModDB community 
	local sparqlQuery = [[
	SELECT ?Research_Problems
	WHERE {
		?item wdt:P31 wd:Q6534292;
        	  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 Expressions---------------------------------------  
	-- Q6481152 refers to mathematical expresion
	-- Q6534265 refers to MathModDB community
	local sparqlQuery = [[
	SELECT ?Mathematical_Expressions 
	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 totalMathExpressions = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/Formula"
    local totalMathExpressionsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalMathExpressions))
    table.insert(MathModDBStatistics, "| Mathematical Expressions: " .. totalMathExpressionsWithUrl)


---------------------------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 quantity kinds
	local totalQuantityKinds = #jsonResults.results.bindings  + 1
	
    -- Construct the Portal URL
    url = "https://portal.mardi4nfdi.de/wiki/MathModDB/QuantityKind"
    local totalQuantityKindsWithUrl = string.format('[%s %s]', tostring(url), tostring(totalQuantityKinds))
    table.insert(MathModDBStatistics, "| Quantity Kinds: " .. totalQuantityKindsWithUrl)


----------------total number of individuals in MathModDB------------------------

	local totalNumberOfIndividuals = totalAcademicDisciplines + totalResearchProblems + totalMathModels + totalCompTasks + totalMathExpressions + totalQuantities + totalQuantityKinds
	
	table.insert(MathModDBStatistics, "| '''Total number of individuals: " .. totalNumberOfIndividuals .. "'''")
	
	
------------------------number of Statements in MathModDB-----------------------	
	
	local sparqlQuery = [[
	SELECT (COUNT(*) AS ?statements)
	WHERE {
		# Restrict to items where P1495 = Q6534265
		?item wdt:P1495 wd:Q6534265 .

		# Count all triples related to those items
		?item ?p ?o .
		# Filter out statement nodes
		FILTER(!STRSTARTS(STR(?o), "https://portal.mardi4nfdi.de/entity/statement/"))
		# Exclude predicates in the wikibase: namespace
		FILTER(!STRSTARTS(STR(?p), STR(wikibase:)))
		# Exclude specific schema predicates
		FILTER(?p NOT IN (schema:version, schema:dateModified))
		}
	]]

	-- Executing the SPARQL query and retrieving results in JSON format
	jsonResults = sparql.runQuery(sparqlQuery)
	
	local totalStatements = 0
	if jsonResults then
		totalStatements = jsonResults.results.bindings[0].statements.value
	end

	table.insert(MathModDBStatistics, "| '''Total number of statements: " .. totalStatements .. "'''")

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


	
		return wikitextTable
    	-- return wikitextTable, totalNumberOfIndividuals
    	-- return wikitextTable followed by a sentence that entails the total number of individuals
		--local wikitextTableTotalNumberOfIndividuals = wikitextTable .. "\n\n'''Total number of individuals is " .. totalNumberOfIndividuals .. ".'''"
		--return wikitextTableTotalNumberOfIndividuals

-- end function getMathModDBStatistics
end


return p