File commands¶
Reformatting with context and indentation¶
kurra file reformat accepts --context (short flag -t) as inline JSON or a path to a UTF-8 JSON context file.
The value must contain a valid JSON-LD context, either wrapped in @context or as a bare mapping. Invalid contexts
produce a CLI error before output files are written. When the input is a directory, the context applies to every RDF file.
For Turtle and N3 output, the context's namespace prefixes are used to shorten IRIs. This example adds the ex prefix
to the default longturtle output, allowing https://example.org/alice to be written as ex:alice:
For JSON-LD output, the context is passed to PyLD's compact(). Use a context file and --indent to choose the number
of spaces for indentation (default 4, minimum 0):
For example, context.jsonld can contain:
--indent only affects JSON-LD output when --context is supplied.
kurra.cli.commands.file ¶
CLI commands for working with RDF files.
reformat_command ¶
reformat_command(file_or_dir: str = typer.Argument(..., help='The file or directory of RDF files to be formatted'), check: bool = typer.Option(False, '--check', '-c', help='Check whether files will be formatted without applying the effect.'), output_format: str = typer.Option('longturtle', '--output-format', '-f', help=f'Indicate the output RDF format. Available are {list(RDF_FILE_SUFFIXES.keys())}.'), output_filename: str = typer.Option(None, '--output-filename', '-o', help='the name of the file you want to write the reformatted content to'), context: str | None = typer.Option(None, '--context', '-t', help='A JSON-LD context as inline JSON or a path to a JSON file.'), indent: int = typer.Option(4, '--indent', min=0, help='Number of spaces used to indent compacted JSON-LD output.')) -> None
Reformat one RDF file or every RDF file in a directory to a given format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_or_dir
|
str
|
The file or directory of RDF files to be formatted. |
Argument(..., help='The file or directory of RDF files to be formatted')
|
check
|
bool
|
If True, check whether files will be changed by this command without applying the effect. |
Option(False, '--check', '-c', help='Check whether files will be formatted without applying the effect.')
|
output_format
|
str
|
The RDF serialization to write. See |
Option('longturtle', '--output-format', '-f', help=f'Indicate the output RDF format. Available are {list(keys())}.')
|
output_filename
|
str
|
The name of the file to write the reformatted content to. |
Option(None, '--output-filename', '-o', help='the name of the file you want to write the reformatted content to')
|
context
|
str | None
|
An inline JSON-LD context or a path to a context file, supplied
with |
Option(None, '--context', '-t', help='A JSON-LD context as inline JSON or a path to a JSON file.')
|
indent
|
int
|
Nonnegative indentation for compacted JSON-LD output. Defaults to 4 spaces. Only applies when a context and JSON-LD output are selected. |
Option(4, '--indent', min=0, help='Number of spaces used to indent compacted JSON-LD output.')
|
Raises:
| Type | Description |
|---|---|
SystemExit
|
With status 1, if |
Source code in kurra/cli/commands/file.py
merge_command ¶
merge_command(files: list[Path], destination: Path | None = None, output_format: str = 'longturtle') -> None
Merge multiple RDF files into a single graph or dataset document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
files
|
list[Path]
|
The RDF files to merge. |
required |
destination
|
Path | None
|
The output file path. If omitted, the merged RDF is printed. |
None
|
output_format
|
str
|
The RDFLib serialization format for the merged RDF. See |
'longturtle'
|
Source code in kurra/cli/commands/file.py
hierarchy_command ¶
Print the class, property, or concept hierarchy found in an RDF source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_or_url
|
str
|
An RDF file path or HTTP URL. |
required |
graph_iri
|
str | None
|
The named graph to use, for remote, TriG, or JSON-LD sources. |
None
|
use_names
|
bool
|
If True, display resource names instead of IRIs where available. |
False
|
Source code in kurra/cli/commands/file.py
quads_command ¶
Export (prints or saves) triples from an RDF source as quads under a given graph identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_or_str
|
Path
|
The RDF file to read triples from. |
required |
graph_iri
|
str
|
The graph IRI to assign to every exported quad. |
required |
destination
|
Path
|
The path of the file to save the quads to. If omitted, the result is printed to the console. |
None
|
Source code in kurra/cli/commands/file.py
query_command ¶
query_command(path_or_url: Path, q: str, response_format: str = typer.Option('table', '--response-format', '-f', help="The response format of the SPARQL query. Either 'table' (default) or 'json'"), username: str = None, password: str = None, timeout: int = 60) -> None
Run a SPARQL query against a local RDF file or a remote SPARQL endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_or_url
|
Path
|
A local RDF file path or a SPARQL endpoint URL to query. |
required |
q
|
str
|
A SPARQL query string, or the path to a file containing one. |
required |
response_format
|
str
|
The response format of the SPARQL query. Either |
Option('table', '--response-format', '-f', help="The response format of the SPARQL query. Either 'table' (default) or 'json'")
|
username
|
str
|
Fuseki username, if the endpoint requires authentication. |
None
|
password
|
str
|
Fuseki password, if the endpoint requires authentication. |
None
|
timeout
|
int
|
Timeout per request, in seconds. |
60
|