fuzzy_dl_owl2.fuzzydl.relation
A class representing a fuzzy role assertion that connects two individuals via a specific relationship type and a lower bound degree.
Description
The software models a role assertion within a fuzzy description logic framework, defining a binary connection between a subject individual and an object individual. It encapsulates the properties of the relationship, including the role name, the two participating entities, and a lower bound degree that represents the minimum truth value required for the assertion to hold. The design allows for the dynamic modification of the subject and object individuals after instantiation, ensuring flexibility in constructing and updating knowledge graphs. Furthermore, the implementation provides mechanisms for cloning the assertion to create independent copies and generating string representations that either include or exclude the degree constraint for various reporting needs.
Classes
This class models a role assertion connecting a subject individual to an object individual via a specific role, constrained by a lower bound degree. It serves as a container for the relationship's properties, storing the role name, the two involved individuals, and the minimum degree required for the assertion to hold. Users can instantiate this object to define such relationships, modify the subject or object individuals after creation, and retrieve string representations that include or exclude the degree constraint. Additionally, the class supports cloning to create independent copies of the assertion. |
Module Contents
UML Class Diagram for Relation
- class Relation(
- role_name: str,
- ind1: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual,
- ind2: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual,
- degree: fuzzy_dl_owl2.fuzzydl.degree.degree.Degree,
This class models a role assertion connecting a subject individual to an object individual via a specific role, constrained by a lower bound degree. It serves as a container for the relationship’s properties, storing the role name, the two involved individuals, and the minimum degree required for the assertion to hold. Users can instantiate this object to define such relationships, modify the subject or object individuals after creation, and retrieve string representations that include or exclude the degree constraint. Additionally, the class supports cloning to create independent copies of the assertion.
- Parameters:
role_name (str) – The name identifying the specific role or relationship type asserted between the subject and object individuals.
ind_a (Individual) – The subject individual of the role assertion.
ind_b (Individual) – The object individual of the role assertion.
degree (Degree) – The lower bound value for the role assertion.
- __repr__() str[source]
Returns the official string representation of the instance by delegating to the object’s informal string conversion method. This ensures that the output displayed in interactive sessions or logs is identical to the result of calling str() on the object. Since it relies on the underlying string conversion logic, any exceptions raised during that process will propagate through this method.
- Returns:
The string representation of the object.
- Return type:
str
- __str__() str[source]
Returns a human-readable string representation of the relation, formatted as ‘name >= degree’. The name component is retrieved by calling get_name_without_degree, while the degree component is taken directly from the object’s degree attribute. This method is automatically invoked by the str() built-in function and the print statement to provide a concise summary of the relation’s constraint.
- Returns:
A string representation of the object in the format “name >= degree”.
- Return type:
str
- clone() Self[source]
Creates and returns a distinct copy of the current Relation instance. This method instantiates a new Relation object using the current values of role_name, ind_a, ind_b, and degree, ensuring that the original object remains unmodified. The returned object is a separate entity, though it shares the same attribute values as the source at the moment of cloning.
- Returns:
A new instance of the class with identical attributes to the current object.
- Return type:
Self
- get_degree() fuzzy_dl_owl2.fuzzydl.degree.degree.Degree[source]
Retrieves the degree associated with this relation instance. This method serves as an accessor for the internal degree attribute, returning the stored Degree object. It performs no modifications to the object’s state and has no side effects.
- Returns:
The degree associated with the instance.
- Return type:
- get_name_without_degree() str[source]
Generates a human-readable string representation of the relation that omits any degree or lower bound information. The returned string is formatted as ‘(individual_a, individual_b): role_name’, incorporating the identifiers of the two entities involved and the name of the role connecting them. This method performs no modifications to the object’s state and relies on the existence of the ind_a, ind_b, and role_name attributes.
- Returns:
A string representation of the role assertion formatted as “(individual_a, individual_b): role_name”, excluding the lower bound.
- Return type:
str
- get_object_individual() fuzzy_dl_owl2.fuzzydl.individual.individual.Individual[source]
Returns the Individual instance that serves as the object of this relation. This method retrieves the target entity involved in the binary link, corresponding to the internal attribute ind_b. The operation is read-only and does not modify the state of the relation or the returned individual.
- Returns:
The Individual instance stored in the object.
- Return type:
- get_role_name() str[source]
Retrieves the name of the role associated with this relation instance. This method provides read access to the internal role_name attribute, which typically identifies the specific function or label of the entity within the relationship. It performs no modification of the object’s state and will return the exact string value stored, or raise an AttributeError if the attribute has not been initialized.
- Returns:
The name of the role.
- Return type:
str
- get_subject_individual() fuzzy_dl_owl2.fuzzydl.individual.individual.Individual[source]
Retrieves the individual entity that serves as the subject of this relation. This method returns the internal attribute ind_a, representing the source node or the first participant in the relationship. Since it returns a direct reference to the stored object, any modifications made to the returned instance will be reflected within the relation, and the method may raise an AttributeError if the relation has not been properly initialized.
- Returns:
The Individual object representing the subject.
- Return type:
- set_object_individual(ind: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual) None[source]
Updates the object of the relation by assigning the provided Individual instance to the internal attribute ind_b. This operation mutates the state of the Relation object, replacing any existing object individual with the new value. The method returns None and does not enforce type constraints at runtime, assuming the provided argument adheres to the Individual type hint.
- Parameters:
ind (Individual)
- set_subject_individual(ind: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual) None[source]
Assigns the provided Individual instance as the subject of the relation by updating the internal attribute ind_a. This method modifies the state of the object in place, overwriting any existing subject reference without performing additional validation or side effects on the input object. The operation returns None.
- Parameters:
ind (Individual) – The individual to be assigned as the subject.
- role_name: str