Module:PersonOtherProperties/doc: Difference between revisions

From MaRDI portal
No edit summary
No edit summary
 
Line 1: Line 1:
== Overview ==
== Overview ==
This Lua module is designed to query SPARQL endpoints and display the results in an HTML table on a MediaWiki page. It is specifically tailored for handling and presenting data from a given Wikidata entity. The module processes SPARQL query results, formats them, and renders an HTML table suitable for embedding in wiki pages.
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).
 
The module operates by executing the SPARQL query against a specified Wikidata entity. The query is constructed to retrieve a set of properties (?property), their labels (?propertyLabel), and their corresponding values (?value) for the target entity. In cases where a value is another Wikidata entity, an optional clause in the query attempts to fetch the label (?valueLabel) for these entities, enhancing the readability of the results.


== Dependencies ==
== Dependencies ==

Latest revision as of 11:25, 8 December 2023

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.