Skip to content

Label commands

Find duplicate names or descriptions

Use kurra labels duplicates with an RDF file or directory to print a table of nodes with multiple distinct annotation literals. Names are checked by default:

kurra labels duplicates vocabulary.ttl
kurra labels duplicates vocabulary.ttl --names-or-descriptions names

To check descriptions instead, use --names-or-descriptions (short form -n):

kurra labels duplicates vocabulary.ttl --names-or-descriptions descriptions
kurra labels duplicates vocabulary.ttl -n descriptions

The only accepted annotation types are names and descriptions. Names use schema:name, rdfs:label, dcterms:title, and skos:prefLabel; descriptions use schema:description, rdfs:comment, dcterms:description, and skos:definition. The schema: predicates use the https://schema.org/ namespace.

Supply full predicate IRIs with --additional-annotation-predicates (short form -a) to extend the default predicates. Repeat the option for each additional IRI:

kurra labels duplicates vocabulary.ttl \
  --additional-annotation-predicates https://example.com/displayName \
  --additional-annotation-predicates https://example.com/shortName

kurra labels duplicates vocabulary.ttl -n descriptions \
  -a https://example.com/description

The table contains a Node column and a Names or Descriptions column. Literal values retain their RDF notation, including language tags and datatypes. Identical literals under different predicates count once; differences in spelling, datatype, or language count separately, including language versus no language. Comparisons use values as stored by RDFLib, which may normalize typed literals when reading the source.

If no duplicates are found, the command prints No nodes with duplicate names or No nodes with duplicate descriptions. The input file or directory must exist. For all options, run:

kurra labels duplicates --help

Command reference

kurra.cli.commands.labels

CLI commands for managing RDF labels.

find_duplicate_labels_command

find_duplicate_labels_command(p: Path, names_or_descriptions: Literal['names', 'descriptions'] = 'names', additional_annotation_predicates: list[str] | None = None) -> None

Print nodes with multiple distinct annotation literals as a table.

Parameters:

Name Type Description Default
p Path

The RDF file or directory to scan.

required
names_or_descriptions Literal['names', 'descriptions']

Check names (default) or descriptions.

'names'
additional_annotation_predicates list[str] | None

Additional predicate IRIs, supplied by repeating the option.

None
Source code in kurra/cli/commands/labels.py
@app.command(name="duplicates", help="Find nodes with distinct names or descriptions")
def find_duplicate_labels_command(
    p: Annotated[
        Path,
        typer.Argument(exists=True, help="The RDF file or directory to scan"),
    ],
    names_or_descriptions: Annotated[
        Literal["names", "descriptions"],
        typer.Option(
            "--names-or-descriptions", "-n", help="The annotation type to check"
        ),
    ] = "names",
    additional_annotation_predicates: Annotated[
        list[str] | None,
        typer.Option(
            "--additional-annotation-predicates",
            "-a",
            help="An additional annotation predicate IRI; repeat for multiple IRIs",
        ),
    ] = None,
) -> None:
    """Print nodes with multiple distinct annotation literals as a table.

    Args:
        p: The RDF file or directory to scan.
        names_or_descriptions: Check names (default) or descriptions.
        additional_annotation_predicates: Additional predicate IRIs, supplied by
            repeating the option.
    """
    duplicates = find_duplicate_labels(
        p,
        names_or_descriptions,
        [URIRef(iri) for iri in additional_annotation_predicates or []],
    )
    if not duplicates:
        console.print(f"No nodes with duplicate {names_or_descriptions}")
        return

    table = Table(show_header=True, header_style="b")
    table.add_column("Node")
    table.add_column(names_or_descriptions.capitalize())
    for node, values in sorted(duplicates.items(), key=lambda item: str(item[0])):
        table.add_row(
            Text(node.n3()),
            Text("\n".join(sorted(value.n3() for value in values))),
        )
    console.print(table)

find_command

find_command(f: str = typer.Argument(..., help='The RDF file to fine IRIs missing labels within'), local_context: str = typer.Option(None, '--local-context', '-l', help='An RDF file or directory of RDF files containing labels')) -> None

Print every IRI in an RDF file or directory that is missing an rdfs:label.

Parameters:

Name Type Description Default
f str

The RDF file or directory of RDF files to scan for IRIs missing labels.

Argument(..., help='The RDF file to fine IRIs missing labels within')
local_context str

An RDF file or directory of files containing labels to check against, in addition to f itself.

Option(None, '--local-context', '-l', help='An RDF file or directory of RDF files containing labels')
Source code in kurra/cli/commands/labels.py
@app.command(name="find", help="Find IRIs missing labels")
def find_command(
    f: str = typer.Argument(
        ..., help="The RDF file to fine IRIs missing labels within"
    ),
    local_context: str = typer.Option(
        None,
        "--local-context",
        "-l",
        help="An RDF file or directory of RDF files containing labels",
    ),
) -> None:
    """Print every IRI in an RDF file or directory that is missing an `rdfs:label`.

    Args:
        f: The RDF file or directory of RDF files to scan for IRIs missing labels.
        local_context: An RDF file or directory of files containing labels to check against, in addition to `f` itself.
    """
    if Path(f).is_file() or Path(f).is_dir():
        if local_context is not None:
            if Path(local_context).is_file() or Path(local_context).is_dir():
                for iri in find_missing_labels(Path(f), Path(local_context)):
                    console.print(iri)
            else:
                console.print(
                    "[red]If a value for local context is given, it must be an existing file or directory[/red]"
                )
        else:
            for iri in find_missing_labels(Path(f)):
                console.print(iri)
    else:
        console.print(
            "[red]The value for f must be an existing file or directory[/red]"
        )

