fuzzy_dl_owl2.fuzzydl.query.defuzzify.defuzzify_query

An abstract base class that implements the logic for converting fuzzy membership degrees into crisp values for a specific individual and feature using Mixed-Integer Linear Programming.

Description

The software provides a framework for resolving fuzzy logic values into crisp numbers by leveraging Mixed-Integer Linear Programming (MILP) to optimize specific features within a knowledge base. During the execution process, the logic first determines the maximum degree of membership for a given individual and concept, asserts this value back into a cloned knowledge base, and then identifies the variable associated with the target feature. By separating the general optimization workflow from the specific mathematical strategy, the design allows subclasses to define custom objective expressions while the base class handles the complexities of ontology consistency, variable retrieval, and solution normalization. Error handling mechanisms ensure that inconsistent ontologies are detected and reported, while the solver manages negative results by returning absolute values to maintain mathematical validity.

Classes

DefuzzifyQuery

This abstract class defines the structure for performing defuzzification, which involves converting a fuzzy membership degree into a crisp value for a specific individual and feature within a knowledge base. During execution, it first determines the maximum degree of membership for the individual to the given concept and asserts this value into a cloned version of the knowledge base. It then identifies the variable associated with the specified feature and optimizes an objective expression derived from that variable to produce the final result. Subclasses are required to implement the abstract method for generating the objective expression, allowing for different defuzzification strategies to be applied. The process relies on Mixed-Integer Linear Programming (MILP) and handles potential inconsistencies in the ontology gracefully.

Module Contents

UML Class Diagram for DefuzzifyQuery

UML Class Diagram for DefuzzifyQuery

class DefuzzifyQuery(
c: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept,
ind: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual,
feature_name: str,
)

Bases: fuzzy_dl_owl2.fuzzydl.query.query.Query

This abstract class defines the structure for performing defuzzification, which involves converting a fuzzy membership degree into a crisp value for a specific individual and feature within a knowledge base. During execution, it first determines the maximum degree of membership for the individual to the given concept and asserts this value into a cloned version of the knowledge base. It then identifies the variable associated with the specified feature and optimizes an objective expression derived from that variable to produce the final result. Subclasses are required to implement the abstract method for generating the objective expression, allowing for different defuzzification strategies to be applied. The process relies on Mixed-Integer Linear Programming (MILP) and handles potential inconsistencies in the ontology gracefully.

Parameters:
  • conc (Concept) – The concept for which the defuzzification operation is performed.

  • a (Individual) – The individual entity for which the defuzzification query is being executed.

  • f_name (str) – The name of the feature for which to perform defuzzification.

  • obj_expr (Expression) – The objective expression used to optimize the solution, representing the degree of membership of the individual to the concept.

abstractmethod get_obj_expression(variable: fuzzy_dl_owl2.fuzzydl.milp.variable.Variable) fuzzy_dl_owl2.fuzzydl.milp.expression.Expression

Retrieves the objective expression associated with the specified variable for the defuzzification process. This abstract method requires subclasses to implement the logic for constructing the expression, which typically represents the target function or calculation needed to resolve the fuzzy variable into a crisp value. The implementation determines how the variable’s properties are translated into a formal expression used by the query engine.

Parameters:

variable (Variable) – The variable instance for which the corresponding object expression is to be retrieved.

Returns:

The expression representing the object associated with the provided variable.

Return type:

Expression

preprocess(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) None

Prepares the defuzzification query by solving a maximum satisfiability problem to determine the optimal degree for the conclusion associated with the current individual. If a consistent solution is found, the method updates the internal reference to the individual, asserts the calculated numeric degree back into the knowledge base, and resolves these assertions. Furthermore, it inspects the individual’s role relations to identify a specific target individual, retrieving the corresponding MILP variable to construct and store an objective expression for later use.

Parameters:

kb (KnowledgeBase) – The knowledge base instance used to solve queries, retrieve individuals, and manage assertions and MILP variables. This object is modified during the preprocessing step.

solve(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) fuzzy_dl_owl2.fuzzydl.milp.solution.Solution | None

Attempts to solve the defuzzification problem by first resolving the ABox of the provided Knowledge Base and then operating on a cloned instance to preserve the original state. The method applies preprocessing to the clone and, if an objective expression is defined, performs an optimization to find a solution. If the resulting solution value is negative, it is converted to its absolute value before being returned. If no objective expression is available, the method issues a warning and returns None. Furthermore, it handles inconsistent ontologies by catching the specific exception and returning a Solution object marked as inconsistent.

Parameters:

kb (KnowledgeBase) – The knowledge base containing the ontology and ABox to be solved and optimized.

Returns:

A Solution object representing the optimization result, or None if the objective expression is missing or a defuzzification problem occurs. Returns a specific Solution indicating inconsistency if the ontology is inconsistent.

Return type:

Optional[Solution]

a: fuzzy_dl_owl2.fuzzydl.individual.individual.Individual
conc: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept
f_name: str
obj_expr: fuzzy_dl_owl2.fuzzydl.milp.expression.Expression = None