fuzzy_dl_owl2.fuzzydl.query.all_instances_query

Retrieves all individuals from a knowledge base that satisfy a specified concept and calculates their corresponding fuzzy membership degrees.

Description

Software designed to retrieve all entities from a knowledge base that satisfy a specific conceptual definition, operating within a fuzzy logic framework where membership is represented by a degree rather than a binary value. It extends the base query functionality to handle complex retrieval tasks by accepting a target concept and evaluating every individual in the ontology to determine the extent to which they satisfy the criteria. The implementation ensures that the input concept is abstract rather than concrete, enforcing structural constraints on the query definition to maintain logical validity.

The core logic involves iterating through the individuals of the knowledge base and calculating the minimum degree of membership for each relative to the target concept. Two distinct solving strategies are provided: a standard approach that executes a minimum instance query for every individual sequentially, and an advanced optimization method that constructs a Mixed Integer Linear Programming (MILP) model to solve for all degrees simultaneously. The optimization approach introduces semi-continuous variables for each individual, links them to the concept via assertions, and maximizes the sum of these variables to determine the most accurate membership values.

Consistency checks are performed prior to calculation to ensure the ABox of the knowledge base is valid, returning a specific error state if the ontology is found to be inconsistent. Results are stored internally, mapping individuals to their calculated degrees, and can be accessed to view the fuzzy classification of the entire population. The design integrates tightly with the underlying MILP solver and knowledge base structure, allowing for efficient batch processing of instance retrieval queries.

Classes

AllInstancesQuery

This class represents a query designed to retrieve all individuals from a knowledge base that are instances of a specified concept, along with their respective degrees of membership. It supports fuzzy logic by determining the minimum degree to which each individual satisfies the concept, rather than relying on binary classification. To use this class, instantiate it with a target Concept object—ensuring the concept is not concrete—and invoke the solve method with a KnowledgeBase to perform the retrieval. The results can be accessed via the get_individuals and get_degrees methods, which return the list of matching entities and their calculated membership values.

Module Contents

UML Class Diagram for AllInstancesQuery

UML Class Diagram for AllInstancesQuery

class AllInstancesQuery(concept: fuzzy_dl_owl2.fuzzydl.concept.concept.Concept)[source]

Bases: fuzzy_dl_owl2.fuzzydl.query.query.Query

Inheritance diagram of fuzzy_dl_owl2.fuzzydl.query.all_instances_query.AllInstancesQuery

This class represents a query designed to retrieve all individuals from a knowledge base that are instances of a specified concept, along with their respective degrees of membership. It supports fuzzy logic by determining the minimum degree to which each individual satisfies the concept, rather than relying on binary classification. To use this class, instantiate it with a target Concept object—ensuring the concept is not concrete—and invoke the solve method with a KnowledgeBase to perform the retrieval. The results can be accessed via the get_individuals and get_degrees methods, which return the list of matching entities and their calculated membership values.

Parameters:
  • conc (Any) – The concept defining the criteria for retrieving instances and calculating membership degrees.

  • degrees (list[float]) – Stores the membership degrees corresponding to the retrieved individuals, indicating the extent to which each satisfies the concept.

  • individuals (list[Individual]) – The list of individuals from the knowledge base that are evaluated for membership in the concept.

  • name (Any) – A string representation of the query that stores the formatted results, including individuals and their degrees, or an error message upon execution.

__str__() str[source]

Returns the informal string representation of the query object, which is utilized by the built-in str() function and print() calls. This implementation simply delegates to the instance’s name attribute, ensuring that the object is represented by its identifying name in user-facing contexts. Since it relies on the name attribute, it assumes that the attribute is defined and holds a value suitable for string representation.

Returns:

The string representation of the object, which is its name.

Return type:

str

get_degrees() list[float][source]

Retrieves the collection of degree values stored within the query instance. This accessor returns the reference to the internal degrees attribute, which is a list of floating-point numbers. Note that because the list object is returned directly, modifications to the returned list will affect the internal state of the query object.

Returns:

A list of floating-point numbers representing the degree values.

Return type:

list[float]

get_individuals() list[fuzzy_dl_owl2.fuzzydl.individual.individual.Individual][source]

Retrieves the list of Individual objects stored in the individuals attribute of the query instance. This method serves as a direct accessor and does not modify the object’s state or perform any calculations. Because it returns a reference to the internal list, any in-place modifications made to the returned list will be reflected in the query object’s internal state.

Returns:

The list of individuals stored in the instance.

Return type:

list[Individual]

preprocess(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) None[source]

Prepares the query for execution by performing necessary setup operations using the provided KnowledgeBase. This method typically involves validating the query parameters, resolving internal references, or optimizing the retrieval strategy based on the schema or data available in the knowledge base. It modifies the internal state of the query object in place and does not return a value.

Parameters:

kb (KnowledgeBase) – The knowledge base object to be preprocessed or prepared for subsequent operations.

solve(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) fuzzy_dl_owl2.fuzzydl.milp.solution.Solution[source]

Executes the query to identify all individuals within the Knowledge Base that are instances of the specified concept. It begins by validating the consistency of the ABox, returning a specific solution if the ontology is found to be inconsistent. The method iterates through the individuals in the knowledge base, ignoring any that are dynamically created, and performs a minimum instance query for each to determine the degree of membership. As consistent results are found, they are appended to the internal list of degrees and formatted into the query’s name string. If an inconsistency arises during the iteration, the loop terminates immediately, and the inconsistent solution is returned.

Parameters:

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

Returns:

A Solution object representing the result of the operation. If the Knowledge Base is inconsistent, the solution indicates this error state; otherwise, it contains the result of the minimum instance query for the last individual processed.

Return type:

Solution

solve_new(kb: fuzzy_dl_owl2.fuzzydl.knowledge_base.KnowledgeBase) fuzzy_dl_owl2.fuzzydl.milp.solution.Solution[source]

Implements a specific algorithm to retrieve instances of the target concept by calculating the degree of membership for each individual in the provided knowledge base. The method operates on a clone of the input knowledge base to preserve the original state, first checking for consistency; if the ABox is inconsistent, it returns a solution indicating an inconsistent knowledge base. For each individual, excluding those that are dynamically created, it introduces a new semi-continuous variable into the MILP model and adds assertions that link the individual’s relationship to the concept with this variable. It then constructs an objective function to maximize the sum of these variables and performs an optimization. As a side effect of this process, the method updates the instance’s internal state by populating self.degrees with the calculated membership values and self.name with a descriptive string of the results, while temporarily toggling MILP helper flags for the optimization step.

Parameters:

kb (KnowledgeBase) – The knowledge base containing the ontology and individuals to be analyzed. It is cloned internally to ensure the original object remains unmodified during the solving process.

Returns:

A Solution object containing the optimization results, including the degrees of membership for individuals regarding the target concept, or indicating an inconsistent knowledge base.

Return type:

Solution

conc
degrees: list[float] = []
individuals: list[fuzzy_dl_owl2.fuzzydl.individual.individual.Individual] = []
name