fuzzy_dl_owl2.fuzzydl.query.max.max_related_query
Determines the maximum degree of truth for a specific role relationship between two individuals within a fuzzy ontology using mathematical optimization.
Description
Designed to calculate the highest possible membership degree for a relationship assertion, the logic translates the semantic query into a Mixed-Integer Linear Programming (MILP) formulation. It achieves this by constructing a specific concept restriction that represents the role value, which is then used to define an objective expression aimed at maximizing the corresponding variable. The execution process ensures data integrity by cloning the knowledge base before performing any modifications, allowing the optimization to run on an isolated instance while the original remains untouched. Robustness is built into the workflow through exception handling that detects ontology inconsistencies, returning a designated solution status instead of propagating errors when the knowledge base cannot be satisfied.
Classes
This class models a query designed to determine the maximum degree of truth for a specific relationship between two individuals within a fuzzy knowledge base. It operates by formulating an optimization problem where the goal is to maximize the membership degree of the assertion that the first individual is related to the second individual via a specified role. To use this class, instantiate it with the two individuals involved and the name of the role, then invoke the solve method with a knowledge base instance to retrieve the optimal solution. The implementation handles potential ontology inconsistencies gracefully by returning a specific solution state. |
Module Contents
UML Class Diagram for MaxRelatedQuery
- class MaxRelatedQuery(
- a: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual,
- b: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual,
- role_name: str,
Bases:
fuzzy_dl_owl2.fuzzydl.query.related_query.RelatedQuery
This class models a query designed to determine the maximum degree of truth for a specific relationship between two individuals within a fuzzy knowledge base. It operates by formulating an optimization problem where the goal is to maximize the membership degree of the assertion that the first individual is related to the second individual via a specified role. To use this class, instantiate it with the two individuals involved and the name of the role, then invoke the solve method with a knowledge base instance to retrieve the optimal solution. The implementation handles potential ontology inconsistencies gracefully by returning a specific solution state.
- Parameters:
ind1 (Individual) – The first individual in the role assertion, representing the subject of the relationship.
ind2 (Individual) – The second individual in the role assertion, representing the target of the relationship.
role (str) – The name of the role through which the two individuals are related.
- __str__() → str
Returns a human-readable string representation of the query object, formatted as a question regarding the relationship between two individuals. The method constructs the string by interpolating the first individual, the second individual, and the relationship role into a template that asks if the first is related to the second through the specified role. The output string concludes with a prompt indicator (‘<= ‘) and relies on the standard string conversion of the object’s attributes, ensuring that the method does not modify the object’s state.
- Returns:
A string representation of the relationship query, formatted as a question asking if the first individual is related to the second through the specified role.
- Return type:
str
- preprocess(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) → None
Prepares the query for execution by translating a specific relationship constraint into a Mixed-Integer Linear Programming (MILP) formulation within the provided Knowledge Base. It constructs a HasValueConcept representing the restriction that an individual must have a specific value for a given role, retrieves the corresponding MILP variable, and asserts this relationship with a degree derived from that variable. As a side effect, this method increments the knowledge base’s counter for legacy variables, initializes the instance’s objective expression to optimize the relationship’s degree, and triggers the solving of all current assertions to update the system state.
- Parameters:
kb (KnowledgeBase) – The knowledge base context used to access the MILP model, add assertions, update variable counters, and trigger the solver.
- solve(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) → fuzzy_dl_owl2.fuzzydl.milp.solution.Solution
Executes the optimization query by first resolving the ABox of the provided Knowledge Base to ensure consistency. Upon successful resolution, the method clones the Knowledge Base to preserve the original state, applies necessary preprocessing, and runs an optimization routine using the defined objective expression. The process includes tracking the total execution time. If the Knowledge Base is determined to be inconsistent during the initial resolution step, the method intercepts the exception and returns a Solution object specifically marked as inconsistent.
- Parameters:
kb (KnowledgeBase) – The knowledge base containing the ontology and data to be solved and optimized.
- Returns:
The Solution object resulting from the optimization process, or a specific solution state indicating the knowledge base is inconsistent.
- Return type:
- role: str