CLI utilities¶
kurra.cli.utils ¶
Formatting helpers that convert SPARQL and SHACL results into CLI-friendly output.
format_sparql_response_as_rich_table ¶
format_sparql_response_as_rich_table(response: SPARQLResult | Graph | dict, query: str) -> Table | str
Format a SPARQL query result for terminal display using print.
CONSTRUCT/DESCRIBE results and RDF graphs are serialized as longturtle, SELECT and ASK results are rendered as a Rich table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SPARQLResult | Graph | dict
|
The parsed SPARQL response - an rdflib |
required |
query
|
str
|
The original SPARQL query string, used for determining query type. |
required |
Returns:
| Type | Description |
|---|---|
Table | str
|
A Rich |
Source code in kurra/cli/utils.py
format_sparql_response_as_json ¶
Serialize a SPARQL query result to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SPARQLResult | dict
|
The parsed SPARQL response - either an rdflib |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If a value in the response cannot be converted to a JSON-serializable or RDF literal form. |
Returns:
| Type | Description |
|---|---|
str
|
A JSON-formatted string of the response. |
Source code in kurra/cli/utils.py
format_sparql_response_as_csv ¶
Format a SPARQL query result as CSV.
CONSTRUCT/DESCRIBE results and RDF graphs are serialized as longturtle instead of CSV, since they aren't tabular.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
SPARQLResult | Graph | dict
|
The parsed SPARQL response - an rdflib |
required |
query
|
str
|
The original SPARQL query string, used for determining query type. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A CSV-formatted string for SELECT/ASK results, or a longturtle-serialized string for CONSTRUCT/DESCRIBE/graph results. |
Source code in kurra/cli/utils.py
format_shacl_graph_as_rich_table ¶
Build a Rich table of SHACL validation results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
An RDF graph containing SHACL |
required |
Returns:
| Type | Description |
|---|---|
Table
|
A Rich |
Source code in kurra/cli/utils.py
format_shacl_summary_as_rich_table ¶
Build a Rich table summarizing SHACL validation results by shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
An RDF graph containing a SHACL validation summary report ( |
required |
Returns:
| Type | Description |
|---|---|
Table
|
A Rich |