get_command

get_command(f: str = typer.Argument(..., help='The RDF file to fine IRIs missing labels within'), local_context: str = typer.Option(None, '--local-context', '-l', help='An RDF file or directory of RDF files containing labels'), additional_context: str = typer.Option('https://fuseki.dev.kurrawong.ai/semback/sparql', '--additional-context', '-c', help='An additional source of labels'), return_type: str = typer.Option('graph', '--return-type', '-r', help="Return RDF in the longturtle format or a printed table of IRIs and labels. Either 'graph' or 'table'")) -> None

Fetch and print labels for IRIs that are missing them from a given context (local_context) or additional context (additional_context), by default the KurrawongAI Semantic Background.

Parameters:

Name Type Description Default
f str

The RDF file or directory of RDF files to scan for IRIs missing labels.

Argument(..., help='The RDF file to fine IRIs missing labels within')
local_context str

An RDF file or directory of files containing labels to check against, in addition to f itself.

Option(None, '--local-context', '-l', help='An RDF file or directory of RDF files containing labels')
additional_context str

A further RDF source (file, directory, or SPARQL endpoint) to fetch missing labels from.

Option('https://fuseki.dev.kurrawong.ai/semback/sparql', '--additional-context', '-c', help='An additional source of labels')
return_type str

graph to output longturtle RDF, table for a printed table of IRIs and labels.

Option('graph', '--return-type', '-r', help="Return RDF in the longturtle format or a printed table of IRIs and labels. Either 'graph' or 'table'")
Source code in kurra/cli/commands/labels.py
@app.command(
    name="get",
    help="Gets labels for IRIs missing them from a given context or the KurrawongAI Semantic Background",
)
def get_command(
    f: str = typer.Argument(
        ..., help="The RDF file to fine IRIs missing labels within"
    ),
    local_context: str = typer.Option(
        None,
        "--local-context",
        "-l",
        help="An RDF file or directory of RDF files containing labels",
    ),
    additional_context: str = typer.Option(
        "https://fuseki.dev.kurrawong.ai/semback/sparql",
        "--additional-context",
        "-c",
        help="An additional source of labels",
    ),
    return_type: str = typer.Option(
        "graph",
        "--return-type",
        "-r",
        help="Return RDF in the longturtle format or a printed table of IRIs and labels. Either 'graph' or 'table'",
    ),
) -> None:
    """Fetch and print labels for IRIs that are missing them from a given context (`local_context`) or additional context (`additional_context`), by default the KurrawongAI Semantic Background.

    Args:
        f: The RDF file or directory of RDF files to scan for IRIs missing labels.
        local_context: An RDF file or directory of files containing labels to check against, in addition to `f` itself.
        additional_context: A further RDF source (file, directory, or SPARQL endpoint) to fetch missing labels from.
        return_type: `graph` to output longturtle RDF, `table` for a printed table of IRIs and labels.
    """
    iris = []
    if Path(f).is_file() or Path(f).is_dir():
        if local_context is not None:
            if Path(local_context).is_file() or Path(local_context).is_dir():
                iris = find_missing_labels(Path(f), Path(local_context))
            else:
                console.print(
                    "[red]If a value for local context is given, it must be an existing file or directory[/red]"
                )
        else:
            iris = find_missing_labels(Path(f))
    else:
        console.print(
            "[red]The value for f must be an existing file or directory[/red]"
        )

    if iris:
        if Path(additional_context).is_file() or Path(additional_context).is_dir():
            rdf = get_labels(iris, Path(additional_context, return_type))
        else:
            rdf = get_labels(iris, additional_context, return_type)

        if return_type == "graph":
            console.print(rdf.serialize(format="longturtle"))
        else:
            t = Table(show_header=True, header_style="b")
            t.add_column("IRI", no_wrap=True)
            t.add_column("Label", no_wrap=True)
            for iri, label in rdf.items():
                t.add_row(iri, label)
            console.print(t)
    else:
        console.print("No IRIs missing labels")

context_command

context_command(rdf: Path, local_context: Path | None = None) -> None

Generate a JSON-LD context from the labels in a given RDF file.

Parameters:

Name Type Description Default
rdf Path

The RDF file to generate a JSON-LD context from.

required
local_context Path | None

An RDF file or directory of files containing labels to source from, in addition to rdf itself.

None
Source code in kurra/cli/commands/labels.py
@app.command(
    "context", help="Generate a JSON-LD context based on the labels in a given RDF file"
)
def context_command(
    rdf: Annotated[
        Path, typer.Argument(help="The RDF file to generate a JSON-LD context from")
    ],
    local_context: Annotated[
        Path | None,
        typer.Option(
            "--local-context",
            "-l",
            help="An RDF file or directory of RDF files containing labels",
        ),
    ] = None,
) -> None:
    """Generate a JSON-LD context from the labels in a given RDF file.

    Args:
        rdf: The RDF file to generate a JSON-LD context from.
        local_context: An RDF file or directory of files containing labels to source from, in addition to `rdf` itself.
    """
    if local_context is not None:
        ctx = jsonld_context(load_graph(rdf), load_graph(local_context))
    else:
        ctx = jsonld_context(load_graph(rdf))
    json.dump(ctx, stdout, indent=4)