Skip to content

ontocast.util

iri2namespace(iri, ontology=False)

Convert an IRI to a namespace string.

Parameters:

Name Type Description Default
iri str

The IRI to convert.

required
ontology bool

If True, append '#' for ontology namespace, otherwise '/'.

False

Returns:

Name Type Description
str str

The converted namespace string.

Source code in ontocast/util.py
def iri2namespace(iri: str, ontology: bool = False) -> str:
    """Convert an IRI to a namespace string.

    Args:
        iri: The IRI to convert.
        ontology: If True, append '#' for ontology namespace, otherwise '/'.

    Returns:
        str: The converted namespace string.
    """
    iri = iri.rstrip("#")
    return f"{iri}#" if ontology else f"{iri}/"

render_text_hash(text, digits=12)

Generate a hash for the given text.

Parameters:

Name Type Description Default
text str

The text to hash

required
digits

Number of digits in the hash (default: 12)

12

Returns:

Type Description
str

A string hash of the text

Source code in ontocast/util.py
def render_text_hash(text: str, digits=12) -> str:
    """
    Generate a hash for the given text.

    Args:
        text: The text to hash
        digits: Number of digits in the hash (default: 12)

    Returns:
        A string hash of the text
    """
    return hashlib.sha256(text.encode()).hexdigest()[:digits]