pyowl2.base.iri

Defines a class representing an Internationalized Resource Identifier (IRI) that acts as a global identifier for entities within an OWL ontology by combining a namespace prefix with a specific local value.

Description

The software provides a robust mechanism for creating and managing Internationalized Resource Identifiers (IRIs) which function as unique global identifiers for ontology elements such as classes, properties, and individuals. By inheriting from abstract annotation interfaces, the implementation ensures compatibility with broader OWL data structures while leveraging the rdflib library to handle the underlying namespace logic and URI resolution. It encapsulates a namespace and a local value, allowing the conversion of these components into a standard URIRef object for seamless integration with RDF data stores. Furthermore, the design includes utility logic to recognize fundamental OWL concepts like owl:Thing and owl:Nothing, and it implements standard comparison and hashing protocols based on the string representation of the identifier to support use in collections and sorting operations.

Classes

IRI

This class models an Internationalized Resource Identifier (IRI), acting as a global identifier for entities within an ontology by combining a namespace prefix with a specific local value. It is primarily used to reference classes, individuals, or properties in OWL structures and can be instantiated by providing a Namespace object and an optional string identifier. The class facilitates interaction with RDF data by offering a method to convert the IRI into a URIRef, while also providing utility methods to identify standard OWL entities such as owl:Thing and owl:Nothing. Comparisons and string representations are handled based on the full resolved identifier.

Module Contents

UML Class Diagram for IRI

UML Class Diagram for IRI

class IRI(namespace: rdflib.Namespace, value: str | rdflib.URIRef = '')[source]

Bases: pyowl2.abstracts.annotation_subject.OWLAnnotationSubject, pyowl2.abstracts.annotation_value.OWLAnnotationValue

Inheritance diagram of pyowl2.base.iri.IRI

This class models an Internationalized Resource Identifier (IRI), acting as a global identifier for entities within an ontology by combining a namespace prefix with a specific local value. It is primarily used to reference classes, individuals, or properties in OWL structures and can be instantiated by providing a Namespace object and an optional string identifier. The class facilitates interaction with RDF data by offering a method to convert the IRI into a URIRef, while also providing utility methods to identify standard OWL entities such as owl:Thing and owl:Nothing. Comparisons and string representations are handled based on the full resolved identifier.

Parameters:
  • namespace (Namespace) – The base prefix or context for the identifier, representing a collection of related entities and combining with the specific value to construct the full Internationalized Resource Identifier.

  • value (Union[str, URIRef]) – The specific identifier for an entity, which can be a local string fragment combined with the namespace or a complete URI reference.

__str__() str[source]

Returns the string representation of the IRI in its URI-encoded form. By delegating to the to_uriref method, this ensures that the returned string is a valid URI reference, typically involving the percent-encoding of any non-ASCII characters present in the IRI. This behavior makes the object compatible with contexts requiring standard ASCII URIs, such as HTTP headers or legacy systems, while the internal representation may retain the original Unicode characters.

Returns:

The string representation of the URI reference.

Return type:

str

is_owl_nothing() bool[source]

Checks if the current IRI corresponds to the OWL Nothing entity, which represents the empty class in Web Ontology Language (OWL) semantics. The method performs this check by converting the object to a URI reference and comparing it against the standard owl:Nothing constant. It returns True if the identifiers match exactly, and False otherwise, without modifying the state of the object.

Returns:

True if the entity represents the OWL Nothing concept, False otherwise.

Return type:

bool

is_owl_thing() bool[source]

Determines whether the current IRI corresponds to the universal class ‘owl:Thing’ within the Web Ontology Language (OWL). The method performs a strict equality check by converting the IRI instance to a URI reference and comparing it against the standard OWL.Thing constant. It returns True if the identifiers match exactly, and False otherwise. This operation is read-only and does not modify the state of the IRI object.

Returns:

True if the object is the OWL Thing class, otherwise False.

Return type:

bool

static nothing_iri() Self[source]

Returns an IRI instance representing the OWL concept of “Nothing,” which denotes the empty class containing no instances. This static method constructs the IRI by combining the standard OWL namespace with the specific identifier for “Nothing,” providing a convenient accessor for this fundamental ontology term. The method creates a new IRI object upon each invocation.

Returns:

Returns the IRI for owl:Nothing.

Return type:

Self

static thing_iri() Self[source]

Returns an instance of the IRI class representing the owl:Thing concept, which serves as the root class of the class hierarchy in the OWL ontology. This static method generates the IRI by combining the standard OWL namespace with the specific identifier for ‘Thing’. The function requires no arguments and has no side effects, simply providing a convenient way to access the IRI for the universal class.

Returns:

Returns the IRI for owl:Thing.

Return type:

Self

to_uriref() rdflib.URIRef[source]

Converts the IRI instance into a concrete URIRef object by resolving it against the associated namespace. If the internal value is already a URIRef, it is returned directly; otherwise, the value is treated as a local identifier and used to construct a URIRef via the namespace. This method requires the namespace attribute to be a valid Namespace instance, raising an AssertionError if this condition is not met, and may propagate errors if the value cannot be resolved within the namespace context.

Returns:

A URIRef representing the fully qualified URI. Returns the value directly if it is already a URIRef, otherwise resolves it against the associated namespace.

Return type:

URIRef

_namespace: rdflib.Namespace
_value: str | rdflib.URIRef = ''
property namespace: rdflib.Namespace

Updates the namespace associated with the IRI instance by assigning the provided Namespace object to the internal state. This setter replaces any previously defined namespace, effectively altering the IRI’s context or prefix mapping. The operation mutates the object in place and does not return a value.

Parameters:

value (Namespace) – The Namespace object to assign to the instance.

property value: str | rdflib.URIRef

Updates the internal representation of the IRI by assigning the provided value to the private _value attribute. This setter accepts either a string or a URIRef object as input, performing no validation or type conversion before assignment. As a result, the internal state is modified directly to reflect the provided argument, regardless of whether it constitutes a valid IRI or matches the expected type strictly.

Parameters:

value (Union[str, URIRef]) – The full IRI to set, provided as either a string or a URIRef.