kapps_triplestore_interface.utils.iri#

class kapps_triplestore_interface.utils.iri.IRI(value: str, base: str | None = None, prefixes: Dict[str, str] | None = None)[source]#

Bases: URIRef

Lightweight IRI wrapper with prefix support and validation.

The stored format is a full IRI string, eg. http://example.org#Name. Prefixes are resolved from the provided dictionary or class-level registry.

Valid input formats are:

  • Full IRIs without fragments: http://example.org

  • Prefixes without fragments: prefix:

  • Full IRI with fragment: http://example.org#Name

  • Prefixes with fragments: prefix:Name

Validation supports:

  • str, rdflib.URIRef, IRI or other subclass of str inputs. rdflib.Literal or non-string inputs raise TypeError. If desired, convert to string explicitly before passing.

  • Separate base and name: base=”http://example.org”, value=”Name”.

  • Angle brackets <…>.

  • Trailing #, ` or `: from value and base.

PREFIXES = {'kafka': 'http://www.ontotext.com/connectors/kafka', 'kafka-inst': 'http://www.ontotext.com/connectors/kafka/instance', 'owl': 'http://www.w3.org/2002/07/owl', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns', 'rdfs': 'http://www.w3.org/2000/01/rdf-schema', 'xsd': 'http://www.w3.org/2001/XMLSchema'}#
PREFIXES_INV = {'http://www.ontotext.com/connectors/kafka': 'kafka', 'http://www.ontotext.com/connectors/kafka/instance': 'kafka-inst', 'http://www.w3.org/1999/02/22-rdf-syntax-ns': 'rdf', 'http://www.w3.org/2000/01/rdf-schema': 'rdfs', 'http://www.w3.org/2001/XMLSchema': 'xsd', 'http://www.w3.org/2002/07/owl': 'owl'}#
SCHEMES = {'http://', 'https://'}#
LINED_PATTERN = [('_', '__'), (':', '_c_'), ('/', '_s_'), ('.', '_d_'), ('#', '_h_')]#
LINED_PATTERN_INV = [('_h_', '#'), ('_d_', '.'), ('_s_', '/'), ('_c_', ':'), ('__', '_')]#
property short: str#

Return a prefixed form if the base is registered.

Returns:

prefix:name if the base IRI is known; otherwise the full IRI.

Return type:

str

property lined: str#

Convert IRI to valid Python identifier using reversible marker encoding.

Character encoding: - _ → __ (underscore escaped to preserve marker distinction) - : → _c_ (colon) - / → _s_ (slash) - . → _d_ (dot) - # → _h_ (hash)

This is a simple, human-readable alternative to Punycode—optimized for debugging and direct IRI recognition in code, not for compression.

Markers use mnemonic single letters (_c_=colon, _s_=slash, etc.) for easy visual decoding. Order of replacement matters for reversibility.

Example

https://www.sfb1574.kit.edu/ontologies/TransferUnit#hasConveyorBelt → https_c_www_d_sfb1574_d_kit_d_edu_s_ontologies_s_TransferUnit_h_hasConveyorBelt

classmethod from_lined(lined: str) → IRI[source]#

Decode a lined identifier back to full IRI.

Reverses the encoding applied by lined property. Decode order: _c_→:, _s_→/, _d_→., _h_→#, then __→_.

Example: https_c__s__s_example_d_com_h_Property → https://example.com#Property

property onto: str#

Return the ontology/base part of the IRI (before the ‘#’).

Returns:

The base IRI.

Return type:

str

classmethod add_prefix(prefix: str, iri: str) → None[source]#

Register or overwrite a prefix mapping.

Parameters:
  • prefix (str) – Prefix label (e.g., “ex”).

  • iri (str) – Base IRI to map (with or without angle brackets or trailing ‘#’).

classmethod remove_prefix(prefix: str) → bool[source]#

Remove a registered prefix mapping.

Parameters:

prefix (str) – The prefix label to remove.

Returns:

True if the prefix existed and was removed, False otherwise.

Return type:

bool

classmethod get_prefixes() → Dict[str, str][source]#

Get a copy of the current prefix registry.

Returns:

Mapping of prefix to base IRI (without trailing ‘#’).

Return type:

Dict[str, str]