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,290 @@
|
|
|
1
|
+
|
|
2
|
+
identifier : /[a-zA-Z_][a-zA-Z0-9_\-']*/
|
|
3
|
+
string : ESCAPED_STRING | identifier
|
|
4
|
+
number : SIGNED_NUMBER
|
|
5
|
+
|
|
6
|
+
sub : "-"
|
|
7
|
+
sum : "+"
|
|
8
|
+
?mul : /\*/
|
|
9
|
+
?left_par : "("
|
|
10
|
+
?right_par : ")"
|
|
11
|
+
?left_square_par : "["
|
|
12
|
+
?right_square_par : "]"
|
|
13
|
+
?comma : ","
|
|
14
|
+
|
|
15
|
+
# CONSTANTS
|
|
16
|
+
|
|
17
|
+
GREATER_THAN.3 : ">="
|
|
18
|
+
LOWER_THAN.3 : "<="
|
|
19
|
+
EQUAL_TO.2 : "="
|
|
20
|
+
|
|
21
|
+
TOP.2 : "*top*"i
|
|
22
|
+
BOTTOM.2 : "*bottom*"i
|
|
23
|
+
AND.2 : "and"i
|
|
24
|
+
G_AND.3 : "g-and"i
|
|
25
|
+
L_AND.3 : "l-and"i
|
|
26
|
+
OR.2 : "or"i
|
|
27
|
+
G_OR.3 : "g-or"i
|
|
28
|
+
L_OR.3 : "l-or"i
|
|
29
|
+
NOT.2 : "not"i
|
|
30
|
+
IMPLIES.2 : "implies"i
|
|
31
|
+
G_IMPLIES.3 : "g-implies"i
|
|
32
|
+
L_IMPLIES.3 : "l-implies"i
|
|
33
|
+
KD_IMPLIES.3 : "kd-implies"i
|
|
34
|
+
Z_IMPLIES.3 : "z-implies"i
|
|
35
|
+
ALL.2 : "all"i
|
|
36
|
+
SOME.2 : "some"i
|
|
37
|
+
HAS_VALUE.3 : "b-some"i
|
|
38
|
+
UPPER_APPROXIMATION.2 : "ua"i
|
|
39
|
+
TIGHT_UPPER_APPROXIMATION.3 : "tua"i
|
|
40
|
+
LOOSE_UPPER_APPROXIMATION.3 : "lua"i
|
|
41
|
+
LOWER_APPROXIMATION.2 : "la"i
|
|
42
|
+
TIGHT_LOWER_APPROXIMATION.3 : "tla"i
|
|
43
|
+
LOOSE_LOWER_APPROXIMATION.3 : "lla"i
|
|
44
|
+
SELF.2 : "self"i
|
|
45
|
+
W_SUM_ZERO.3 : "w-sum-zero"i
|
|
46
|
+
W_SUM.2 : "w-sum"i
|
|
47
|
+
W_MAX.2 : "w-max"i
|
|
48
|
+
W_MIN.2 : "w-min"i
|
|
49
|
+
OWA.2 : "owa"i
|
|
50
|
+
QOWA.2 : "q-owa"i
|
|
51
|
+
CHOQUET_INTEGRAL.2 : "choquet"i
|
|
52
|
+
Q_SUGENO_INTEGRAL.3 : "q-sugeno"i
|
|
53
|
+
SUGENO_INTEGRAL.2 : "sugeno"i
|
|
54
|
+
LINEAR_MODIFIER.2 : "linear-modifier"i
|
|
55
|
+
TRIANGULAR_MODIFIER.2 : "triangular-modifier"i
|
|
56
|
+
CRISP_FN.2 : "crisp"i
|
|
57
|
+
LEFT_FN.2 : "left-shoulder"i
|
|
58
|
+
RIGHT_FN.2 : "right-shoulder"i
|
|
59
|
+
TRIANGULAR_FN.2 : "triangular"i
|
|
60
|
+
TRAPEZOIDAL_FN.2 : "trapezoidal"i
|
|
61
|
+
LINEAR_FN.2 : "linear"i
|
|
62
|
+
MODIFIED_FN.2 : "modified"i
|
|
63
|
+
FEATURE_SUM.2 : "f+"i
|
|
64
|
+
FEATURE_MUL.2 : "f*"i
|
|
65
|
+
FEATURE_SUB.2 : "f-"i
|
|
66
|
+
FEATURE_DIV.2 : "f/"i
|
|
67
|
+
RANGE.2 : "range"i
|
|
68
|
+
DOMAIN.2 : "domain"i
|
|
69
|
+
INTEGER_ROLE.2 : "*integer*"i
|
|
70
|
+
REAL_ROLE.2 : "*real*"i
|
|
71
|
+
STRING_ROLE.2 : "*string*"i
|
|
72
|
+
BOOLEAN_ROLE.2 : "*boolean*"i
|
|
73
|
+
BINARY_VAR.2 : "binary"i
|
|
74
|
+
FREE_VAR.2 : "free"i
|
|
75
|
+
|
|
76
|
+
DEFINE_FUZZY_LOGIC.2 : "define-fuzzy-logic"i
|
|
77
|
+
DEFINE_MODIFIER.2 : "define-modifier"i
|
|
78
|
+
DEFINE_TRUTH_CONSTANT.2 : "define-truth-constant"i
|
|
79
|
+
DEFINE_FUZZY_CONCEPT.2 : "define-fuzzy-concept"i
|
|
80
|
+
DEFINE_FUZZY_NUMBER_RANGE.3 : "define-fuzzy-number-range"i
|
|
81
|
+
DEFINE_FUZZY_NUMBER.2 : "define-fuzzy-number"i
|
|
82
|
+
DEFINE_FUZZY_SIMILARITY.2 : "define-fuzzy-similarity"i
|
|
83
|
+
DEFINE_FUZZY_EQUIVALENCE.2 : "define-fuzzy-equivalence"i
|
|
84
|
+
DEFINE_ROLE.2 : "functional"i
|
|
85
|
+
|
|
86
|
+
SHOW_CONCRETE_FILLERS.2 : "show-concrete-fillers"i
|
|
87
|
+
SHOW_CONCRETE_FILLERS_FOR.3 : "show-concrete-fillers-for"i
|
|
88
|
+
SHOW_CONCRETE_INSTANCE_FOR.2 : "show-concrete-instance-for"i
|
|
89
|
+
SHOW_ABSTRACT_FILLERS.2 : "show-abstract-fillers"i
|
|
90
|
+
SHOW_ABSTRACT_FILLERS_FOR.3 : "show-abstract-fillers-for"i
|
|
91
|
+
SHOW_CONCEPTS.2 : "show-concepts"i
|
|
92
|
+
SHOW_INSTANCES.2 : "show-instances"i
|
|
93
|
+
SHOW_VARIABLES.2 : "show-variables"i
|
|
94
|
+
SHOW_LANGUAGE.2 : "show-language"i
|
|
95
|
+
|
|
96
|
+
CRISP_CONCEPT.2 : "crisp-concept"i
|
|
97
|
+
CRISP_ROLE.2 : "crisp-role"i
|
|
98
|
+
|
|
99
|
+
AXIOM_DEF_CONCEPT.2 : "define-concept"i
|
|
100
|
+
AXIOM_DEF_PRIMITIVE_CONCEPT.2 : "define-primitive-concept"i
|
|
101
|
+
AXIOM_INSTANCE.2 : "instance"i
|
|
102
|
+
AXIOM_RELATED.2 : "related"i
|
|
103
|
+
AXIOM_IMPLIES.2 : "implies"i
|
|
104
|
+
AXIOM_G_IMPLIES.2 : "g-implies"i
|
|
105
|
+
AXIOM_L_IMPLIES.2 : "l-implies"i
|
|
106
|
+
AXIOM_KD_IMPLIES.2 : "kd-implies"i
|
|
107
|
+
AXIOM_Z_IMPLIES.2 : "z-implies"i
|
|
108
|
+
AXIOM_IMPLIES_ROLE.2 : "implies-role"i
|
|
109
|
+
AXIOM_EQ_CONCEPTS.2 : "equivalent-concepts"i
|
|
110
|
+
AXIOM_DISJOINT_UNION.3 : "disjoint-union"i
|
|
111
|
+
AXIOM_DISJOINT.2 : "disjoint"i
|
|
112
|
+
AXIOM_INV_FUNCTIONAL_ROLE.2 : "inverse-functional"i
|
|
113
|
+
AXIOM_FUNCTIONAL_ROLE.2 : "functional"i
|
|
114
|
+
AXIOM_TRANSITIVE_ROLE.2 : "transitive"i
|
|
115
|
+
AXIOM_SYMMETRIC_ROLE.2 : "symmetric"i
|
|
116
|
+
AXIOM_REFLEXIVE_ROLE.2 : "reflexive"i
|
|
117
|
+
AXIOM_INV_ROLE.2 : "inverse"i
|
|
118
|
+
|
|
119
|
+
MAX_INSTANCE_QUERY.2 : "max-instance?"i
|
|
120
|
+
MIN_INSTANCE_QUERY.2 : "min-instance?"i
|
|
121
|
+
ALL_INSTANCES_QUERY.2 : "all-instances?"i
|
|
122
|
+
MAX_RELATED_QUERY.2 : "max-related?"i
|
|
123
|
+
MIN_RELATED_QUERY.2 : "min-related?"i
|
|
124
|
+
MAX_SUBS_QUERY.2 : "max-subs?"i
|
|
125
|
+
MAX_G_SUBS_QUERY.2 : "max-g-subs?"i
|
|
126
|
+
MAX_L_SUBS_QUERY.2 : "max-l-subs?"i
|
|
127
|
+
MAX_KD_SUBS_QUERY.2 : "max-kd-subs?"i
|
|
128
|
+
MIN_SUBS_QUERY.2 : "min-subs?"i
|
|
129
|
+
MIN_G_SUBS_QUERY.2 : "min-g-subs?"i
|
|
130
|
+
MIN_L_SUBS_QUERY.2 : "min-l-subs?"i
|
|
131
|
+
MIN_KD_SUBS_QUERY.2 : "min-kd-subs?"i
|
|
132
|
+
MAX_SAT_QUERY.2 : "max-sat?"i
|
|
133
|
+
MIN_SAT_QUERY.2 : "min-sat?"i
|
|
134
|
+
MAX_VAR_QUERY.2 : "max-var?"i
|
|
135
|
+
MIN_VAR_QUERY.2 : "min-var?"i
|
|
136
|
+
SAT_QUERY.2 : "sat?"i
|
|
137
|
+
DEFUZZIFY_LOM_QUERY.2 : "defuzzify-lom?"i
|
|
138
|
+
DEFUZZIFY_SOM_QUERY.2 : "defuzzify-som?"i
|
|
139
|
+
DEFUZZIFY_MOM_QUERY.2 : "defuzzify-mom?"i
|
|
140
|
+
BNP_QUERY.2 : "bnp?"i
|
|
141
|
+
|
|
142
|
+
?start : comment
|
|
143
|
+
| fuzzy_logic
|
|
144
|
+
| truth_constants
|
|
145
|
+
| modifier
|
|
146
|
+
| fuzzy_concept
|
|
147
|
+
| fuzzy_number_range
|
|
148
|
+
| fuzzy_number
|
|
149
|
+
| feature
|
|
150
|
+
| constraints
|
|
151
|
+
| show_statement
|
|
152
|
+
| crisp_declarations
|
|
153
|
+
| concept
|
|
154
|
+
| fuzzy_similarity
|
|
155
|
+
| fuzzy_equivalence
|
|
156
|
+
| axiom
|
|
157
|
+
| query
|
|
158
|
+
|
|
159
|
+
logic : "lukasiewicz"i | "zadeh"i | "classical"i
|
|
160
|
+
fuzzy_logic : left_par DEFINE_FUZZY_LOGIC logic right_par
|
|
161
|
+
comment : /[#%]/ /[^\n]+/
|
|
162
|
+
binary_op : AND
|
|
163
|
+
| G_AND
|
|
164
|
+
| L_AND
|
|
165
|
+
| OR
|
|
166
|
+
| L_OR
|
|
167
|
+
| G_OR
|
|
168
|
+
| IMPLIES
|
|
169
|
+
| G_IMPLIES
|
|
170
|
+
| L_IMPLIES
|
|
171
|
+
| KD_IMPLIES
|
|
172
|
+
| Z_IMPLIES
|
|
173
|
+
approx_or_restrict : ALL
|
|
174
|
+
| SOME
|
|
175
|
+
| UPPER_APPROXIMATION
|
|
176
|
+
| TIGHT_UPPER_APPROXIMATION
|
|
177
|
+
| LOOSE_UPPER_APPROXIMATION
|
|
178
|
+
| LOWER_APPROXIMATION
|
|
179
|
+
| TIGHT_LOWER_APPROXIMATION
|
|
180
|
+
| LOOSE_LOWER_APPROXIMATION
|
|
181
|
+
weighted_type : W_SUM_ZERO
|
|
182
|
+
| W_SUM
|
|
183
|
+
| W_MAX
|
|
184
|
+
| W_MIN
|
|
185
|
+
integral_type : OWA
|
|
186
|
+
| CHOQUET_INTEGRAL
|
|
187
|
+
| Q_SUGENO_INTEGRAL
|
|
188
|
+
| SUGENO_INTEGRAL
|
|
189
|
+
weighted_concept_simple : left_par number concept right_par -> weighted_concept_simple
|
|
190
|
+
concept : TOP
|
|
191
|
+
| BOTTOM
|
|
192
|
+
| string -> to_concept
|
|
193
|
+
| datatype_restriction
|
|
194
|
+
| left_par binary_op concept concept+ right_par -> binary_concept
|
|
195
|
+
| left_par approx_or_restrict string concept right_par -> binary_concept
|
|
196
|
+
| left_par SOME string (string | concept) right_par -> binary_concept
|
|
197
|
+
| left_par HAS_VALUE string string right_par -> binary_concept
|
|
198
|
+
| left_par NOT concept right_par -> unary_concept
|
|
199
|
+
| left_par SELF string right_par -> unary_concept
|
|
200
|
+
| left_par string concept right_par -> modifier_concept
|
|
201
|
+
| left_par left_square_par (GREATER_THAN | LOWER_THAN) (string | number) right_square_par concept right_par -> threshold_concept
|
|
202
|
+
| left_par weighted_type (weighted_concept_simple)+ right_par -> weighted_concept
|
|
203
|
+
| left_par QOWA string (concept+) right_par -> q_owa_concept
|
|
204
|
+
| left_par integral_type left_par (number)+ right_par left_par (concept+) right_par right_par -> owa_integral_concept
|
|
205
|
+
linear_mod : LINEAR_MODIFIER left_par number right_par
|
|
206
|
+
triangular_mod : TRIANGULAR_MODIFIER left_par number comma number comma number right_par
|
|
207
|
+
modifier : left_par DEFINE_MODIFIER string (linear_mod | triangular_mod) right_par
|
|
208
|
+
truth_constants : left_par DEFINE_TRUTH_CONSTANT string number right_par
|
|
209
|
+
fuzzy_concept : left_par DEFINE_FUZZY_CONCEPT string (CRISP_FN left_par number ((comma number) ~ 3) right_par
|
|
210
|
+
| LEFT_FN left_par number ((comma number) ~ 3) right_par
|
|
211
|
+
| RIGHT_FN left_par number ((comma number) ~ 3) right_par
|
|
212
|
+
| TRIANGULAR_FN left_par number ((comma number) ~ 4) right_par
|
|
213
|
+
| TRAPEZOIDAL_FN left_par number ((comma number) ~ 5) right_par
|
|
214
|
+
| LINEAR_FN left_par number ((comma number) ~ 3) right_par
|
|
215
|
+
| MODIFIED_FN left_par string comma string right_par) right_par
|
|
216
|
+
fuzzy_number_range : left_par DEFINE_FUZZY_NUMBER_RANGE number number right_par
|
|
217
|
+
simple_fuzzy_number : string
|
|
218
|
+
| number
|
|
219
|
+
| left_par number (comma number ~ 2) right_par
|
|
220
|
+
fuzzy_number : left_par DEFINE_FUZZY_NUMBER string (simple_fuzzy_number
|
|
221
|
+
| left_par (FEATURE_SUM | FEATURE_MUL) (fuzzy_number+) right_par
|
|
222
|
+
| left_par (FEATURE_SUB | FEATURE_DIV) (fuzzy_number ~ 2) right_par) right_par
|
|
223
|
+
feature : left_par (DEFINE_ROLE string
|
|
224
|
+
| RANGE string (INTEGER_ROLE | REAL_ROLE) (number ~ 2)
|
|
225
|
+
| RANGE string (STRING_ROLE | BOOLEAN_ROLE)) right_par
|
|
226
|
+
datatype_restriction_function : string -> restrictions
|
|
227
|
+
| number -> restrictions
|
|
228
|
+
| number (mul)? string -> restrictions
|
|
229
|
+
| string sub string -> restrictions
|
|
230
|
+
| (string sum)+ string -> restrictions
|
|
231
|
+
datatype_restriction.3 : left_par (GREATER_THAN | LOWER_THAN | EQUAL_TO) string (string
|
|
232
|
+
| datatype_restriction_function
|
|
233
|
+
| fuzzy_number) right_par
|
|
234
|
+
term : number (mul)? string
|
|
235
|
+
expression : term (sum term)*
|
|
236
|
+
inequality : expression (GREATER_THAN | LOWER_THAN | EQUAL_TO) number
|
|
237
|
+
constraints : left_par (inequality | BINARY_VAR string | FREE_VAR string) right_par
|
|
238
|
+
show_statement : left_par (SHOW_CONCRETE_FILLERS (string+)
|
|
239
|
+
| SHOW_CONCRETE_FILLERS_FOR string (string+)
|
|
240
|
+
| SHOW_CONCRETE_INSTANCE_FOR (string ~ 2) (string+)
|
|
241
|
+
| SHOW_ABSTRACT_FILLERS (string+)
|
|
242
|
+
| SHOW_ABSTRACT_FILLERS_FOR string (string+)
|
|
243
|
+
| SHOW_CONCEPTS (string+)
|
|
244
|
+
| SHOW_INSTANCES (concept+)
|
|
245
|
+
| SHOW_VARIABLES (string+)
|
|
246
|
+
| SHOW_LANGUAGE) right_par
|
|
247
|
+
crisp_declarations : left_par (CRISP_CONCEPT | CRISP_ROLE) (string)+ right_par
|
|
248
|
+
fuzzy_similarity : left_par DEFINE_FUZZY_SIMILARITY string right_par
|
|
249
|
+
fuzzy_equivalence : left_par DEFINE_FUZZY_EQUIVALENCE string right_par
|
|
250
|
+
degree : number | expression | string
|
|
251
|
+
axiom : left_par (AXIOM_INSTANCE string concept (degree)?
|
|
252
|
+
| AXIOM_RELATED (string ~ 3) (degree)?
|
|
253
|
+
| AXIOM_IMPLIES_ROLE (string ~ 2) (number)?
|
|
254
|
+
| AXIOM_Z_IMPLIES (concept ~ 2)
|
|
255
|
+
| (AXIOM_IMPLIES
|
|
256
|
+
| AXIOM_G_IMPLIES
|
|
257
|
+
| AXIOM_KD_IMPLIES
|
|
258
|
+
| AXIOM_L_IMPLIES) (concept ~ 2) (degree)?
|
|
259
|
+
| AXIOM_DEF_CONCEPT string concept
|
|
260
|
+
| AXIOM_DEF_PRIMITIVE_CONCEPT string concept
|
|
261
|
+
| AXIOM_EQ_CONCEPTS (concept ~ 2)
|
|
262
|
+
| (AXIOM_DISJOINT | AXIOM_DISJOINT_UNION) (concept+)
|
|
263
|
+
| (RANGE | DOMAIN) string concept
|
|
264
|
+
| (AXIOM_INV_FUNCTIONAL_ROLE
|
|
265
|
+
| AXIOM_FUNCTIONAL_ROLE
|
|
266
|
+
| AXIOM_SYMMETRIC_ROLE
|
|
267
|
+
| AXIOM_REFLEXIVE_ROLE
|
|
268
|
+
| AXIOM_TRANSITIVE_ROLE) string
|
|
269
|
+
| AXIOM_INV_ROLE (string ~ 2)) right_par
|
|
270
|
+
query : left_par (SAT_QUERY
|
|
271
|
+
| (MAX_INSTANCE_QUERY | MIN_INSTANCE_QUERY) string concept
|
|
272
|
+
| ALL_INSTANCES_QUERY concept
|
|
273
|
+
| (MAX_RELATED_QUERY | MIN_RELATED_QUERY) (string ~ 3)
|
|
274
|
+
| (MAX_SUBS_QUERY
|
|
275
|
+
| MAX_G_SUBS_QUERY
|
|
276
|
+
| MAX_L_SUBS_QUERY
|
|
277
|
+
| MAX_KD_SUBS_QUERY
|
|
278
|
+
| MIN_SUBS_QUERY
|
|
279
|
+
| MIN_G_SUBS_QUERY
|
|
280
|
+
| MIN_L_SUBS_QUERY
|
|
281
|
+
| MIN_KD_SUBS_QUERY) (concept ~ 2)
|
|
282
|
+
| (MAX_SAT_QUERY | MIN_SAT_QUERY) concept (string)?
|
|
283
|
+
| (MAX_VAR_QUERY | MIN_VAR_QUERY) expression
|
|
284
|
+
| (DEFUZZIFY_LOM_QUERY | DEFUZZIFY_SOM_QUERY | DEFUZZIFY_MOM_QUERY) concept (string ~ 2)
|
|
285
|
+
| BNP_QUERY fuzzy_number) right_par
|
|
286
|
+
|
|
287
|
+
%import common.ESCAPED_STRING
|
|
288
|
+
%import common.SIGNED_NUMBER
|
|
289
|
+
%import common.WS
|
|
290
|
+
%ignore WS
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from lark import Lark, Transformer, v_args
|
|
2
|
+
|
|
3
|
+
calc_grammar = """
|
|
4
|
+
?start: sum
|
|
5
|
+
| NAME "=" sum -> assign_var
|
|
6
|
+
|
|
7
|
+
?sum: product
|
|
8
|
+
| sum "+" product -> add
|
|
9
|
+
| sum "-" product -> sub
|
|
10
|
+
|
|
11
|
+
?product: atom
|
|
12
|
+
| product "*" atom -> mul
|
|
13
|
+
| product "/" atom -> div
|
|
14
|
+
|
|
15
|
+
?atom: NUMBER -> number
|
|
16
|
+
| "-" atom -> neg
|
|
17
|
+
| NAME -> var
|
|
18
|
+
| "(" sum ")"
|
|
19
|
+
|
|
20
|
+
%import common.CNAME -> NAME
|
|
21
|
+
%import common.NUMBER
|
|
22
|
+
%import common.WS_INLINE
|
|
23
|
+
|
|
24
|
+
%ignore WS_INLINE
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@v_args(inline=True) # Affects the signatures of the methods
|
|
29
|
+
class CalculateTree(Transformer):
|
|
30
|
+
from operator import add, mul, neg, sub
|
|
31
|
+
from operator import truediv as div
|
|
32
|
+
|
|
33
|
+
number = float
|
|
34
|
+
|
|
35
|
+
def __init__(self):
|
|
36
|
+
self.vars = {}
|
|
37
|
+
|
|
38
|
+
def assign_var(self, name, value):
|
|
39
|
+
print(name, value)
|
|
40
|
+
self.vars[name] = value
|
|
41
|
+
return value
|
|
42
|
+
|
|
43
|
+
def var(self, name):
|
|
44
|
+
try:
|
|
45
|
+
return self.vars[name]
|
|
46
|
+
except KeyError:
|
|
47
|
+
raise Exception("Variable not found: %s" % name)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
calc_parser = Lark(calc_grammar, parser="lalr", transformer=CalculateTree())
|
|
51
|
+
calc = calc_parser.parse
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def main():
|
|
55
|
+
while True:
|
|
56
|
+
try:
|
|
57
|
+
s = input("> ")
|
|
58
|
+
except EOFError:
|
|
59
|
+
break
|
|
60
|
+
print(calc(s))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test():
|
|
64
|
+
print(calc("a = 1+2"))
|
|
65
|
+
print(calc("1+a*-3"))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
# test()
|
|
70
|
+
main()
|
|
@@ -0,0 +1,81 @@
|
|
|
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.util.constants import LogicOperatorType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PrimitiveConceptDefinition:
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
defined: str,
|
|
14
|
+
definition: Concept,
|
|
15
|
+
implication: LogicOperatorType,
|
|
16
|
+
degree: float,
|
|
17
|
+
) -> None:
|
|
18
|
+
self.defined: str = defined
|
|
19
|
+
self.definition: Concept = definition
|
|
20
|
+
self.degree: float = degree
|
|
21
|
+
self.implication: LogicOperatorType = implication
|
|
22
|
+
|
|
23
|
+
def clone(self) -> typing.Self:
|
|
24
|
+
return PrimitiveConceptDefinition(
|
|
25
|
+
self.defined, self.definition, self.implication, self.degree
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def get_defined_concept(self) -> str:
|
|
29
|
+
return self.defined
|
|
30
|
+
|
|
31
|
+
def get_definition(self) -> Concept:
|
|
32
|
+
return self.definition
|
|
33
|
+
|
|
34
|
+
def set_definition(self, definition: Concept) -> None:
|
|
35
|
+
self.definition = definition
|
|
36
|
+
|
|
37
|
+
def get_degree(self) -> float:
|
|
38
|
+
return self.degree
|
|
39
|
+
|
|
40
|
+
def set_degree(self, deg: float) -> None:
|
|
41
|
+
self.degree = deg
|
|
42
|
+
|
|
43
|
+
def get_type(self) -> LogicOperatorType:
|
|
44
|
+
return self.implication
|
|
45
|
+
|
|
46
|
+
def __eq__(self, other: typing.Self) -> bool:
|
|
47
|
+
return (
|
|
48
|
+
isinstance(other, PrimitiveConceptDefinition)
|
|
49
|
+
and self.defined == other.defined
|
|
50
|
+
and self.definition == other.definition
|
|
51
|
+
and self.degree == other.degree
|
|
52
|
+
and self.implication == other.implication
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def __ne__(self, other: typing.Self) -> bool:
|
|
56
|
+
return not (self == other)
|
|
57
|
+
|
|
58
|
+
def __lt__(self, other: typing.Self) -> bool:
|
|
59
|
+
return isinstance(other, PrimitiveConceptDefinition) and hash(self) < hash(
|
|
60
|
+
other
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def __le__(self, other: typing.Self) -> bool:
|
|
64
|
+
return not (self > other)
|
|
65
|
+
|
|
66
|
+
def __gt__(self, other: typing.Self) -> bool:
|
|
67
|
+
return isinstance(other, PrimitiveConceptDefinition) and hash(self) > hash(
|
|
68
|
+
other
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def __ge__(self, other: typing.Self) -> bool:
|
|
72
|
+
return not (self < other)
|
|
73
|
+
|
|
74
|
+
def __hash__(self) -> int:
|
|
75
|
+
return hash(str(self))
|
|
76
|
+
|
|
77
|
+
def __repr__(self) -> str:
|
|
78
|
+
return str(self)
|
|
79
|
+
|
|
80
|
+
def __str__(self) -> str:
|
|
81
|
+
return f"{self.defined} =>_{self.implication.name[0]} {self.definition} >= {self.degree}"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .query import Query
|
|
2
|
+
from .bnp_query import BnpQuery
|
|
3
|
+
from .instance_query import InstanceQuery
|
|
4
|
+
from .kb_satisfiable_query import KbSatisfiableQuery
|
|
5
|
+
from .related_query import RelatedQuery
|
|
6
|
+
from .satisfiable_query import SatisfiableQuery
|
|
7
|
+
from .subsumption_query import SubsumptionQuery
|
|
8
|
+
from .all_instances_query import AllInstancesQuery
|
|
9
|
+
|
|
10
|
+
from .max import *
|
|
11
|
+
|
|
12
|
+
from .min import *
|
|
13
|
+
|
|
14
|
+
from .defuzzify import *
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.individual.created_individual import CreatedIndividual
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.query.min.min_instance_query import MinInstanceQuery
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.query.query import Query
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AllInstancesQuery(Query):
|
|
14
|
+
def __init__(self, concept: Concept) -> None:
|
|
15
|
+
if concept.is_concrete():
|
|
16
|
+
Util.error(f"Error: {concept} cannot be a concrete concept.")
|
|
17
|
+
self.conc = concept
|
|
18
|
+
self.degrees: list[float] = []
|
|
19
|
+
self.individuals: list[Individual] = []
|
|
20
|
+
self.name = f"Instances of {self.conc}?"
|
|
21
|
+
|
|
22
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
26
|
+
sol: Solution = None
|
|
27
|
+
self.name: str = ""
|
|
28
|
+
self.individuals: list[Individual] = list(kb.individuals.values())
|
|
29
|
+
|
|
30
|
+
for i in self.individuals:
|
|
31
|
+
if isinstance(i, CreatedIndividual):
|
|
32
|
+
continue
|
|
33
|
+
q: MinInstanceQuery = MinInstanceQuery(self.conc, i)
|
|
34
|
+
sol: Solution = q.solve(kb)
|
|
35
|
+
if sol.is_consistent_kb():
|
|
36
|
+
self.degrees.append(float(sol.get_solution()))
|
|
37
|
+
self.name += f"{q}{sol.get_solution()}"
|
|
38
|
+
continue
|
|
39
|
+
self.name = f"Instances of {self.conc}? Inconsistent KB"
|
|
40
|
+
break
|
|
41
|
+
return sol
|
|
42
|
+
|
|
43
|
+
def get_individuals(self) -> list[Individual]:
|
|
44
|
+
return self.individuals
|
|
45
|
+
|
|
46
|
+
def get_degrees(self) -> list[float]:
|
|
47
|
+
return self.degrees
|
|
48
|
+
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
return self.name
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concrete.fuzzy_number.triangular_fuzzy_number import (
|
|
4
|
+
TriangularFuzzyNumber,
|
|
5
|
+
)
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.query.query import Query
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class BnpQuery(Query):
|
|
12
|
+
def __init__(self, c: TriangularFuzzyNumber) -> None:
|
|
13
|
+
self.c: TriangularFuzzyNumber = c
|
|
14
|
+
|
|
15
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
19
|
+
return Solution(self.c.get_best_non_fuzzy_performance())
|
|
20
|
+
|
|
21
|
+
def __str__(self) -> str:
|
|
22
|
+
return f"Best non-fuzzy performance of {self.c.compute_name()} = "
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typing
|
|
4
|
+
from abc import abstractmethod
|
|
5
|
+
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_numeric import DegreeNumeric
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
9
|
+
InconsistentOntologyException,
|
|
10
|
+
)
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.individual.created_individual import CreatedIndividual
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.milp.milp_helper import MILPHelper
|
|
16
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
17
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
18
|
+
from fuzzy_dl_owl2.fuzzydl.query.max.max_satisfiable_query import MaxSatisfiableQuery
|
|
19
|
+
from fuzzy_dl_owl2.fuzzydl.query.query import Query
|
|
20
|
+
from fuzzy_dl_owl2.fuzzydl.relation import Relation
|
|
21
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DefuzzifyQuery(Query):
|
|
25
|
+
|
|
26
|
+
def __init__(self, c: Concept, ind: Individual, feature_name: str) -> None:
|
|
27
|
+
self.conc: Concept = c
|
|
28
|
+
self.a: Individual = ind
|
|
29
|
+
self.f_name: str = feature_name
|
|
30
|
+
self.obj_expr: Expression = None
|
|
31
|
+
MILPHelper.PRINT_VARIABLES = False
|
|
32
|
+
MILPHelper.PRINT_LABELS = False
|
|
33
|
+
|
|
34
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
35
|
+
kb.set_dynamic_blocking()
|
|
36
|
+
s: Solution = MaxSatisfiableQuery(self.conc, self.a).solve(kb)
|
|
37
|
+
|
|
38
|
+
if s is not None and s.is_consistent_kb():
|
|
39
|
+
self.a = kb.individuals[str(self.a)]
|
|
40
|
+
kb.set_dynamic_blocking()
|
|
41
|
+
kb.add_assertion(
|
|
42
|
+
self.a, self.conc, DegreeNumeric.get_degree(s.get_solution())
|
|
43
|
+
)
|
|
44
|
+
kb.solve_assertions()
|
|
45
|
+
|
|
46
|
+
if self.f_name in self.a.role_relations:
|
|
47
|
+
rel_set: list[Relation] = self.a.role_relations[self.f_name]
|
|
48
|
+
b: CreatedIndividual = typing.cast(
|
|
49
|
+
CreatedIndividual, rel_set[0].get_object_individual()
|
|
50
|
+
)
|
|
51
|
+
q: Variable = kb.milp.get_variable(b)
|
|
52
|
+
self.obj_expr = self.get_obj_expression(q)
|
|
53
|
+
|
|
54
|
+
def solve(self, kb: KnowledgeBase) -> typing.Optional[Solution]:
|
|
55
|
+
try:
|
|
56
|
+
kb.solve_abox()
|
|
57
|
+
cloned: KnowledgeBase = kb.clone()
|
|
58
|
+
self.preprocess(cloned)
|
|
59
|
+
|
|
60
|
+
if self.obj_expr is not None:
|
|
61
|
+
MILPHelper.PRINT_LABELS = True
|
|
62
|
+
MILPHelper.PRINT_VARIABLES = True
|
|
63
|
+
|
|
64
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
65
|
+
if sol.get_solution() < 0.0:
|
|
66
|
+
return Solution(-sol.get_solution())
|
|
67
|
+
return sol
|
|
68
|
+
|
|
69
|
+
Util.warning("Warning: Problem in defuzzification. Answer is 0.")
|
|
70
|
+
return None
|
|
71
|
+
except InconsistentOntologyException:
|
|
72
|
+
return Solution(False)
|
|
73
|
+
|
|
74
|
+
@abstractmethod
|
|
75
|
+
def get_obj_expression(self, variable: Variable) -> Expression:
|
|
76
|
+
pass
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.query.defuzzify.defuzzify_query import DefuzzifyQuery
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LomDefuzzifyQuery(DefuzzifyQuery):
|
|
12
|
+
def __init__(self, c: Concept, ind: Individual, feature_name: str) -> None:
|
|
13
|
+
super().__init__(c, ind, feature_name)
|
|
14
|
+
|
|
15
|
+
def __str__(self) -> str:
|
|
16
|
+
return f"Largest of the maxima defuzzification of feature {self.f_name} for instance {self.a} = "
|
|
17
|
+
|
|
18
|
+
def get_obj_expression(self, variable: Variable) -> Expression:
|
|
19
|
+
return Expression(Term(-1.0, variable))
|