fuzzy_dl_owl2.fuzzyowl2.util.fuzzy_xml

A utility builder for generating XML elements that conform to the FuzzyOWL2 ontology specification.

Description

The software abstracts the low-level details of XML manipulation by providing a suite of static factory methods that create specific nodes required for fuzzy ontology definitions. By leveraging a centralized set of constants for tag names and attributes, the implementation ensures that generated XML structures strictly adhere to the FuzzyOWL2 standard while allowing for optional custom attributes. It handles the construction of various components, ranging from root ontology elements and logic definitions to complex structures like weights and concept names, effectively acting as a domain-specific language for XML generation. Additionally, a serialization helper transforms the constructed element trees into formatted, human-readable strings, facilitating debugging and output generation without requiring external formatting libraries.

Classes

FuzzyXML

This utility class acts as a builder for XML elements conforming to the FuzzyOWL2 ontology specification. It provides a suite of static methods for constructing specific XML nodes, including definitions for fuzzy logics, datatypes, modifiers, truth degrees, concepts, weights, and concept names. By abstracting the underlying tag names and attribute structures, it facilitates the programmatic generation of complex fuzzy ontology documents. The class also includes a serialization helper to convert constructed XML elements into formatted, human-readable strings for debugging or output purposes.

Module Contents

UML Class Diagram for FuzzyXML

UML Class Diagram for FuzzyXML

class FuzzyXML[source]

Bases: object

This utility class acts as a builder for XML elements conforming to the FuzzyOWL2 ontology specification. It provides a suite of static methods for constructing specific XML nodes, including definitions for fuzzy logics, datatypes, modifiers, truth degrees, concepts, weights, and concept names. By abstracting the underlying tag names and attribute structures, it facilitates the programmatic generation of complex fuzzy ontology documents. The class also includes a serialization helper to convert constructed XML elements into formatted, human-readable strings for debugging or output purposes.

static build_concept_xml(concept_type: str, attrib: dict[str, str] = dict()) xml.etree.ElementTree.Element[source]

Creates an XML element representing a concept definition, specifically designed for use within Fuzzy OWL 2 structures. The generated element is tagged according to the concept keyword and automatically includes a ‘type’ attribute derived from the input string. While the method accepts an optional dictionary of additional attributes to append to the element, any keys in this dictionary that conflict with the default ‘type’ attribute will override the initial value, allowing for manual control over the final attribute set.

Parameters:
  • concept_type (str) – The classification of the concept (e.g., “fuzzy” or “crisp”), which is assigned to the element’s type attribute.

  • attrib (dict[str, str]) – Optional dictionary of additional XML attributes to include in the concept element.

Returns:

An XML Element representing a concept definition, including the specified type and any additional attributes.

Return type:

Element

static build_datatype_xml(datatype_type: str, attrib: dict[str, str] = dict()) xml.etree.ElementTree.Element[source]

This static method constructs an XML element representing a datatype definition, formatted according to the specific ontology keywords used by the class. It initializes the element with a tag corresponding to a datatype and sets the primary type attribute using the provided datatype_type string. Any additional attributes supplied in the optional dictionary are merged into the element’s properties, with user-provided values taking precedence in case of key conflicts, before returning the fully configured Element object.

Parameters:
  • datatype_type (str) – The specific data type identifier (e.g., “integer”, “float”) to be assigned to the type attribute of the XML element.

  • attrib (dict[str, str]) – Additional XML attributes to include in the element, merged with the standard type attribute.

Returns:

An XML element representing a datatype definition, configured with the provided type and optional attributes.

Return type:

Element

static build_degree_xml(value: int | float, attrib: dict[str, str] = dict()) xml.etree.ElementTree.Element[source]

Constructs an XML element representing a degree definition, typically used for defining membership degrees or truth values in Fuzzy OWL 2 ontologies. The method accepts a numeric value, which is converted to a string and assigned to a specific attribute key determined by the FuzzyOWL2Keyword standard. It also allows for an optional dictionary of additional attributes to be merged into the element; if the provided dictionary contains a key identical to the degree value attribute, the user-provided value will override the automatically generated one. The function returns a new XML Element object without modifying the input arguments.

Parameters:
  • value (Union[int, float])

  • attrib (dict[str, str]) – Optional dictionary of additional XML attributes to merge into the degree definition element.

Returns:

An XML element representing a degree definition, containing the provided value as an attribute along with any additional specified attributes.

Return type:

Element

static build_logic_xml(logic: str, attrib: dict[str, str] = dict()) xml.etree.ElementTree.Element[source]

