fuzzy-dl-owl2 1.0.2__py3-none-any.whl → 1.0.3__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/fuzzydl/concept/approximation_concept.py +35 -10
- fuzzy_dl_owl2/fuzzydl/concept/concrete/fuzzy_number/triangular_fuzzy_number.py +2 -1
- fuzzy_dl_owl2/fuzzydl/concept/concrete/trapezoidal_concrete_concept.py +1 -0
- fuzzy_dl_owl2/fuzzydl/concept/implies_concept.py +14 -11
- fuzzy_dl_owl2/fuzzydl/concept/operator_concept.py +10 -6
- fuzzy_dl_owl2/fuzzydl/concept/value_concept.py +1 -1
- fuzzy_dl_owl2/fuzzydl/concrete_feature.py +7 -1
- fuzzy_dl_owl2/fuzzydl/feature_function.py +16 -2
- fuzzy_dl_owl2/fuzzydl/fuzzydl_to_owl2.py +1 -1
- fuzzy_dl_owl2/fuzzydl/knowledge_base.py +494 -358
- fuzzy_dl_owl2/fuzzydl/milp/expression.py +4 -2
- fuzzy_dl_owl2/fuzzydl/milp/milp_helper.py +3 -2
- fuzzy_dl_owl2/fuzzydl/milp/variable.py +3 -0
- fuzzy_dl_owl2/fuzzydl/modifier/triangular_modifier.py +1 -1
- fuzzy_dl_owl2/fuzzydl/parser/dl_parser.py +1465 -1210
- fuzzy_dl_owl2/fuzzydl/query/defuzzify/mom_defuzzify_query.py +14 -7
- fuzzy_dl_owl2/fuzzydl/query/min/min_subsumes_query.py +2 -2
- fuzzy_dl_owl2/fuzzydl/util/config_reader.py +0 -6
- fuzzy_dl_owl2/fuzzydl/util/constants.py +10 -9
- fuzzy_dl_owl2/fuzzydl/util/utils.py +48 -7
- fuzzy_dl_owl2/fuzzyowl2/fuzzyowl2.py +1 -1
- {fuzzy_dl_owl2-1.0.2.dist-info → fuzzy_dl_owl2-1.0.3.dist-info}/METADATA +9 -7
- {fuzzy_dl_owl2-1.0.2.dist-info → fuzzy_dl_owl2-1.0.3.dist-info}/RECORD +25 -25
- {fuzzy_dl_owl2-1.0.2.dist-info → fuzzy_dl_owl2-1.0.3.dist-info}/LICENSE +0 -0
- {fuzzy_dl_owl2-1.0.2.dist-info → fuzzy_dl_owl2-1.0.3.dist-info}/WHEEL +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.all_some_concept import AllSomeConcept
|
|
3
4
|
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
5
|
from fuzzy_dl_owl2.fuzzydl.concept.interface.has_role_concept_interface import (
|
|
5
6
|
HasRoleConceptInterface,
|
|
@@ -48,29 +49,52 @@ class ApproximationConcept(Concept, HasRoleConceptInterface):
|
|
|
48
49
|
self.name = self.compute_name()
|
|
49
50
|
|
|
50
51
|
@staticmethod
|
|
51
|
-
def lower_approx(role: str, c: Concept) ->
|
|
52
|
+
def lower_approx(role: str, c: Concept) -> typing.Self:
|
|
52
53
|
return ApproximationConcept(ConceptType.LOWER_APPROX, role, c)
|
|
53
54
|
|
|
54
55
|
@staticmethod
|
|
55
|
-
def loose_lower_approx(role: str, c: Concept) ->
|
|
56
|
+
def loose_lower_approx(role: str, c: Concept) -> typing.Self:
|
|
56
57
|
return ApproximationConcept(ConceptType.LOOSE_LOWER_APPROX, role, c)
|
|
57
58
|
|
|
58
59
|
@staticmethod
|
|
59
|
-
def tight_lower_approx(role: str, c: Concept) ->
|
|
60
|
+
def tight_lower_approx(role: str, c: Concept) -> typing.Self:
|
|
60
61
|
return ApproximationConcept(ConceptType.TIGHT_LOWER_APPROX, role, c)
|
|
61
62
|
|
|
62
63
|
@staticmethod
|
|
63
|
-
def upper_approx(role: str, c: Concept) ->
|
|
64
|
+
def upper_approx(role: str, c: Concept) -> typing.Self:
|
|
64
65
|
return ApproximationConcept(ConceptType.UPPER_APPROX, role, c)
|
|
65
66
|
|
|
66
67
|
@staticmethod
|
|
67
|
-
def loose_upper_approx(role: str, c: Concept) ->
|
|
68
|
+
def loose_upper_approx(role: str, c: Concept) -> typing.Self:
|
|
68
69
|
return ApproximationConcept(ConceptType.LOOSE_UPPER_APPROX, role, c)
|
|
69
70
|
|
|
70
71
|
@staticmethod
|
|
71
|
-
def tight_upper_approx(role: str, c: Concept) ->
|
|
72
|
+
def tight_upper_approx(role: str, c: Concept) -> typing.Self:
|
|
72
73
|
return ApproximationConcept(ConceptType.TIGHT_UPPER_APPROX, role, c)
|
|
73
74
|
|
|
75
|
+
def to_all_some_concept(self) -> AllSomeConcept:
|
|
76
|
+
if self.type == ConceptType.LOWER_APPROX:
|
|
77
|
+
return AllSomeConcept.all(self.role, self.curr_concept)
|
|
78
|
+
if self.type == ConceptType.TIGHT_LOWER_APPROX:
|
|
79
|
+
return AllSomeConcept.all(
|
|
80
|
+
self.role, AllSomeConcept.all(self.role, self.curr_concept)
|
|
81
|
+
)
|
|
82
|
+
if self.type == ConceptType.LOOSE_LOWER_APPROX:
|
|
83
|
+
return AllSomeConcept.some(
|
|
84
|
+
self.role, AllSomeConcept.all(self.role, self.curr_concept)
|
|
85
|
+
)
|
|
86
|
+
if self.type == ConceptType.UPPER_APPROX:
|
|
87
|
+
return AllSomeConcept.some(self.role, self.curr_concept)
|
|
88
|
+
if self.type == ConceptType.TIGHT_UPPER_APPROX:
|
|
89
|
+
return AllSomeConcept.all(
|
|
90
|
+
self.role, AllSomeConcept.some(self.role, self.curr_concept)
|
|
91
|
+
)
|
|
92
|
+
if self.type == ConceptType.LOOSE_UPPER_APPROX:
|
|
93
|
+
return AllSomeConcept.some(
|
|
94
|
+
self.role, AllSomeConcept.some(self.role, self.curr_concept)
|
|
95
|
+
)
|
|
96
|
+
raise ValueError
|
|
97
|
+
|
|
74
98
|
def clone(self) -> typing.Self:
|
|
75
99
|
return ApproximationConcept(self.type, self.role, self.curr_concept)
|
|
76
100
|
|
|
@@ -111,10 +135,11 @@ class ApproximationConcept(Concept, HasRoleConceptInterface):
|
|
|
111
135
|
return f"(lla {self.role} {self.curr_concept})"
|
|
112
136
|
elif self.type == ConceptType.UPPER_APPROX:
|
|
113
137
|
return f"(ua {self.role} {self.curr_concept})"
|
|
114
|
-
elif self.type == ConceptType.
|
|
115
|
-
return f"(
|
|
116
|
-
elif self.type == ConceptType.
|
|
117
|
-
return f"(
|
|
138
|
+
elif self.type == ConceptType.TIGHT_UPPER_APPROX:
|
|
139
|
+
return f"(tua {self.role} {self.curr_concept})"
|
|
140
|
+
elif self.type == ConceptType.TIGHT_LOWER_APPROX:
|
|
141
|
+
return f"(tla {self.role} {self.curr_concept})"
|
|
142
|
+
raise ValueError
|
|
118
143
|
|
|
119
144
|
def compute_atomic_concepts(self) -> set[Concept]:
|
|
120
145
|
return self.curr_concept.compute_atomic_concepts()
|
|
@@ -34,6 +34,7 @@ class TriangularFuzzyNumber(TriangularConcreteConcept):
|
|
|
34
34
|
def __tringular_fn_init_1(self, name: str, a: float, b: float, c: float) -> None:
|
|
35
35
|
super().__init__(name, self.K1, self.K2, a, b, c)
|
|
36
36
|
self.type = ConceptType.FUZZY_NUMBER
|
|
37
|
+
self.name = name or self.compute_name()
|
|
37
38
|
|
|
38
39
|
def __tringular_fn_init_2(self, a: float, b: float, c: float) -> None:
|
|
39
40
|
self.__init__(f"({a}, {b}, {c})", a, b, c)
|
|
@@ -76,7 +77,7 @@ class TriangularFuzzyNumber(TriangularConcreteConcept):
|
|
|
76
77
|
return self.a == self.b == self.c
|
|
77
78
|
|
|
78
79
|
def compute_name(self) -> str:
|
|
79
|
-
return f"({self.k1}, {self.k2}
|
|
80
|
+
return f"({self.k1}, {self.k2}; {self.a}, {self.b}, {self.c})"
|
|
80
81
|
|
|
81
82
|
def __add__(self, other: typing.Self) -> typing.Self:
|
|
82
83
|
return TriangularFuzzyNumber(
|
|
@@ -14,6 +14,7 @@ class TrapezoidalConcreteConcept(FuzzyConcreteConcept):
|
|
|
14
14
|
def __init__(
|
|
15
15
|
self, name: str, k1: float, k2: float, a: float, b: float, c: float, d: float
|
|
16
16
|
) -> None:
|
|
17
|
+
super().__init__(name)
|
|
17
18
|
if a > b or b > c or c > d:
|
|
18
19
|
Util.error(f"Error: Trapezoidal functions require {a} <= {b} <= {c} <= {d}")
|
|
19
20
|
if k1 > a:
|
|
@@ -10,10 +10,12 @@ from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import (
|
|
|
10
10
|
GoedelOr,
|
|
11
11
|
LukasiewiczOr,
|
|
12
12
|
Not,
|
|
13
|
+
OperatorConcept,
|
|
13
14
|
Or,
|
|
14
15
|
)
|
|
15
16
|
from fuzzy_dl_owl2.fuzzydl.concept.truth_concept import TruthConcept
|
|
16
|
-
from fuzzy_dl_owl2.fuzzydl.util
|
|
17
|
+
from fuzzy_dl_owl2.fuzzydl.util import constants
|
|
18
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import ConceptType, FuzzyLogic
|
|
17
19
|
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
18
20
|
|
|
19
21
|
|
|
@@ -26,7 +28,6 @@ class ImpliesConcept(Concept, HasConceptsInterface):
|
|
|
26
28
|
assert c_type in (
|
|
27
29
|
ConceptType.ZADEH_IMPLIES,
|
|
28
30
|
ConceptType.GOEDEL_IMPLIES,
|
|
29
|
-
ConceptType,
|
|
30
31
|
)
|
|
31
32
|
|
|
32
33
|
self.name: str = self.compute_name()
|
|
@@ -42,8 +43,8 @@ class ImpliesConcept(Concept, HasConceptsInterface):
|
|
|
42
43
|
return TruthConcept.get_top()
|
|
43
44
|
if c2.type == ConceptType.BOTTOM:
|
|
44
45
|
return -c1
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if constants.KNOWLEDGE_BASE_SEMANTICS == FuzzyLogic.CLASSICAL:
|
|
47
|
+
return Or(-c1, c2)
|
|
47
48
|
return LukasiewiczOr(-c1, c2)
|
|
48
49
|
|
|
49
50
|
@staticmethod
|
|
@@ -52,8 +53,8 @@ class ImpliesConcept(Concept, HasConceptsInterface):
|
|
|
52
53
|
return c2
|
|
53
54
|
if c2.type == ConceptType.TOP or c1.type == ConceptType.BOTTOM:
|
|
54
55
|
return TruthConcept.get_top()
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
if constants.KNOWLEDGE_BASE_SEMANTICS == FuzzyLogic.CLASSICAL:
|
|
57
|
+
return Or(-c1, c2)
|
|
57
58
|
return GoedelOr(-c1, c2)
|
|
58
59
|
|
|
59
60
|
@staticmethod
|
|
@@ -62,16 +63,18 @@ class ImpliesConcept(Concept, HasConceptsInterface):
|
|
|
62
63
|
return c2
|
|
63
64
|
if c2.type == ConceptType.TOP or c1.type == ConceptType.BOTTOM:
|
|
64
65
|
return TruthConcept.get_top()
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
if constants.KNOWLEDGE_BASE_SEMANTICS == FuzzyLogic.CLASSICAL:
|
|
67
|
+
return Or(-c1, c2)
|
|
67
68
|
if c1.type == ConceptType.GOEDEL_OR:
|
|
68
|
-
return GoedelAnd(
|
|
69
|
+
return GoedelAnd(
|
|
70
|
+
[GoedelOr(ci, c2) for ci in typing.cast(OperatorConcept, c1).concepts]
|
|
71
|
+
)
|
|
69
72
|
return ImpliesConcept(ConceptType.GOEDEL_IMPLIES, [c1, c2])
|
|
70
73
|
|
|
71
74
|
@staticmethod
|
|
72
75
|
def zadeh_implies(c1: Concept, c2: Concept) -> Concept:
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
if constants.KNOWLEDGE_BASE_SEMANTICS == FuzzyLogic.CLASSICAL:
|
|
77
|
+
return Or(-c1, c2)
|
|
75
78
|
return ImpliesConcept(ConceptType.ZADEH_IMPLIES, [c1, c2])
|
|
76
79
|
|
|
77
80
|
def replace(self, a: Concept, c: Concept) -> Concept:
|
|
@@ -360,16 +360,20 @@ class OperatorConcept(Concept, HasConceptsInterface):
|
|
|
360
360
|
A | A = A
|
|
361
361
|
"""
|
|
362
362
|
if OperatorConcept.is_and(self.type):
|
|
363
|
-
if
|
|
364
|
-
|
|
363
|
+
if (
|
|
364
|
+
ConceptType.BOTTOM in [c.type for c in self.concepts]
|
|
365
|
+
or any(-c in self.concepts for c in self.concepts)
|
|
366
|
+
and constants.KNOWLEDGE_BASE_SEMANTICS == FuzzyLogic.CLASSICAL
|
|
365
367
|
):
|
|
366
368
|
return TruthConcept.get_bottom()
|
|
367
369
|
if self.type in OperatorConcept.ABSORPTION_OPERATORS:
|
|
368
370
|
self.concepts = sorted(set(self.concepts))
|
|
369
371
|
self.concepts = [c for c in self.concepts if c.type != ConceptType.TOP]
|
|
370
372
|
elif OperatorConcept.is_or(self.type):
|
|
371
|
-
if
|
|
372
|
-
|
|
373
|
+
if (
|
|
374
|
+
ConceptType.TOP in [c.type for c in self.concepts]
|
|
375
|
+
or any(-c in self.concepts for c in self.concepts)
|
|
376
|
+
and constants.KNOWLEDGE_BASE_SEMANTICS == FuzzyLogic.CLASSICAL
|
|
373
377
|
):
|
|
374
378
|
return TruthConcept.get_top()
|
|
375
379
|
if self.type in OperatorConcept.ABSORPTION_OPERATORS:
|
|
@@ -458,8 +462,8 @@ class OperatorConcept(Concept, HasConceptsInterface):
|
|
|
458
462
|
if a not in [TruthConcept.get_bottom(), TruthConcept.get_top()]
|
|
459
463
|
]
|
|
460
464
|
)
|
|
461
|
-
if len(self.concepts) == 1:
|
|
462
|
-
|
|
465
|
+
# if len(self.concepts) == 1:
|
|
466
|
+
# return self.concepts[0]
|
|
463
467
|
return OperatorConcept.__op(self.type, self.concepts)
|
|
464
468
|
|
|
465
469
|
def reduce_quantifiers(self) -> typing.Self:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.util import constants
|
|
3
4
|
from fuzzy_dl_owl2.fuzzydl.util.constants import ConcreteFeatureType
|
|
4
5
|
|
|
5
6
|
|
|
@@ -29,7 +30,9 @@ class ConcreteFeature:
|
|
|
29
30
|
elif len(args) == 3:
|
|
30
31
|
if isinstance(args[1], int) and isinstance(args[2], int):
|
|
31
32
|
self.__concrete_feature_init_3(*args)
|
|
32
|
-
elif isinstance(args[1],
|
|
33
|
+
elif isinstance(args[1], constants.NUMBER) and isinstance(
|
|
34
|
+
args[2], constants.NUMBER
|
|
35
|
+
):
|
|
33
36
|
self.__concrete_feature_init_4(*args)
|
|
34
37
|
else:
|
|
35
38
|
raise ValueError
|
|
@@ -90,5 +93,8 @@ class ConcreteFeature:
|
|
|
90
93
|
def get_name(self) -> str:
|
|
91
94
|
return self.name
|
|
92
95
|
|
|
96
|
+
def __repr__(self) -> str:
|
|
97
|
+
return str(self)
|
|
98
|
+
|
|
93
99
|
def __str__(self) -> str:
|
|
94
100
|
return self.get_name()
|
|
@@ -13,6 +13,9 @@ from fuzzy_dl_owl2.fuzzydl.util.constants import FeatureFunctionType
|
|
|
13
13
|
|
|
14
14
|
class FeatureFunction:
|
|
15
15
|
|
|
16
|
+
@typing.overload
|
|
17
|
+
def __init__(self, feature: typing.Self) -> None: ...
|
|
18
|
+
|
|
16
19
|
@typing.overload
|
|
17
20
|
def __init__(self, feature: str) -> None: ...
|
|
18
21
|
|
|
@@ -31,7 +34,9 @@ class FeatureFunction:
|
|
|
31
34
|
def __init__(self, *args) -> None:
|
|
32
35
|
assert len(args) in [1, 2]
|
|
33
36
|
if len(args) == 1:
|
|
34
|
-
if isinstance(args[0],
|
|
37
|
+
if isinstance(args[0], FeatureFunction):
|
|
38
|
+
self.__feature_function_init_6(*args)
|
|
39
|
+
elif isinstance(args[0], str):
|
|
35
40
|
self.__feature_function_init_1(*args)
|
|
36
41
|
elif isinstance(args[0], constants.NUMBER):
|
|
37
42
|
self.__feature_function_init_2(*args)
|
|
@@ -87,6 +92,12 @@ class FeatureFunction:
|
|
|
87
92
|
self.feature: str = ""
|
|
88
93
|
self.n: float = n
|
|
89
94
|
|
|
95
|
+
def __feature_function_init_6(self, feature: typing.Self) -> None:
|
|
96
|
+
self.type: FeatureFunctionType = feature.type
|
|
97
|
+
self.f: list[FeatureFunction] = feature.f
|
|
98
|
+
self.feature: str = feature.feature
|
|
99
|
+
self.n: float = feature.n
|
|
100
|
+
|
|
90
101
|
def get_type(self) -> FeatureFunctionType:
|
|
91
102
|
return self.type
|
|
92
103
|
|
|
@@ -134,6 +145,9 @@ class FeatureFunction:
|
|
|
134
145
|
return ex1
|
|
135
146
|
return None
|
|
136
147
|
|
|
148
|
+
def __repr__(self) -> str:
|
|
149
|
+
return str(self)
|
|
150
|
+
|
|
137
151
|
def __str__(self) -> str:
|
|
138
152
|
if self.type == FeatureFunctionType.ATOMIC:
|
|
139
153
|
return self.feature
|
|
@@ -144,5 +158,5 @@ class FeatureFunction:
|
|
|
144
158
|
elif self.type == FeatureFunctionType.SUBTRACTION:
|
|
145
159
|
return f"({self.f[0]} - {self.f[1]})"
|
|
146
160
|
elif self.type == FeatureFunctionType.SUM:
|
|
147
|
-
return f"({' + '.join(map(str, self.f))}"
|
|
161
|
+
return f"({' + '.join(map(str, self.f))})"
|
|
148
162
|
return ""
|
|
@@ -517,7 +517,7 @@ class FuzzydlToOwl2:
|
|
|
517
517
|
self, value: typing.Union[float, DegreeNumeric]
|
|
518
518
|
) -> set[OWLAnnotation]:
|
|
519
519
|
"""Get annotations for an axiom with degree"""
|
|
520
|
-
if isinstance(value,
|
|
520
|
+
if isinstance(value, constants.NUMBER):
|
|
521
521
|
n = value
|
|
522
522
|
elif isinstance(value, DegreeNumeric): # Degree object
|
|
523
523
|
n = value.get_numerical_value()
|