drepr.utils.namespace_mixin#

Classes

NamespaceManager(prefix2ns, ns2prefix, ...)

A helper class for converting between absolute URI and relative URI.

NamespaceMixin()

PrefixIndex(index, start, end)

Namespace indexing so we can quickly get prefix of a URI.

class NamespaceMixin[source]#

Bases: object

prefixes: dict[str, str]#
property namespace_manager#
classmethod is_rel_iri(iri: str) bool[source]#
Parameters:

iri (str) –

Return type:

bool

get_rel_iri(abs_iri: str) str[source]#

Convert an absolute IRI to a relative IRI.

Parameters:

abs_iri (str) –

Return type:

str

get_abs_iri(rel_iri: str) str[source]#

Convert a relative IRI to an absolute IRI.

Parameters:

rel_iri (str) –

Return type:

str

class NamespaceManager(prefix2ns: dict[str, str], ns2prefix: dict[str, str], prefix_index: PrefixIndex)[source]#

Bases: object

A helper class for converting between absolute URI and relative URI.

Parameters:
prefix2ns#
ns2prefix#
prefix_index#
prefix2len#
classmethod from_prefix2ns(prefix2ns: dict[str, str])[source]#
Parameters:

prefix2ns (dict[str, str]) –

normalizeUri(uri: str) str[source]#
Parameters:

uri (str) –

Return type:

str

class PrefixIndex(index: dict[str, drepr.utils.namespace_mixin.PrefixIndex | str], start: int, end: int)[source]#

Bases: object

Namespace indexing so we can quickly get prefix of a URI.

Parameters:
index#
start#
end#
static create(ns2prefix: Mapping[str, str])[source]#
Parameters:

ns2prefix (Mapping[str, str]) –

get(uri: str) Optional[str][source]#

Get prefix of an uri. Return None if it is not found

Parameters:

uri (str) –

Return type:

Optional[str]

to_dict()[source]#