prov.identifier

prov.identifier implements PROV’s namespaced identifiers. A Namespace groups identifiers under a URI and an optional prefix. A QualifiedName combines a namespace with a local part to name entities, activities, agents and attributes. Identifier is the common base class; an Identifier given as an attribute value is stored as an xsd:anyURI Literal. prov.model.NamespaceManager (see prov.model) tracks the namespaces registered on a bundle and resolves prefixes during parsing and serialization.

class prov.identifier.Identifier(uri: str)[source]

Bases: object

Base class for all identifiers.

Its fields are read-only after construction. Assigning or deleting one raises AttributeError, while a subclass may still set attributes of its own.

property uri: str

The URI associated with the current identifier.

provn_representation() → str[source]

Return the PROV-N representation of this identifier as an xsd:anyURI literal.

class prov.identifier.QualifiedName(namespace: Namespace, localpart: str)[source]

Bases: Identifier

Represents a qualified name, which combines a namespace and a local part for use in identifying entities in a namespace-aware context.

Its fields are read-only after construction. Assigning or deleting one raises AttributeError, while a subclass may still set attributes of its own.

property namespace: Namespace

Namespace of qualified name.

property localpart: str

Local part of qualified name.

provn_bare_representation() → str[source]

Return the prefix:local PROV-N form used at IDENTIFIER positions.

The local part’s PROV-N metacharacters (= ' ( ) , : ; [ ]) are backslash-escaped, as are a leading - or . and a trailing ., which PROV-N does not allow bare. The prefix is never escaped, as it cannot contain these characters.

Raises:

ProvException – If the local part is empty and the namespace has no prefix, which has no PROV-N spelling.

provn_representation() → str[source]

Return the PROV-N representation of this qualified name as a quoted string.

class prov.identifier.Namespace(prefix: str, uri: str)[source]

Bases: object

PROV Namespace.

A prefix is a SPARQL PN_PREFIX: it starts with a letter, and holds letters, digits, -, _, ., U+00B7 and the combining marks, but does not end with ..

Its fields are read-only after construction. Assigning or deleting one raises AttributeError, while a subclass may still set attributes of its own.

property uri: str

Namespace URI.

property prefix: str

Namespace prefix.

contains(identifier: str | Identifier) → bool[source]

Check whether the given identifier’s URI is contained in this namespace.

Parameters:

identifier – Identifier (or URI string) to check.

Returns:

True if the identifier’s URI starts with this namespace’s URI, False otherwise (including when the URI cannot be determined).

qname(identifier: str | Identifier) → QualifiedName | None[source]

Resolve an identifier to a QualifiedName in this namespace.

Parameters:

identifier – Identifier (or URI string) to resolve.

Returns:

A new QualifiedName in this namespace if identifier’s URI starts with this namespace’s URI, otherwise None.