fuzzy-dl-owl2 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fuzzy_dl_owl2/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/__init__.py +23 -0
- fuzzy_dl_owl2/fuzzydl/assertion/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/assertion/assertion.py +72 -0
- fuzzy_dl_owl2/fuzzydl/assertion/atomic_assertion.py +19 -0
- fuzzy_dl_owl2/fuzzydl/concept/__init__.py +13 -0
- fuzzy_dl_owl2/fuzzydl/concept/all_some_concept.py +85 -0
- fuzzy_dl_owl2/fuzzydl/concept/approximation_concept.py +147 -0
- fuzzy_dl_owl2/fuzzydl/concept/atomic_concept.py +91 -0
- fuzzy_dl_owl2/fuzzydl/concept/choquet_integral.py +64 -0
- fuzzy_dl_owl2/fuzzydl/concept/concept.py +230 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/__init__.py +10 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/crisp_concrete_concept.py +60 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_concrete_concept.py +63 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_number/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_number/triangular_fuzzy_number.py +127 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/left_concrete_concept.py +70 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/linear_concrete_concept.py +70 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/modified_concrete_concept.py +66 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/right_concrete_concept.py +70 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/trapezoidal_concrete_concept.py +96 -0
- fuzzy_dl_owl2/fuzzydl/concept/concrete/triangular_concrete_concept.py +89 -0
- fuzzy_dl_owl2/fuzzydl/concept/ext_threshold_concept.py +77 -0
- fuzzy_dl_owl2/fuzzydl/concept/has_value_concept.py +51 -0
- fuzzy_dl_owl2/fuzzydl/concept/implies_concept.py +144 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/__init__.py +6 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_concept_interface.py +17 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_concepts_interface.py +18 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_role_concept_interface.py +14 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_role_interface.py +15 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_value_interface.py +21 -0
- fuzzy_dl_owl2/fuzzydl/concept/interface/has_weighted_concepts_interface.py +29 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/linearly_modified_concept.py +32 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/modified_concept.py +59 -0
- fuzzy_dl_owl2/fuzzydl/concept/modified/triangularly_modified_concept.py +33 -0
- fuzzy_dl_owl2/fuzzydl/concept/negated_nominal.py +42 -0
- fuzzy_dl_owl2/fuzzydl/concept/operator_concept.py +707 -0
- fuzzy_dl_owl2/fuzzydl/concept/owa_concept.py +57 -0
- fuzzy_dl_owl2/fuzzydl/concept/qowa_concept.py +62 -0
- fuzzy_dl_owl2/fuzzydl/concept/quasi_sugeno_integral.py +46 -0
- fuzzy_dl_owl2/fuzzydl/concept/self_concept.py +45 -0
- fuzzy_dl_owl2/fuzzydl/concept/string_concept.py +35 -0
- fuzzy_dl_owl2/fuzzydl/concept/sugeno_integral.py +83 -0
- fuzzy_dl_owl2/fuzzydl/concept/threshold_concept.py +81 -0
- fuzzy_dl_owl2/fuzzydl/concept/truth_concept.py +83 -0
- fuzzy_dl_owl2/fuzzydl/concept/value_concept.py +67 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_concept.py +55 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_max_concept.py +63 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_min_concept.py +57 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_sum_concept.py +62 -0
- fuzzy_dl_owl2/fuzzydl/concept/weighted_sum_zero_concept.py +62 -0
- fuzzy_dl_owl2/fuzzydl/concept_equivalence.py +20 -0
- fuzzy_dl_owl2/fuzzydl/concrete_feature.py +94 -0
- fuzzy_dl_owl2/fuzzydl/degree/__init__.py +4 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree.py +79 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree_expression.py +57 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree_numeric.py +57 -0
- fuzzy_dl_owl2/fuzzydl/degree/degree_variable.py +54 -0
- fuzzy_dl_owl2/fuzzydl/domain_axiom.py +8 -0
- fuzzy_dl_owl2/fuzzydl/exception/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/exception/fuzzy_ontology_exception.py +4 -0
- fuzzy_dl_owl2/fuzzydl/exception/inconsistent_ontology_exception.py +4 -0
- fuzzy_dl_owl2/fuzzydl/feature_function.py +148 -0
- fuzzy_dl_owl2/fuzzydl/fuzzydl_to_owl2.py +920 -0
- fuzzy_dl_owl2/fuzzydl/fuzzydl_to_owl2_java.py +953 -0
- fuzzy_dl_owl2/fuzzydl/general_concept_inclusion.py +82 -0
- fuzzy_dl_owl2/fuzzydl/individual/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/individual/created_individual.py +219 -0
- fuzzy_dl_owl2/fuzzydl/individual/individual.py +113 -0
- fuzzy_dl_owl2/fuzzydl/individual/representative_individual.py +37 -0
- fuzzy_dl_owl2/fuzzydl/knowledge_base.py +9037 -0
- fuzzy_dl_owl2/fuzzydl/label.py +32 -0
- fuzzy_dl_owl2/fuzzydl/milp/__init__.py +7 -0
- fuzzy_dl_owl2/fuzzydl/milp/expression.py +186 -0
- fuzzy_dl_owl2/fuzzydl/milp/inequation.py +55 -0
- fuzzy_dl_owl2/fuzzydl/milp/milp_helper.py +787 -0
- fuzzy_dl_owl2/fuzzydl/milp/show_variables_helper.py +151 -0
- fuzzy_dl_owl2/fuzzydl/milp/solution.py +45 -0
- fuzzy_dl_owl2/fuzzydl/milp/term.py +76 -0
- fuzzy_dl_owl2/fuzzydl/milp/variable.py +89 -0
- fuzzy_dl_owl2/fuzzydl/modifier/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/modifier/linear_modifier.py +76 -0
- fuzzy_dl_owl2/fuzzydl/modifier/modifier.py +39 -0
- fuzzy_dl_owl2/fuzzydl/modifier/triangular_modifier.py +76 -0
- fuzzy_dl_owl2/fuzzydl/parser/ParserConstants.py +406 -0
- fuzzy_dl_owl2/fuzzydl/parser/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzydl/parser/dl_parser.py +2029 -0
- fuzzy_dl_owl2/fuzzydl/parser/ebnf.lark +290 -0
- fuzzy_dl_owl2/fuzzydl/parser/larkx.py +70 -0
- fuzzy_dl_owl2/fuzzydl/primitive_concept_definition.py +81 -0
- fuzzy_dl_owl2/fuzzydl/query/__init__.py +14 -0
- fuzzy_dl_owl2/fuzzydl/query/all_instances_query.py +50 -0
- fuzzy_dl_owl2/fuzzydl/query/bnp_query.py +22 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/__init__.py +4 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/defuzzify_query.py +76 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/lom_defuzzify_query.py +19 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/mom_defuzzify_query.py +88 -0
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/som_defuzzify_query.py +20 -0
- fuzzy_dl_owl2/fuzzydl/query/instance_query.py +19 -0
- fuzzy_dl_owl2/fuzzydl/query/kb_satisfiable_query.py +32 -0
- fuzzy_dl_owl2/fuzzydl/query/max/__init__.py +5 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_instance_query.py +45 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_query.py +31 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_related_query.py +45 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_satisfiable_query.py +73 -0
- fuzzy_dl_owl2/fuzzydl/query/max/max_subsumes_query.py +64 -0
- fuzzy_dl_owl2/fuzzydl/query/min/__init__.py +5 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_instance_query.py +50 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_query.py +31 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_related_query.py +57 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_satisfiable_query.py +80 -0
- fuzzy_dl_owl2/fuzzydl/query/min/min_subsumes_query.py +65 -0
- fuzzy_dl_owl2/fuzzydl/query/query.py +38 -0
- fuzzy_dl_owl2/fuzzydl/query/related_query.py +15 -0
- fuzzy_dl_owl2/fuzzydl/query/satisfiable_query.py +37 -0
- fuzzy_dl_owl2/fuzzydl/query/subsumption_query.py +20 -0
- fuzzy_dl_owl2/fuzzydl/range_axiom.py +7 -0
- fuzzy_dl_owl2/fuzzydl/relation.py +47 -0
- fuzzy_dl_owl2/fuzzydl/restriction/__init__.py +2 -0
- fuzzy_dl_owl2/fuzzydl/restriction/has_value_restriction.py +16 -0
- fuzzy_dl_owl2/fuzzydl/restriction/restriction.py +34 -0
- fuzzy_dl_owl2/fuzzydl/role_parent_with_degree.py +10 -0
- fuzzy_dl_owl2/fuzzydl/util/__init__.py +3 -0
- fuzzy_dl_owl2/fuzzydl/util/config_reader.py +56 -0
- fuzzy_dl_owl2/fuzzydl/util/constants.py +424 -0
- fuzzy_dl_owl2/fuzzydl/util/util.py +73 -0
- fuzzy_dl_owl2/fuzzyowl2/__init__.py +5 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2.py +1513 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_java.py +1409 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_to_fuzzydl.py +917 -0
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2_to_fuzzydl_java.py +956 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/__init__.py +0 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/choquet_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/concept_definition.py +14 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_datatype.py +22 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_modifier.py +4 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_nominal_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/fuzzy_property.py +5 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/left_shoulder_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/linear_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/linear_modifier.py +13 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/modified_property.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/owa_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/property_definition.py +10 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/qowa_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/quasi_sugeno_concept.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/right_shoulder_function.py +17 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/sugeno_concept.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/trapezoidal_function.py +25 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/triangular_function.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/triangular_modifer.py +21 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_concept.py +19 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_max_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_min_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_sum_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/owl_types/weighted_sum_zero_concept.py +15 -0
- fuzzy_dl_owl2/fuzzyowl2/parser/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzyowl2/parser/owl2_parser.py +491 -0
- fuzzy_dl_owl2/fuzzyowl2/util/__init__.py +1 -0
- fuzzy_dl_owl2/fuzzyowl2/util/constants.py +112 -0
- fuzzy_dl_owl2-1.0.0.dist-info/LICENSE +427 -0
- fuzzy_dl_owl2-1.0.0.dist-info/METADATA +299 -0
- fuzzy_dl_owl2-1.0.0.dist-info/RECORD +167 -0
- fuzzy_dl_owl2-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_weighted_concepts_interface import (
|
|
7
|
+
HasWeightedConceptsInterface,
|
|
8
|
+
)
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OwaConcept(Concept, HasWeightedConceptsInterface):
|
|
15
|
+
def __init__(self, weights: list[float], concepts: list[Concept]) -> None:
|
|
16
|
+
Concept.__init__(self, ConceptType.OWA)
|
|
17
|
+
HasWeightedConceptsInterface.__init__(self, weights, concepts)
|
|
18
|
+
|
|
19
|
+
if weights is not None:
|
|
20
|
+
if len(weights) != len(concepts):
|
|
21
|
+
Util.error(
|
|
22
|
+
"Error: The number of weights and the number of concepts should be the same"
|
|
23
|
+
)
|
|
24
|
+
self.name = self.compute_name()
|
|
25
|
+
|
|
26
|
+
def clone(self) -> typing.Self:
|
|
27
|
+
return OwaConcept(self.weights[:], [c for c in self.concepts])
|
|
28
|
+
|
|
29
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
30
|
+
concept_list: set[Concept] = set()
|
|
31
|
+
for c in self.concepts:
|
|
32
|
+
concept_list.update(c.compute_atomic_concepts())
|
|
33
|
+
return concept_list
|
|
34
|
+
|
|
35
|
+
def get_roles(self) -> set[str]:
|
|
36
|
+
role_list: set[str] = set()
|
|
37
|
+
for c in self.concepts:
|
|
38
|
+
role_list.update(c.get_roles())
|
|
39
|
+
return role_list
|
|
40
|
+
|
|
41
|
+
def replace(self, a: Concept, c: Concept) -> typing.Optional[Concept]:
|
|
42
|
+
return -OwaConcept(self.weights, [ci.replace(a, c) for ci in self.concepts])
|
|
43
|
+
|
|
44
|
+
def compute_name(self) -> str:
|
|
45
|
+
return f"(owa ({' '.join(map(str, self.weights))}) ({' '.join(map(str, self.concepts))}))"
|
|
46
|
+
|
|
47
|
+
def __neg__(self) -> Concept:
|
|
48
|
+
return OperatorConcept.not_(self)
|
|
49
|
+
|
|
50
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
51
|
+
return OperatorConcept.and_(self, value)
|
|
52
|
+
|
|
53
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
54
|
+
return OperatorConcept.or_(self, value)
|
|
55
|
+
|
|
56
|
+
def __hash__(self) -> int:
|
|
57
|
+
return hash(str(self))
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concrete.fuzzy_concrete_concept import (
|
|
5
|
+
FuzzyConcreteConcept,
|
|
6
|
+
)
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.concept.owa_concept import OwaConcept
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class QowaConcept(OwaConcept):
|
|
13
|
+
def __init__(
|
|
14
|
+
self, quantifier: FuzzyConcreteConcept, concepts: list[Concept]
|
|
15
|
+
) -> None:
|
|
16
|
+
super().__init__(None, concepts)
|
|
17
|
+
|
|
18
|
+
self.type = ConceptType.QUANTIFIED_OWA
|
|
19
|
+
self._quantifier: FuzzyConcreteConcept = quantifier
|
|
20
|
+
self.compute_weights(len(concepts))
|
|
21
|
+
self.name = self.compute_name()
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def quantifier(self) -> FuzzyConcreteConcept:
|
|
25
|
+
return self._quantifier
|
|
26
|
+
|
|
27
|
+
@quantifier.setter
|
|
28
|
+
def quantifier(self, value: FuzzyConcreteConcept) -> None:
|
|
29
|
+
self._quantifier = value
|
|
30
|
+
self.name = self.compute_name()
|
|
31
|
+
|
|
32
|
+
def clone(self) -> typing.Self:
|
|
33
|
+
return QowaConcept(self.quantifier, [c for c in self.concepts])
|
|
34
|
+
|
|
35
|
+
def compute_weights(self, n: int) -> None:
|
|
36
|
+
if n <= 0:
|
|
37
|
+
return
|
|
38
|
+
if self.weights is None:
|
|
39
|
+
self.weights = []
|
|
40
|
+
previous: float = 0.0
|
|
41
|
+
for i in range(1, n + 1):
|
|
42
|
+
w: float = i / n
|
|
43
|
+
self.weights.append(self.quantifier.get_membership_degree(w - previous))
|
|
44
|
+
previous: float = w
|
|
45
|
+
|
|
46
|
+
def replace(self, a: Concept, c: Concept) -> typing.Optional[Concept]:
|
|
47
|
+
return -OwaConcept(self.quantifier, [ci.replace(a, c) for ci in self.concepts])
|
|
48
|
+
|
|
49
|
+
def compute_name(self) -> str:
|
|
50
|
+
return f"(q-owa {self.quantifier} {' '.join(map(str, self.concepts))})"
|
|
51
|
+
|
|
52
|
+
def __neg__(self) -> Concept:
|
|
53
|
+
return OperatorConcept.not_(OwaConcept(self.weights, self.concepts))
|
|
54
|
+
|
|
55
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
56
|
+
return OperatorConcept.and_(self, value)
|
|
57
|
+
|
|
58
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
59
|
+
return OperatorConcept.or_(self, value)
|
|
60
|
+
|
|
61
|
+
def __hash__(self) -> int:
|
|
62
|
+
return hash(str(self))
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.sugeno_integral import SugenoIntegral
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class QsugenoIntegral(SugenoIntegral):
|
|
13
|
+
|
|
14
|
+
def __init__(self, weights: list[float], concepts: list[Concept]) -> None:
|
|
15
|
+
super().__init__(weights, concepts)
|
|
16
|
+
self.type = ConceptType.QUASI_SUGENO_INTEGRAL
|
|
17
|
+
|
|
18
|
+
if weights is not None:
|
|
19
|
+
if len(weights) != len(concepts):
|
|
20
|
+
Util.error(
|
|
21
|
+
"Error: The number of weights and the number of concepts should be the same"
|
|
22
|
+
)
|
|
23
|
+
self.name = self.compute_name()
|
|
24
|
+
|
|
25
|
+
def clone(self) -> typing.Self:
|
|
26
|
+
return QsugenoIntegral(self.weights[:], [c for c in self.concepts])
|
|
27
|
+
|
|
28
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
29
|
+
return -QsugenoIntegral(
|
|
30
|
+
self.weights, [ci.replace(a, c) for ci in self.concepts]
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def compute_name(self) -> str:
|
|
34
|
+
return f"(qsugeno ({' '.join(map(str, self.weights))}) ({' '.join(map(str, self.concepts))}))"
|
|
35
|
+
|
|
36
|
+
def __neg__(self) -> Concept:
|
|
37
|
+
return OperatorConcept.not_(self)
|
|
38
|
+
|
|
39
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
40
|
+
return OperatorConcept.and_(self, value)
|
|
41
|
+
|
|
42
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
43
|
+
return OperatorConcept.or_(self, value)
|
|
44
|
+
|
|
45
|
+
def __hash__(self) -> int:
|
|
46
|
+
return hash(str(self))
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_role_interface import HasRoleInterface
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SelfConcept(Concept, HasRoleInterface):
|
|
10
|
+
|
|
11
|
+
def __init__(self, role: str) -> None:
|
|
12
|
+
Concept.__init__(self, ConceptType.SELF)
|
|
13
|
+
HasRoleInterface.__init__(self, role)
|
|
14
|
+
self.name = self.compute_name()
|
|
15
|
+
|
|
16
|
+
@staticmethod
|
|
17
|
+
def self(role: str) -> typing.Self:
|
|
18
|
+
return SelfConcept(role)
|
|
19
|
+
|
|
20
|
+
def clone(self):
|
|
21
|
+
return SelfConcept(self.role)
|
|
22
|
+
|
|
23
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
24
|
+
return self
|
|
25
|
+
|
|
26
|
+
def compute_name(self) -> typing.Optional[str]:
|
|
27
|
+
return f"(self {self.role})"
|
|
28
|
+
|
|
29
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
30
|
+
return set([self])
|
|
31
|
+
|
|
32
|
+
def get_roles(self) -> set[str]:
|
|
33
|
+
return set([self.role])
|
|
34
|
+
|
|
35
|
+
def __neg__(self) -> Concept:
|
|
36
|
+
return OperatorConcept.not_(self)
|
|
37
|
+
|
|
38
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
39
|
+
return OperatorConcept.and_(self, value)
|
|
40
|
+
|
|
41
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
42
|
+
return OperatorConcept.or_(self, value)
|
|
43
|
+
|
|
44
|
+
def __hash__(self) -> int:
|
|
45
|
+
return hash(str(self))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.exception.fuzzy_ontology_exception import (
|
|
5
|
+
FuzzyOntologyException,
|
|
6
|
+
)
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class StringConcept(Concept):
|
|
11
|
+
|
|
12
|
+
def __init__(self, name: str) -> None:
|
|
13
|
+
super().__init__(ConceptType.ATOMIC)
|
|
14
|
+
self._name: str = name
|
|
15
|
+
|
|
16
|
+
def clone(self) -> typing.Self:
|
|
17
|
+
return StringConcept(self.name)
|
|
18
|
+
|
|
19
|
+
def compute_name(self) -> str | None:
|
|
20
|
+
return f'"{self.name}"'
|
|
21
|
+
|
|
22
|
+
def get_roles(self) -> set[str]:
|
|
23
|
+
return set()
|
|
24
|
+
|
|
25
|
+
def compute_atomic_concepts(self) -> set[typing.Self]:
|
|
26
|
+
return set()
|
|
27
|
+
|
|
28
|
+
def replace(self, a: typing.Self, c: typing.Self) -> typing.Self | None:
|
|
29
|
+
return self
|
|
30
|
+
|
|
31
|
+
def __neg__(self) -> typing.Self:
|
|
32
|
+
raise FuzzyOntologyException("Strings cannot be complemented")
|
|
33
|
+
|
|
34
|
+
def __hash__(self) -> int:
|
|
35
|
+
return hash(str(self))
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
|
|
5
|
+
import trycast
|
|
6
|
+
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_weighted_concepts_interface import (
|
|
9
|
+
HasWeightedConceptsInterface,
|
|
10
|
+
)
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SugenoIntegral(Concept, HasWeightedConceptsInterface):
|
|
17
|
+
|
|
18
|
+
@typing.overload
|
|
19
|
+
def __init__(self) -> None: ...
|
|
20
|
+
|
|
21
|
+
@typing.overload
|
|
22
|
+
def __init__(
|
|
23
|
+
self, weights: typing.Optional[list[float]], concepts: list[Concept]
|
|
24
|
+
) -> None: ...
|
|
25
|
+
|
|
26
|
+
def __init__(self, *args) -> None:
|
|
27
|
+
assert len(args) in [0, 2]
|
|
28
|
+
if len(args) == 0:
|
|
29
|
+
self.__sugeno_init_1()
|
|
30
|
+
else:
|
|
31
|
+
trycast.checkcast(typing.Optional[list[float]], args[0])
|
|
32
|
+
trycast.checkcast(list[Concept], args[1])
|
|
33
|
+
self.__sugeno_init_2(*args)
|
|
34
|
+
|
|
35
|
+
def __sugeno_init_1(self) -> None:
|
|
36
|
+
Concept.__init__(self, ConceptType.SUGENO_INTEGRAL)
|
|
37
|
+
HasWeightedConceptsInterface.__init__(self, None, [])
|
|
38
|
+
|
|
39
|
+
def __sugeno_init_2(
|
|
40
|
+
self, weights: typing.Optional[list[float]], concepts: list[Concept]
|
|
41
|
+
) -> None:
|
|
42
|
+
Concept.__init__(self, ConceptType.SUGENO_INTEGRAL)
|
|
43
|
+
HasWeightedConceptsInterface.__init__(self, weights, concepts)
|
|
44
|
+
|
|
45
|
+
if weights is not None:
|
|
46
|
+
if len(weights) != len(concepts):
|
|
47
|
+
Util.error(
|
|
48
|
+
"Error: The number of weights and the number of concepts should be the same"
|
|
49
|
+
)
|
|
50
|
+
self.name = self.compute_name()
|
|
51
|
+
|
|
52
|
+
def clone(self) -> typing.Self:
|
|
53
|
+
return SugenoIntegral(self.weights[:], [c for c in self.concepts])
|
|
54
|
+
|
|
55
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
56
|
+
concept_list: set[Concept] = set()
|
|
57
|
+
for c in self.concepts:
|
|
58
|
+
concept_list.update(c.compute_atomic_concepts())
|
|
59
|
+
return concept_list
|
|
60
|
+
|
|
61
|
+
def get_roles(self) -> set[str]:
|
|
62
|
+
role_list: set[str] = set()
|
|
63
|
+
for c in self.concepts:
|
|
64
|
+
role_list.update(c.get_roles())
|
|
65
|
+
return role_list
|
|
66
|
+
|
|
67
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
68
|
+
return -SugenoIntegral(self.weights, [ci.replace(a, c) for ci in self.concepts])
|
|
69
|
+
|
|
70
|
+
def compute_name(self) -> str:
|
|
71
|
+
return f"(sugeno ({' '.join(map(str, self.weights))}) ({' '.join(map(str, self.concepts))}))"
|
|
72
|
+
|
|
73
|
+
def __neg__(self) -> Concept:
|
|
74
|
+
return OperatorConcept.not_(self)
|
|
75
|
+
|
|
76
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
77
|
+
return OperatorConcept.and_(self, value)
|
|
78
|
+
|
|
79
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
80
|
+
return OperatorConcept.or_(self, value)
|
|
81
|
+
|
|
82
|
+
def __hash__(self) -> int:
|
|
83
|
+
return hash(str(self))
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_concept_interface import (
|
|
5
|
+
HasConceptInterface,
|
|
6
|
+
)
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ThresholdConcept(Concept, HasConceptInterface):
|
|
12
|
+
|
|
13
|
+
def __init__(self, c_type: ConceptType, c: Concept, weight: float) -> None:
|
|
14
|
+
Concept.__init__(self, c_type)
|
|
15
|
+
HasConceptInterface.__init__(self, c)
|
|
16
|
+
|
|
17
|
+
assert c_type in (
|
|
18
|
+
ConceptType.POS_THRESHOLD,
|
|
19
|
+
ConceptType.NEG_THRESHOLD,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
self._weight: float = weight
|
|
23
|
+
self.name = self.compute_name()
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def weight(self) -> float:
|
|
27
|
+
return self._weight
|
|
28
|
+
|
|
29
|
+
@weight.setter
|
|
30
|
+
def weight(self, value: float) -> None:
|
|
31
|
+
self._weight = value
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def pos_threshold(w: float, c: typing.Self) -> typing.Self:
|
|
35
|
+
return ThresholdConcept(ConceptType.POS_THRESHOLD, c, w)
|
|
36
|
+
|
|
37
|
+
@staticmethod
|
|
38
|
+
def neg_threshold(w: float, c: typing.Self) -> typing.Self:
|
|
39
|
+
return ThresholdConcept(ConceptType.NEG_THRESHOLD, c, w)
|
|
40
|
+
|
|
41
|
+
def clone(self) -> typing.Self:
|
|
42
|
+
return ThresholdConcept(self.type, self.curr_concept, self.weight)
|
|
43
|
+
|
|
44
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
45
|
+
c_type: ConceptType = c.type
|
|
46
|
+
if c_type == ConceptType.POS_THRESHOLD:
|
|
47
|
+
return ThresholdConcept.pos_threshold(
|
|
48
|
+
self.weight, self.curr_concept.replace(a, c)
|
|
49
|
+
)
|
|
50
|
+
elif c_type == ConceptType.NEG_THRESHOLD:
|
|
51
|
+
return ThresholdConcept.neg_threshold(
|
|
52
|
+
self.weight, self.curr_concept.replace(a, c)
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def compute_name(self) -> typing.Optional[str]:
|
|
56
|
+
if self.type == ConceptType.POS_THRESHOLD:
|
|
57
|
+
return f"([>= {self.weight}] {self.curr_concept})"
|
|
58
|
+
elif self.type == ConceptType.NEG_THRESHOLD:
|
|
59
|
+
return f"([<= {self.weight}] {self.curr_concept})"
|
|
60
|
+
|
|
61
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
62
|
+
return self.curr_concept.compute_atomic_concepts()
|
|
63
|
+
|
|
64
|
+
def get_roles(self) -> set[str]:
|
|
65
|
+
return self.curr_concept.get_roles()
|
|
66
|
+
|
|
67
|
+
def __neg__(self) -> Concept:
|
|
68
|
+
return OperatorConcept.not_(self)
|
|
69
|
+
|
|
70
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
71
|
+
return OperatorConcept.and_(self, value)
|
|
72
|
+
|
|
73
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
74
|
+
return OperatorConcept.or_(self, value)
|
|
75
|
+
|
|
76
|
+
def __hash__(self) -> int:
|
|
77
|
+
return hash(str(self))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
PosThreshold = ThresholdConcept.pos_threshold
|
|
81
|
+
NegThreshold = ThresholdConcept.neg_threshold
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TruthConcept(Concept):
|
|
8
|
+
def __init__(self, c_type: ConceptType) -> None:
|
|
9
|
+
assert c_type in (ConceptType.TOP, ConceptType.BOTTOM)
|
|
10
|
+
if c_type == ConceptType.TOP:
|
|
11
|
+
super().__init__(ConceptType.TOP)
|
|
12
|
+
else:
|
|
13
|
+
super().__init__(ConceptType.BOTTOM)
|
|
14
|
+
self.name = self.compute_name()
|
|
15
|
+
|
|
16
|
+
@staticmethod
|
|
17
|
+
def get_top():
|
|
18
|
+
return TruthConcept(ConceptType.TOP)
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
def get_bottom():
|
|
22
|
+
return TruthConcept(ConceptType.BOTTOM)
|
|
23
|
+
|
|
24
|
+
def is_atomic(self) -> bool:
|
|
25
|
+
return True
|
|
26
|
+
|
|
27
|
+
def is_complemented_atomic(self) -> bool:
|
|
28
|
+
return False
|
|
29
|
+
|
|
30
|
+
def clone(self) -> typing.Self:
|
|
31
|
+
return TruthConcept(self.type)
|
|
32
|
+
|
|
33
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
def compute_name(self) -> typing.Optional[str]:
|
|
37
|
+
if self.type == ConceptType.TOP:
|
|
38
|
+
return "*top*"
|
|
39
|
+
elif self.type == ConceptType.BOTTOM:
|
|
40
|
+
return "*bottom*"
|
|
41
|
+
|
|
42
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
43
|
+
return set()
|
|
44
|
+
|
|
45
|
+
def get_atomic_concepts(self) -> set[typing.Self]:
|
|
46
|
+
return set([self])
|
|
47
|
+
|
|
48
|
+
def get_atoms(self) -> list[typing.Self]:
|
|
49
|
+
return [self]
|
|
50
|
+
|
|
51
|
+
def get_roles(self) -> set[str]:
|
|
52
|
+
return set()
|
|
53
|
+
|
|
54
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
55
|
+
return value if self.type == ConceptType.TOP else TruthConcept.get_bottom()
|
|
56
|
+
|
|
57
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
58
|
+
return TruthConcept.get_top() if self.type == ConceptType.TOP else value
|
|
59
|
+
|
|
60
|
+
def __rshift__(self, value: Concept) -> Concept:
|
|
61
|
+
if self.type == ConceptType.TOP:
|
|
62
|
+
return value
|
|
63
|
+
else:
|
|
64
|
+
return TruthConcept.get_top()
|
|
65
|
+
|
|
66
|
+
def __neg__(self) -> typing.Self:
|
|
67
|
+
if self.type == ConceptType.TOP:
|
|
68
|
+
return TruthConcept(ConceptType.BOTTOM)
|
|
69
|
+
else:
|
|
70
|
+
return TruthConcept(ConceptType.TOP)
|
|
71
|
+
|
|
72
|
+
def __hash__(self) -> int:
|
|
73
|
+
return hash(self.name)
|
|
74
|
+
|
|
75
|
+
def __eq__(self, value: typing.Self) -> bool:
|
|
76
|
+
return isinstance(value, TruthConcept) and str(self) == str(value)
|
|
77
|
+
|
|
78
|
+
def __ne__(self, value: typing.Self) -> bool:
|
|
79
|
+
return not (self == value)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
TOP: Concept = TruthConcept.get_top()
|
|
83
|
+
BOTTOM: Concept = TruthConcept.get_bottom()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_value_interface import (
|
|
5
|
+
HasValueInterface,
|
|
6
|
+
)
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ValueConcept(Concept, HasValueInterface):
|
|
12
|
+
|
|
13
|
+
def __init__(self, c_type: ConceptType, role: str, value: typing.Any) -> None:
|
|
14
|
+
Concept.__init__(self, c_type)
|
|
15
|
+
HasValueInterface.__init__(self, role, value)
|
|
16
|
+
|
|
17
|
+
assert c_type in (
|
|
18
|
+
ConceptType.AT_LEAST_VALUE,
|
|
19
|
+
ConceptType.AT_LEAST_VALUE,
|
|
20
|
+
ConceptType.EXACT_VALUE,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
self.name = self.compute_name()
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def at_most_value(role: str, o: typing.Any) -> typing.Self:
|
|
27
|
+
return ValueConcept(ConceptType.AT_MOST_VALUE, role, o)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def at_least_value(role: str, o: typing.Any) -> typing.Self:
|
|
31
|
+
return ValueConcept(ConceptType.AT_LEAST_VALUE, role, o)
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def exact_value(role: str, o: typing.Any) -> typing.Self:
|
|
35
|
+
return ValueConcept(ConceptType.EXACT_VALUE, role, o)
|
|
36
|
+
|
|
37
|
+
def clone(self) -> typing.Self:
|
|
38
|
+
return ValueConcept(self.type, self.role, self.value)
|
|
39
|
+
|
|
40
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def compute_name(self) -> typing.Optional[str]:
|
|
44
|
+
if self.type == ConceptType.AT_MOST_VALUE:
|
|
45
|
+
return f"(<= {self.role} {self.value})"
|
|
46
|
+
elif self.type == ConceptType.AT_LEAST_VALUE:
|
|
47
|
+
return f"(>= {self.role} {self.value})"
|
|
48
|
+
elif self.type == ConceptType.EXACT_VALUE:
|
|
49
|
+
return f"(= {self.role} {self.value})"
|
|
50
|
+
|
|
51
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
52
|
+
return set()
|
|
53
|
+
|
|
54
|
+
def get_roles(self) -> set[str]:
|
|
55
|
+
return set()
|
|
56
|
+
|
|
57
|
+
def __neg__(self) -> Concept:
|
|
58
|
+
return OperatorConcept.not_(self)
|
|
59
|
+
|
|
60
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
61
|
+
return OperatorConcept.and_(self, value)
|
|
62
|
+
|
|
63
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
64
|
+
return OperatorConcept.or_(self, value)
|
|
65
|
+
|
|
66
|
+
def __hash__(self) -> int:
|
|
67
|
+
return hash(str(self))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_concept_interface import (
|
|
5
|
+
HasConceptInterface,
|
|
6
|
+
)
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WeightedConcept(Concept, HasConceptInterface):
|
|
12
|
+
|
|
13
|
+
def __init__(self, weight: float, c: Concept) -> None:
|
|
14
|
+
Concept.__init__(self, ConceptType.WEIGHTED)
|
|
15
|
+
HasConceptInterface.__init__(self, c)
|
|
16
|
+
|
|
17
|
+
self._weight: float = weight
|
|
18
|
+
self.name = self.compute_name()
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def weight(self) -> float:
|
|
22
|
+
return self._weight
|
|
23
|
+
|
|
24
|
+
@weight.setter
|
|
25
|
+
def weight(self, value: float) -> None:
|
|
26
|
+
self._weight = value
|
|
27
|
+
|
|
28
|
+
def clone(self) -> typing.Self:
|
|
29
|
+
return WeightedConcept(self.weight, self.curr_concept)
|
|
30
|
+
|
|
31
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
32
|
+
c_type: ConceptType = c.type
|
|
33
|
+
if c_type == ConceptType.WEIGHTED:
|
|
34
|
+
return WeightedConcept(self.weight, self.curr_concept.replace(a, c))
|
|
35
|
+
|
|
36
|
+
def compute_name(self) -> typing.Optional[str]:
|
|
37
|
+
return f"({self.weight} {self.curr_concept})"
|
|
38
|
+
|
|
39
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
40
|
+
return self.curr_concept.compute_atomic_concepts()
|
|
41
|
+
|
|
42
|
+
def get_roles(self) -> set[str]:
|
|
43
|
+
return self.curr_concept.get_roles()
|
|
44
|
+
|
|
45
|
+
def __neg__(self) -> Concept:
|
|
46
|
+
return OperatorConcept.not_(self)
|
|
47
|
+
|
|
48
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
49
|
+
return OperatorConcept.and_(self, value)
|
|
50
|
+
|
|
51
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
52
|
+
return OperatorConcept.or_(self, value)
|
|
53
|
+
|
|
54
|
+
def __hash__(self) -> int:
|
|
55
|
+
return hash(str(self))
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_weighted_concepts_interface import (
|
|
5
|
+
HasWeightedConceptsInterface,
|
|
6
|
+
)
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WeightedMaxConcept(Concept, HasWeightedConceptsInterface):
|
|
13
|
+
|
|
14
|
+
def __init__(self, weights: list[float], concepts: list[Concept]) -> None:
|
|
15
|
+
Concept.__init__(self, ConceptType.W_MAX)
|
|
16
|
+
HasWeightedConceptsInterface.__init__(self, weights, concepts)
|
|
17
|
+
|
|
18
|
+
if len(weights) != len(concepts):
|
|
19
|
+
Util.error(
|
|
20
|
+
"Error: The number of weights and the number of concepts should be the same"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
if not any(w == 1.0 for w in weights):
|
|
24
|
+
Util.error(
|
|
25
|
+
"Error: Some of the weights of the weighted max concept must be 1.0."
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
self.name = self.compute_name()
|
|
29
|
+
|
|
30
|
+
def clone(self) -> typing.Self:
|
|
31
|
+
return WeightedMaxConcept(self.weights[:], [c for c in self.concepts])
|
|
32
|
+
|
|
33
|
+
def compute_atomic_concepts(self) -> set[Concept]:
|
|
34
|
+
concept_list: set[Concept] = set()
|
|
35
|
+
for c in self.concepts:
|
|
36
|
+
concept_list.update(c.compute_atomic_concepts())
|
|
37
|
+
return concept_list
|
|
38
|
+
|
|
39
|
+
def get_roles(self) -> set[str]:
|
|
40
|
+
role_list: set[str] = set()
|
|
41
|
+
for c in self.concepts:
|
|
42
|
+
role_list.update(c.get_roles())
|
|
43
|
+
return role_list
|
|
44
|
+
|
|
45
|
+
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
46
|
+
return -WeightedMaxConcept(
|
|
47
|
+
self.weights, [ci.replace(a, c) for ci in self.concepts]
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
def compute_name(self) -> str:
|
|
51
|
+
return f"(w-max {' '.join([f'({concept} {weight})' for concept, weight in zip(self.concepts, self.weights)])})"
|
|
52
|
+
|
|
53
|
+
def __neg__(self) -> Concept:
|
|
54
|
+
return OperatorConcept.not_(self)
|
|
55
|
+
|
|
56
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
57
|
+
return OperatorConcept.and_(self, value)
|
|
58
|
+
|
|
59
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
60
|
+
return OperatorConcept.or_(self, value)
|
|
61
|
+
|
|
62
|
+
def __hash__(self) -> int:
|
|
63
|
+
return hash(str(self))
|