Constructs an XML element representing a specific fuzzy logic definition, typically used within Fuzzy OWL 2 ontology structures. The method assigns the provided logic type string, such as ‘Lukasiewicz’ or ‘Zadeh’, to the standard logic attribute key defined by the underlying ontology keywords. If an optional dictionary of additional attributes is supplied, its contents are merged into the element’s attributes, allowing for custom metadata or potentially overriding the default logic attribute if a conflicting key is provided. The function returns the newly created Element object and does not perform any I/O operations or modify global state.

Parameters:
  • logic (str) – The specific fuzzy logic type to define, such as “Lukasiewicz” or “Zadeh”.

  • attrib (dict[str, str]) – Optional mapping of additional XML attributes to include in the generated element.

Returns:

An XML element representing the fuzzy logic definition, configured with the specified logic type and any additional attributes.

Return type:

Element

static build_main_xml(fuzzy_type: str) xml.etree.ElementTree.Element[source]

Constructs the root XML element for a FuzzyOWL2 ontology document, serving as the entry point for building the ontology structure. This static method creates an Element with a tag name corresponding to the FuzzyOWL2 standard and assigns the provided fuzzy_type string (e.g., “fuzzyDL” or “fuzzyOWL2”) to a specific attribute to denote the dialect. The function acts as a pure factory method with no side effects, returning a new XML node without validating the content of the input string.

Parameters:

fuzzy_type (str) – The specific dialect or variant of the fuzzy ontology (e.g., “fuzzyDL”, “fuzzyOWL2”).

Returns:

The root XML element for the FuzzyOWL2 ontology, initialized with the specified fuzzy type attribute.

Return type:

Element

static build_modifier_xml(modifier_type: str, attrib: dict[str, str] = dict()) xml.etree.ElementTree.Element[source]

Constructs an XML element representing a modifier definition, tagged according to the FuzzyOWL2 vocabulary. The method automatically assigns the mandatory ‘type’ attribute using the provided modifier_type argument, ensuring the element identifies the specific kind of modifier. Any additional attributes supplied via the attrib dictionary are merged into the element’s properties, potentially overwriting default values if keys conflict, to allow for extended configuration.

Parameters:
  • modifier_type (str) – The specific classification of the modifier (e.g., “linear”, “triangular”).

  • attrib (dict[str, str]) – Optional dictionary of additional XML attributes to include in the modifier element.

Returns:

An XML Element representing the modifier definition, containing the specified type and any additional attributes.

Return type:

Element

static build_names_xml(concepts: list[pyowl2.abstracts.class_expression.OWLClassExpression]) xml.etree.ElementTree.Element[source]

Constructs an XML hierarchy representing a collection of concept names derived from a list of OWL class expressions. The method initializes a parent element corresponding to concept names and iterates over the provided list to generate individual child elements for each concept. Each child element’s text content is populated by converting the corresponding class expression to its string representation. If the input list is empty, the method returns an empty parent element. This operation does not modify the input list or the class expressions themselves.

Parameters:

concepts (list[OWLClassExpression]) – The OWL class expressions to be serialized as XML name elements.

Returns:

An XML element representing the concept names container, with child elements corresponding to each concept in the input list.

Return type:

Element

static build_weights_xml(weights: list[float]) xml.etree.ElementTree.Element[source]

Constructs an XML hierarchy representing a sequence of weights for use in fuzzy logic definitions. The method instantiates a root element to encapsulate the collection and iterates over the provided list of floating-point values, creating a distinct child element for each. Every weight is converted to a string and embedded within its corresponding tag. If the input list is empty, the method returns a root element with no children. This function does not modify the input list and relies on FuzzyOWL2Keyword to determine the appropriate tag names for the generated elements.

Parameters:

weights (list[float]) – A sequence of numerical values to be serialized as individual weight elements within the XML structure.

Returns:

The root XML element representing the weights definition, containing child elements for each provided float value.

Return type:

Element

static to_str(element: xml.etree.ElementTree.Element) str[source]

Converts the provided XML element into a formatted, human-readable string representation. This static method serializes the element using standard XML methods and applies indentation via minidom to produce a clean structure. The resulting Unicode string excludes the XML declaration header and has any consecutive newline characters collapsed into a single line break to ensure compact formatting. This process does not modify the original element.

Parameters:

element (Element) – The XML element to be converted to a string.

Returns:

A pretty-printed string representation of the XML element, excluding the XML declaration header.

Return type:

str