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,151 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import copy
|
|
4
|
+
import typing
|
|
5
|
+
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concrete.fuzzy_concrete_concept import (
|
|
7
|
+
FuzzyConcreteConcept,
|
|
8
|
+
)
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ShowVariablesHelper:
|
|
13
|
+
def __init__(self) -> None:
|
|
14
|
+
self.abstract_fillers: dict[str, set[str]] = dict()
|
|
15
|
+
self.concepts: set[str] = set()
|
|
16
|
+
self.concrete_fillers: dict[str, set[str]] = dict()
|
|
17
|
+
self.global_abstract_fillers: set[str] = set()
|
|
18
|
+
self.global_concrete_fillers: set[str] = set()
|
|
19
|
+
self.individuals: set[str] = set()
|
|
20
|
+
self.labels_for_fillers: dict[str, list[FuzzyConcreteConcept]] = dict()
|
|
21
|
+
self.variables: dict[Variable, str] = dict()
|
|
22
|
+
|
|
23
|
+
def clone(self) -> typing.Self:
|
|
24
|
+
s = ShowVariablesHelper()
|
|
25
|
+
s.abstract_fillers = copy.deepcopy(self.abstract_fillers)
|
|
26
|
+
s.concepts = copy.deepcopy(self.concepts)
|
|
27
|
+
s.concrete_fillers = copy.deepcopy(self.concrete_fillers)
|
|
28
|
+
s.global_abstract_fillers = copy.deepcopy(self.global_abstract_fillers)
|
|
29
|
+
s.global_concrete_fillers = copy.deepcopy(self.global_concrete_fillers)
|
|
30
|
+
s.individuals = copy.deepcopy(self.individuals)
|
|
31
|
+
s.labels_for_fillers = {
|
|
32
|
+
k: [c for c in v] for k, v in self.labels_for_fillers.items()
|
|
33
|
+
}
|
|
34
|
+
s.variables = {k: v for k, v in self.variables.items()}
|
|
35
|
+
return s
|
|
36
|
+
|
|
37
|
+
def get_name(self, var: Variable) -> str:
|
|
38
|
+
return self.variables.get(var)
|
|
39
|
+
|
|
40
|
+
def show_variable(self, var: Variable) -> bool:
|
|
41
|
+
return var in self.variables
|
|
42
|
+
|
|
43
|
+
def add_individual_to_show(self, ind_name: str) -> None:
|
|
44
|
+
self.individuals.add(ind_name)
|
|
45
|
+
|
|
46
|
+
def show_individuals(self, ind_name: str) -> bool:
|
|
47
|
+
return ind_name in self.individuals
|
|
48
|
+
|
|
49
|
+
@typing.overload
|
|
50
|
+
def add_concrete_filler_to_show(self, f_name: str) -> None: ...
|
|
51
|
+
|
|
52
|
+
@typing.overload
|
|
53
|
+
def add_concrete_filler_to_show(self, f_name: str, ind_name: str) -> None: ...
|
|
54
|
+
|
|
55
|
+
@typing.overload
|
|
56
|
+
def add_concrete_filler_to_show(
|
|
57
|
+
self, f_name: str, ind_name: str, ar: list[FuzzyConcreteConcept]
|
|
58
|
+
) -> None: ...
|
|
59
|
+
|
|
60
|
+
def add_concrete_filler_to_show(self, *args) -> None:
|
|
61
|
+
assert len(args) in [1, 2, 3]
|
|
62
|
+
assert isinstance(args[0], str)
|
|
63
|
+
if len(args) == 1:
|
|
64
|
+
self.__add_concrete_filler_to_show_1(*args)
|
|
65
|
+
elif len(args) == 2:
|
|
66
|
+
assert isinstance(args[1], str)
|
|
67
|
+
self.__add_concrete_filler_to_show_2(*args)
|
|
68
|
+
else:
|
|
69
|
+
assert isinstance(args[1], str)
|
|
70
|
+
assert isinstance(args[2], list) and all(
|
|
71
|
+
isinstance(a, FuzzyConcreteConcept) for a in args[2]
|
|
72
|
+
)
|
|
73
|
+
self.__add_concrete_filler_to_show_3(*args)
|
|
74
|
+
|
|
75
|
+
def __add_concrete_filler_to_show_1(self, f_name: str) -> None:
|
|
76
|
+
self.global_concrete_fillers.add(f_name)
|
|
77
|
+
if f_name in self.concrete_fillers:
|
|
78
|
+
del self.concrete_fillers[f_name]
|
|
79
|
+
|
|
80
|
+
def __add_concrete_filler_to_show_2(self, f_name: str, ind_name: str) -> None:
|
|
81
|
+
if f_name in self.global_concrete_fillers:
|
|
82
|
+
return
|
|
83
|
+
self.concrete_fillers[f_name] = self.concrete_fillers.get(f_name, set()) | set(
|
|
84
|
+
[ind_name]
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def __add_concrete_filler_to_show_3(
|
|
88
|
+
self, f_name: str, ind_name: str, ar: list[FuzzyConcreteConcept]
|
|
89
|
+
) -> None:
|
|
90
|
+
self.add_concrete_filler_to_show(f_name, ind_name)
|
|
91
|
+
name: str = f"{f_name}({ind_name})"
|
|
92
|
+
aux: list[FuzzyConcreteConcept] = self.get_labels(name)
|
|
93
|
+
if len(aux) > 0:
|
|
94
|
+
aux.extend(ar)
|
|
95
|
+
self.labels_for_fillers[name] = aux
|
|
96
|
+
else:
|
|
97
|
+
self.labels_for_fillers[name] = ar
|
|
98
|
+
|
|
99
|
+
def get_labels(self, var_name: str) -> list[FuzzyConcreteConcept]:
|
|
100
|
+
return self.labels_for_fillers.get(var_name, [])
|
|
101
|
+
|
|
102
|
+
@typing.overload
|
|
103
|
+
def add_abstract_filler_to_show(self, role_name: str) -> None: ...
|
|
104
|
+
|
|
105
|
+
@typing.overload
|
|
106
|
+
def add_abstract_filler_to_show(self, role_name: str, ind_name: str) -> None: ...
|
|
107
|
+
|
|
108
|
+
def add_abstract_filler_to_show(self, *args) -> None:
|
|
109
|
+
assert len(args) in [1, 2]
|
|
110
|
+
assert isinstance(args[0], str)
|
|
111
|
+
if len(args) == 1:
|
|
112
|
+
self.__add_abstract_filler_to_show_1(*args)
|
|
113
|
+
else:
|
|
114
|
+
assert isinstance(args[1], str)
|
|
115
|
+
self.__add_abstract_filler_to_show_2(*args)
|
|
116
|
+
|
|
117
|
+
def __add_abstract_filler_to_show_1(self, role_name: str) -> None:
|
|
118
|
+
self.global_abstract_fillers.add(role_name)
|
|
119
|
+
if role_name in self.abstract_fillers:
|
|
120
|
+
del self.abstract_fillers[role_name]
|
|
121
|
+
|
|
122
|
+
def __add_abstract_filler_to_show_2(self, role_name: str, ind_name: str) -> None:
|
|
123
|
+
if role_name in self.global_abstract_fillers:
|
|
124
|
+
return
|
|
125
|
+
self.abstract_fillers[role_name] = self.abstract_fillers.get(
|
|
126
|
+
role_name, set()
|
|
127
|
+
) | set([ind_name])
|
|
128
|
+
|
|
129
|
+
def show_concrete_fillers(self, f_name: str, ind_name: str) -> bool:
|
|
130
|
+
if f_name not in self.global_concrete_fillers:
|
|
131
|
+
hs = self.concrete_fillers.get(f_name)
|
|
132
|
+
return hs is not None and ind_name in hs
|
|
133
|
+
return True
|
|
134
|
+
|
|
135
|
+
def show_abstract_role_fillers(self, role_name: str, ind_name: str) -> bool:
|
|
136
|
+
if role_name not in self.global_abstract_fillers:
|
|
137
|
+
hs = self.abstract_fillers.get(role_name)
|
|
138
|
+
return hs is not None and ind_name in hs
|
|
139
|
+
return True
|
|
140
|
+
|
|
141
|
+
def add_concept_to_show(self, conc_name: str) -> None:
|
|
142
|
+
self.concepts.add(conc_name)
|
|
143
|
+
|
|
144
|
+
def show_concepts(self, concept_name: str) -> bool:
|
|
145
|
+
return concept_name in self.concepts
|
|
146
|
+
|
|
147
|
+
def add_variable(self, var: Variable, name_to_show: str) -> None:
|
|
148
|
+
self.variables[var] = name_to_show
|
|
149
|
+
|
|
150
|
+
def get_variables(self) -> list[Variable]:
|
|
151
|
+
return list(self.variables.keys())
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.util import constants
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Solution:
|
|
7
|
+
CONSISTENT_KB: bool = True
|
|
8
|
+
INCONSISTENT_KB: bool = False
|
|
9
|
+
|
|
10
|
+
@typing.overload
|
|
11
|
+
def __init__(self, consistent: bool) -> None: ...
|
|
12
|
+
|
|
13
|
+
@typing.overload
|
|
14
|
+
def __init__(self, sol: float) -> None: ...
|
|
15
|
+
|
|
16
|
+
def __init__(self, *args) -> None:
|
|
17
|
+
assert len(args) == 1
|
|
18
|
+
if isinstance(args[0], bool):
|
|
19
|
+
self.__solution_init_1(*args)
|
|
20
|
+
elif isinstance(args[0], constants.NUMBER):
|
|
21
|
+
self.__solution_init_2(*args)
|
|
22
|
+
else:
|
|
23
|
+
raise ValueError
|
|
24
|
+
|
|
25
|
+
def __solution_init_1(self, consistent: bool) -> None:
|
|
26
|
+
self.sol: typing.Union[bool, float] = 0.0
|
|
27
|
+
self.consistent: bool = consistent
|
|
28
|
+
|
|
29
|
+
def __solution_init_2(self, sol: float) -> None:
|
|
30
|
+
self.sol: typing.Union[bool, float] = sol
|
|
31
|
+
self.consistent: bool = True
|
|
32
|
+
|
|
33
|
+
def is_consistent_kb(self) -> bool:
|
|
34
|
+
return self.consistent
|
|
35
|
+
|
|
36
|
+
def get_solution(self) -> typing.Union[bool, float]:
|
|
37
|
+
return self.sol
|
|
38
|
+
|
|
39
|
+
def __repr__(self) -> str:
|
|
40
|
+
return str(self)
|
|
41
|
+
|
|
42
|
+
def __str__(self) -> str:
|
|
43
|
+
if self.consistent:
|
|
44
|
+
return str(self.sol)
|
|
45
|
+
return "Inconsistent KB"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.util import constants
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Term:
|
|
8
|
+
|
|
9
|
+
@typing.overload
|
|
10
|
+
def __init__(self, coeff: float, var: Variable) -> None: ...
|
|
11
|
+
|
|
12
|
+
@typing.overload
|
|
13
|
+
def __init__(self, var: Variable) -> None: ...
|
|
14
|
+
|
|
15
|
+
def __init__(self, *args) -> None:
|
|
16
|
+
assert len(args) in [1, 2]
|
|
17
|
+
if len(args) == 1:
|
|
18
|
+
assert isinstance(args[0], Variable)
|
|
19
|
+
self.__term_init_2(*args)
|
|
20
|
+
else:
|
|
21
|
+
assert isinstance(args[0], constants.NUMBER)
|
|
22
|
+
assert isinstance(args[1], Variable)
|
|
23
|
+
self.__term_init_1(*args)
|
|
24
|
+
|
|
25
|
+
def __term_init_1(self, coeff: typing.Union[int, float], var: Variable) -> None:
|
|
26
|
+
self.var: Variable = var
|
|
27
|
+
self.coeff: float = coeff
|
|
28
|
+
|
|
29
|
+
def __term_init_2(self, var: Variable) -> None:
|
|
30
|
+
self.__term_init_1(1.0, var)
|
|
31
|
+
|
|
32
|
+
def clone(self) -> typing.Self:
|
|
33
|
+
return Term(self.coeff, self.var)
|
|
34
|
+
|
|
35
|
+
def get_var(self) -> Variable:
|
|
36
|
+
return self.var
|
|
37
|
+
|
|
38
|
+
def get_coeff(self) -> float:
|
|
39
|
+
return self.coeff
|
|
40
|
+
|
|
41
|
+
def clone(self) -> typing.Self:
|
|
42
|
+
return Term(self.coeff, self.var)
|
|
43
|
+
|
|
44
|
+
def __neg__(self) -> typing.Self:
|
|
45
|
+
return Term(-self.coeff, self.var)
|
|
46
|
+
|
|
47
|
+
def __add__(self, term: typing.Self) -> typing.Self:
|
|
48
|
+
if self.var != term.var:
|
|
49
|
+
raise ValueError("Cannot add terms with different variables")
|
|
50
|
+
return Term(self.coeff + term.coeff, self.var)
|
|
51
|
+
|
|
52
|
+
def __sub__(self, term: typing.Self) -> typing.Self:
|
|
53
|
+
return self + (-term)
|
|
54
|
+
|
|
55
|
+
def __mul__(self, scalar: float) -> typing.Self:
|
|
56
|
+
return Term(self.coeff * scalar, self.var)
|
|
57
|
+
|
|
58
|
+
def __rmul__(self, scalar: float) -> typing.Self:
|
|
59
|
+
return self * scalar
|
|
60
|
+
|
|
61
|
+
def __truediv__(self, scalar: float) -> typing.Self:
|
|
62
|
+
return self * (1 / scalar)
|
|
63
|
+
|
|
64
|
+
def __eq__(self, term: typing.Self) -> bool:
|
|
65
|
+
if not isinstance(term, Term):
|
|
66
|
+
return False
|
|
67
|
+
return self.var == term.var
|
|
68
|
+
|
|
69
|
+
def __ne__(self, term: typing.Self) -> bool:
|
|
70
|
+
return not (self == term)
|
|
71
|
+
|
|
72
|
+
def __repr__(self) -> str:
|
|
73
|
+
return str(self)
|
|
74
|
+
|
|
75
|
+
def __str__(self) -> str:
|
|
76
|
+
return f"{self.coeff} * {self.var}"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import VariableType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Variable:
|
|
7
|
+
VARIABLE_NAME: str = "y"
|
|
8
|
+
VARIABLE_NUMBER: int = 0
|
|
9
|
+
|
|
10
|
+
def __init__(self, name: str, v_type: VariableType) -> None:
|
|
11
|
+
self.lower_bound: float = 0.0
|
|
12
|
+
self.upper_bound: float = 0.0
|
|
13
|
+
self.name: str = name
|
|
14
|
+
self.type: VariableType = None
|
|
15
|
+
self.datatype_filler: bool = False
|
|
16
|
+
self.set_type(v_type)
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def get_binary_variable(name: str) -> typing.Self:
|
|
20
|
+
return Variable(name, VariableType.BINARY)
|
|
21
|
+
|
|
22
|
+
@staticmethod
|
|
23
|
+
def get_continuous_variable(name: str) -> typing.Self:
|
|
24
|
+
return Variable(name, VariableType.CONTINUOUS)
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def get_semi_continuous_variable(name: str) -> typing.Self:
|
|
28
|
+
return Variable(name, VariableType.SEMI_CONTINUOUS)
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
def get_integer_variable(name: str) -> typing.Self:
|
|
32
|
+
return Variable(name, VariableType.INTEGER)
|
|
33
|
+
|
|
34
|
+
def get_lower_bound(self) -> float:
|
|
35
|
+
return self.lower_bound
|
|
36
|
+
|
|
37
|
+
def get_type(self) -> VariableType:
|
|
38
|
+
return self.type
|
|
39
|
+
|
|
40
|
+
def get_datatype_filler_type(self) -> bool:
|
|
41
|
+
return self.datatype_filler
|
|
42
|
+
|
|
43
|
+
def get_upper_bound(self) -> float:
|
|
44
|
+
return self.upper_bound
|
|
45
|
+
|
|
46
|
+
def set_binary_variable(self) -> None:
|
|
47
|
+
self.set_type(VariableType.BINARY)
|
|
48
|
+
|
|
49
|
+
def set_datatype_filler_variable(self) -> None:
|
|
50
|
+
self.datatype_filler = True
|
|
51
|
+
|
|
52
|
+
def set_name(self, name: str) -> None:
|
|
53
|
+
self.name = name
|
|
54
|
+
|
|
55
|
+
def set_type(self, v_type: VariableType) -> None:
|
|
56
|
+
if v_type in (VariableType.BINARY, VariableType.SEMI_CONTINUOUS):
|
|
57
|
+
self.lower_bound = 0.0
|
|
58
|
+
self.upper_bound = 1.0
|
|
59
|
+
else:
|
|
60
|
+
assert v_type in (VariableType.CONTINUOUS, VariableType.INTEGER)
|
|
61
|
+
self.lower_bound = float("-inf")
|
|
62
|
+
self.upper_bound = float("inf")
|
|
63
|
+
self.type = v_type
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def get_new_variable(v_type: VariableType) -> typing.Self:
|
|
67
|
+
Variable.VARIABLE_NUMBER += 1
|
|
68
|
+
return Variable(f"{Variable.VARIABLE_NAME}{Variable.VARIABLE_NUMBER}", v_type)
|
|
69
|
+
|
|
70
|
+
def clone(self) -> typing.Self:
|
|
71
|
+
return Variable(self.name, self.type)
|
|
72
|
+
|
|
73
|
+
def __eq__(self, value: typing.Self) -> bool:
|
|
74
|
+
return str(self) == str(value)
|
|
75
|
+
|
|
76
|
+
def __ne__(self, value: object) -> bool:
|
|
77
|
+
return not (self == value)
|
|
78
|
+
|
|
79
|
+
def __repr__(self) -> str:
|
|
80
|
+
return str(self)
|
|
81
|
+
|
|
82
|
+
def __str__(self) -> str:
|
|
83
|
+
return self.name
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
BinaryVar = Variable.get_binary_variable
|
|
87
|
+
IntegerVar = Variable.get_integer_variable
|
|
88
|
+
UpVar = Variable.get_semi_continuous_variable
|
|
89
|
+
FreeVar = Variable.get_continuous_variable
|
|
@@ -0,0 +1,76 @@
|
|
|
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.modified.linearly_modified_concept import (
|
|
7
|
+
LinearlyModifiedConcept,
|
|
8
|
+
)
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.modifier.modifier import Modifier
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LinearModifier(Modifier):
|
|
14
|
+
|
|
15
|
+
def __init__(self, name: str, c: float) -> None:
|
|
16
|
+
super().__init__(name)
|
|
17
|
+
self._c: float = c
|
|
18
|
+
self._a: float = c / (c + 1.0)
|
|
19
|
+
self._b: float = 1.0 / (c + 1.0)
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def a(self) -> float:
|
|
23
|
+
return self._a
|
|
24
|
+
|
|
25
|
+
@a.setter
|
|
26
|
+
def a(self, value: float) -> None:
|
|
27
|
+
self._a = value
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def b(self) -> float:
|
|
31
|
+
return self._b
|
|
32
|
+
|
|
33
|
+
@b.setter
|
|
34
|
+
def b(self, value: float) -> None:
|
|
35
|
+
self._b = value
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def c(self) -> float:
|
|
39
|
+
return self._c
|
|
40
|
+
|
|
41
|
+
@c.setter
|
|
42
|
+
def c(self, value: float) -> None:
|
|
43
|
+
self._c = value
|
|
44
|
+
|
|
45
|
+
def clone(self) -> typing.Self:
|
|
46
|
+
return LinearModifier(self.name, self.c)
|
|
47
|
+
|
|
48
|
+
def modify(self, concept: Concept) -> LinearlyModifiedConcept:
|
|
49
|
+
return LinearlyModifiedConcept(concept, self)
|
|
50
|
+
|
|
51
|
+
def compute_name(self) -> str:
|
|
52
|
+
return f"linear-modifier({self.c})"
|
|
53
|
+
|
|
54
|
+
def get_membership_degree(self, value: float) -> float:
|
|
55
|
+
if value <= 0.0:
|
|
56
|
+
return 0.0
|
|
57
|
+
if value >= 1.0:
|
|
58
|
+
return 1.0
|
|
59
|
+
if value <= self.a:
|
|
60
|
+
return self.b / self.a * value
|
|
61
|
+
return (value * (1.0 - self.b) + self.b - self.a) / (1.0 - self.a)
|
|
62
|
+
|
|
63
|
+
def __neg__(self) -> Concept:
|
|
64
|
+
return OperatorConcept.not_(self)
|
|
65
|
+
|
|
66
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
67
|
+
return OperatorConcept.and_(self, value)
|
|
68
|
+
|
|
69
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
70
|
+
return OperatorConcept.or_(self, value)
|
|
71
|
+
|
|
72
|
+
def __hash__(self) -> int:
|
|
73
|
+
return hash(str(self))
|
|
74
|
+
|
|
75
|
+
# def __str__(self) -> str:
|
|
76
|
+
# return self.compute_name()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Modifier(ABC):
|
|
10
|
+
|
|
11
|
+
def __init__(self, name: str) -> None:
|
|
12
|
+
self.name: str = name
|
|
13
|
+
|
|
14
|
+
def set_name(self, name: str) -> None:
|
|
15
|
+
self.name = name
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def compute_name(self) -> str:
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def clone(self) -> typing.Self:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def modify(self, concept: Concept) -> Concept:
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
@abstractmethod
|
|
30
|
+
def get_membership_degree(self, value: float) -> float:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
def __repr__(self) -> str:
|
|
34
|
+
return str(self)
|
|
35
|
+
|
|
36
|
+
def __str__(self) -> str:
|
|
37
|
+
if self.name is None:
|
|
38
|
+
self.name = self.compute_name()
|
|
39
|
+
return self.name
|
|
@@ -0,0 +1,76 @@
|
|
|
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.modified.triangularly_modified_concept import (
|
|
7
|
+
TriangularlyModifiedConcept,
|
|
8
|
+
)
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.modifier.modifier import Modifier
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TriangularModifier(Modifier):
|
|
15
|
+
def __init__(self, name: str, a: float, b: float, c: float) -> None:
|
|
16
|
+
super().__init__(name)
|
|
17
|
+
if a > b or b > c:
|
|
18
|
+
Util.error(f"Error: Triangular functions require {a} <= {b} <= {c}")
|
|
19
|
+
self._a = a
|
|
20
|
+
self._b = b
|
|
21
|
+
self._c = c
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def a(self) -> float:
|
|
25
|
+
return self._a
|
|
26
|
+
|
|
27
|
+
@a.setter
|
|
28
|
+
def a(self, value: float) -> None:
|
|
29
|
+
self._a = value
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def b(self) -> float:
|
|
33
|
+
return self._b
|
|
34
|
+
|
|
35
|
+
@b.setter
|
|
36
|
+
def b(self, value: float) -> None:
|
|
37
|
+
self._b = value
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def c(self) -> float:
|
|
41
|
+
return self._c
|
|
42
|
+
|
|
43
|
+
@c.setter
|
|
44
|
+
def c(self, value: float) -> None:
|
|
45
|
+
self._c = value
|
|
46
|
+
|
|
47
|
+
def clone(self) -> typing.Self:
|
|
48
|
+
return TriangularModifier(self.name, self.c)
|
|
49
|
+
|
|
50
|
+
def compute_name(self) -> str:
|
|
51
|
+
return f"triangular-modifier({self.a}, {self.b}, {self.c})"
|
|
52
|
+
|
|
53
|
+
def get_membership_degree(self, x: float) -> float:
|
|
54
|
+
if x <= self.a or x >= self.c:
|
|
55
|
+
return 0.0
|
|
56
|
+
if x <= self.b:
|
|
57
|
+
return (x - self.a) / (self.b - self.a)
|
|
58
|
+
return (self.c - x) / (self.c - self.b)
|
|
59
|
+
|
|
60
|
+
def modify(self, concept: Concept) -> Concept:
|
|
61
|
+
return TriangularlyModifiedConcept(concept, self)
|
|
62
|
+
|
|
63
|
+
def __neg__(self) -> Concept:
|
|
64
|
+
return OperatorConcept.not_(self)
|
|
65
|
+
|
|
66
|
+
def __and__(self, value: typing.Self) -> typing.Self:
|
|
67
|
+
return OperatorConcept.and_(self, value)
|
|
68
|
+
|
|
69
|
+
def __or__(self, value: typing.Self) -> typing.Self:
|
|
70
|
+
return OperatorConcept.or_(self, value)
|
|
71
|
+
|
|
72
|
+
def __hash__(self) -> int:
|
|
73
|
+
return hash(str(self))
|
|
74
|
+
|
|
75
|
+
# def __str__(self) -> str:
|
|
76
|
+
# return self.get_name()
|