Module:PersonOtherProperties/doc

From MaRDI portal

This is the documentation page for Module:PersonOtherProperties

Overview

This Lua module queries the local SPARQL endpoints to show all known properties that are having a direct value (e.g. birthdate) and not a relationship (e.g doctoral student of).

Dependencies

SPARQL Module: Used for executing SPARQL queries. mw.html Module: Utilized for constructing HTML content, particularly for table generation.

Module Functions

buildTableFromSparql(frame)

Constructs an HTML table based on SPARQL query results related to a specified entity.

Parameters
* frame: A frame object containing arguments passed to the module. The first argument should be the entity ID.
Returns
* A string representing an HTML table with the SPARQL query results.
* If the target entity ID is not provided, it returns "No records found".
Description
This function forms a SPARQL query using the provided entity ID, executes the query, and processes the results into a formatted HTML table. It handles errors in SPARQL query execution and logs them for debugging. The table contains columns for properties and their values related to the entity.

convertJsonToTable(jsonResults)

Converts JSON-formatted SPARQL query results into a Lua table.

Parameters
* jsonResults: The JSON object containing the SPARQL query results.
Returns
* A Lua table representation of the SPARQL query results.
Description
Parses the JSON results from a SPARQL query and converts them into a structured Lua table for further processing.

createHtmlTableWithMergedCols(dataTable, headers)

Generates an HTML table from a Lua table with specified headers, merging certain columns for readability.

Parameters
* dataTable: The data table obtained from SPARQL query results.
* headers: A table of strings representing the headers for the HTML table.
Returns
* A string representing the constructed HTML table.
Description
Constructs an HTML table using mw.html. It merges specific columns from the data table based on their content (URLs or literal values) for better presentation in the HTML format.

Usage Example

To use this module in a MediaWiki template or page, invoke it with the necessary parameters, such as the Wikidata entity ID:

{{#invoke:YourModuleName|buildTableFromSparql|Q161115}}

Replace YourModuleName with the actual name of this module. The parameter (e.g., 'Q161115') should be the Wikidata entity ID for which you want to fetch and display data.

Debugging Example

For testing or debugging purposes, you can simulate the module's function in a Lua sandbox using:

local mockFrame = { args = { 'Q161115' } }
local result = p.buildTableFromSparql(mockFrame)
mw.log(result)

Replace 'Q161115' with the desired entity ID.