owlapy.utils
Owlapy utils.
Attributes
Classes
Length calculation of OWLClassExpression |
|
Abstract base class for generic types. |
|
Interface for types with an index; this is used to group objects by type when sorting. |
|
Holder of OWL Objects that can be used for Python sorted. |
|
This class contains functions to transform a Class Expression into Negation Normal Form. |
|
This class contains functions to transform a class expression into Top-Level Conjunctive Normal Form. |
|
This class contains functions to transform a class expression into Top-Level Disjunctive Normal Form. |
|
Constants shares by all lru cache instances. |
Functions
|
|
|
Reduces a set of concepts by applying a binary operation to each pair of concepts. |
Map a set of owl concepts and a set of properties into OWL Restrictions |
|
|
|
Shortens an OWLClassExpression or OWLDataRange by combining all nested nary expressions of the same type. |
|
|
Count the number of elements in an iterable. |
|
Cast OWL Object to HasIndex. |
Module Contents
- owlapy.utils.concept_reducer(concepts: Iterable, opt: Callable)[source]
Reduces a set of concepts by applying a binary operation to each pair of concepts.
- Parameters:
concepts (set) – A set of concepts to be reduced.
opt (function) – A binary function that takes a pair of concepts and returns a single concept.
- Returns:
A set containing the results of applying the binary operation to each pair of concepts.
- Return type:
set
Example
>>> concepts = {1, 2, 3} >>> opt = lambda x: x[0] + x[1] >>> concept_reducer(concepts, opt) {2, 3, 4, 5, 6}
Note
The operation opt should be commutative and associative to ensure meaningful reduction in the context of set operations.
- owlapy.utils.concept_reducer_properties(concepts: Iterable, properties, cls: Callable = None, cardinality: int = 2) Iterable[owlapy.class_expression.OWLQuantifiedObjectRestriction | owlapy.class_expression.OWLObjectCardinalityRestriction] [source]
Map a set of owl concepts and a set of properties into OWL Restrictions
- Parameters:
concepts
properties
cls (Callable) – An owl Restriction class
cardinality – A positive Integer
Returns: List of OWL Restrictions
- class owlapy.utils.OWLClassExpressionLengthMetric(*, class_length: int, object_intersection_length: int, object_union_length: int, object_complement_length: int, object_some_values_length: int, object_all_values_length: int, object_has_value_length: int, object_cardinality_length: int, object_has_self_length: int, object_one_of_length: int, data_some_values_length: int, data_all_values_length: int, data_has_value_length: int, data_cardinality_length: int, object_property_length: int, object_inverse_length: int, data_property_length: int, datatype_length: int, data_one_of_length: int, data_complement_length: int, data_intersection_length: int, data_union_length: int)[source]
Length calculation of OWLClassExpression
- Parameters:
class_length – Class: “C”
object_intersection_length – Intersection: A ⨅ B
object_union_length – Union: A ⨆ B
object_complement_length – Complement: ¬ C
object_some_values_length – Obj. Some Values: ∃ r.C
object_all_values_length – Obj. All Values: ∀ r.C
object_has_value_length – Obj. Has Value: ∃ r.{I}
object_cardinality_length – Obj. Cardinality restriction: ≤n r.C
object_has_self_length – Obj. Self restriction: ∃ r.Self
object_one_of_length – Obj. One of: ∃ r.{X,Y,Z}
data_some_values_length – Data Some Values: ∃ p.t
data_all_values_length – Data All Values: ∀ p.t
data_has_value_length – Data Has Value: ∃ p.{V}
data_cardinality_length – Data Cardinality restriction: ≤n r.t
object_property_length – Obj. Property: ∃ r.C
object_inverse_length – Inverse property: ∃ r⁻.C
data_property_length – Data Property: ∃ p.t
datatype_length – Datatype: ^^datatype
data_one_of_length – Data One of: ∃ p.{U,V,W}
data_complement_length – Data Complement: ¬datatype
data_intersection_length – Data Intersection: datatype ⨅ datatype
data_union_length – Data Union: datatype ⨆ datatype
- __slots__ = ('class_length', 'object_intersection_length', 'object_union_length',...
- class_length: int
- object_intersection_length: int
- object_union_length: int
- object_complement_length: int
- object_some_values_length: int
- object_all_values_length: int
- object_has_value_length: int
- object_cardinality_length: int
- object_has_self_length: int
- object_one_of_length: int
- data_some_values_length: int
- data_all_values_length: int
- data_has_value_length: int
- data_cardinality_length: int
- object_property_length: int
- object_inverse_length: int
- data_property_length: int
- datatype_length: int
- data_one_of_length: int
- data_complement_length: int
- data_intersection_length: int
- data_union_length: int
- static get_default() OWLClassExpressionLengthMetric [source]
- abstract length(o: owlapy.owl_object.OWLObject) int [source]
- owlapy.utils.measurer
- owlapy.utils.get_expression_length(ce: owlapy.class_expression.OWLClassExpression) int [source]
- class owlapy.utils.EvaluatedDescriptionSet(ordering: Callable[[_N], _O], max_size: int = 10)[source]
Bases:
Generic
[_N
,_O
]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
- __slots__ = ('items', '_max_size', '_Ordering')
- items: SortedSet[_N]
- class owlapy.utils.HasIndex[source]
Bases:
Protocol
Interface for types with an index; this is used to group objects by type when sorting.
- type_index: ClassVar[int]
- class owlapy.utils.OrderedOWLObject(o: _HasIndex)[source]
Holder of OWL Objects that can be used for Python sorted.
The Ordering is dependent on the type_index of the impl. classes recursively followed by all components of the OWL Object.
- o
OWL object.
- __slots__ = ('o', '_chain')
- o: _HasIndex
- class owlapy.utils.NNF[source]
This class contains functions to transform a Class Expression into Negation Normal Form.
- abstract get_class_nnf(ce: owlapy.class_expression.OWLClassExpression, negated: bool = False) owlapy.class_expression.OWLClassExpression [source]
Convert a Class Expression to Negation Normal Form. Operands will be sorted.
- Parameters:
ce – Class Expression.
negated – Whether the result should be negated.
- Returns:
Class Expression in Negation Normal Form.
- class owlapy.utils.TopLevelCNF[source]
This class contains functions to transform a class expression into Top-Level Conjunctive Normal Form.
- get_top_level_cnf(ce: owlapy.class_expression.OWLClassExpression) owlapy.class_expression.OWLClassExpression [source]
Convert a class expression into Top-Level Conjunctive Normal Form. Operands will be sorted.
- Parameters:
ce – Class Expression.
- Returns:
Class Expression in Top-Level Conjunctive Normal Form.
- class owlapy.utils.TopLevelDNF[source]
This class contains functions to transform a class expression into Top-Level Disjunctive Normal Form.
- get_top_level_dnf(ce: owlapy.class_expression.OWLClassExpression) owlapy.class_expression.OWLClassExpression [source]
Convert a class expression into Top-Level Disjunctive Normal Form. Operands will be sorted.
- Parameters:
ce – Class Expression.
- Returns:
Class Expression in Top-Level Disjunctive Normal Form.
- owlapy.utils.combine_nary_expressions(ce: owlapy.class_expression.OWLClassExpression) owlapy.class_expression.OWLClassExpression [source]
- owlapy.utils.combine_nary_expressions(ce: owlapy.owl_data_ranges.OWLDataRange) owlapy.owl_data_ranges.OWLDataRange
Shortens an OWLClassExpression or OWLDataRange by combining all nested nary expressions of the same type. Operands will be sorted.
E.g. OWLObjectUnionOf(A, OWLObjectUnionOf(C, B)) -> OWLObjectUnionOf(A, B, C).
- owlapy.utils.as_index(o: owlapy.owl_object.OWLObject) HasIndex [source]
Cast OWL Object to HasIndex.
- class owlapy.utils.LRUCache(maxsize: int | None = None)[source]
Bases:
Generic
[_K
,_V
]Constants shares by all lru cache instances.
Adapted from functools.lru_cache.
- sentinel
Unique object used to signal cache misses.
- PREV
Name for the link field 0.
- NEXT
Name for the link field 1.
- KEY
Name for the link field 2.
- RESULT
Name for the link field 3.
- sentinel
- cache
- full = False
- cache_get
- cache_len
- lock
- root = []
- maxsize = None