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,88 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import traceback
|
|
4
|
+
import typing
|
|
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.fuzzy_ontology_exception import (
|
|
9
|
+
FuzzyOntologyException,
|
|
10
|
+
)
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
12
|
+
InconsistentOntologyException,
|
|
13
|
+
)
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.individual.created_individual import CreatedIndividual
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
16
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
17
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
18
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
19
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
20
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
21
|
+
from fuzzy_dl_owl2.fuzzydl.query.defuzzify.defuzzify_query import DefuzzifyQuery
|
|
22
|
+
from fuzzy_dl_owl2.fuzzydl.query.max.max_satisfiable_query import MaxSatisfiableQuery
|
|
23
|
+
from fuzzy_dl_owl2.fuzzydl.relation import Relation
|
|
24
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class MomDefuzzifyQuery(DefuzzifyQuery):
|
|
28
|
+
|
|
29
|
+
def __init__(self, c: Concept, ind: Individual, feature_name: str) -> None:
|
|
30
|
+
super().__init__(c, ind, feature_name)
|
|
31
|
+
|
|
32
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
36
|
+
try:
|
|
37
|
+
kb.solve_abox()
|
|
38
|
+
cloned: KnowledgeBase = kb.clone()
|
|
39
|
+
cloned.set_dynamic_blocking()
|
|
40
|
+
s: Solution = MaxSatisfiableQuery(self.conc, self.a).solve(cloned)
|
|
41
|
+
if not s.is_consistent_kb():
|
|
42
|
+
return s
|
|
43
|
+
d: float = s.get_solution()
|
|
44
|
+
cloned: KnowledgeBase = kb.clone()
|
|
45
|
+
ind: Individual = cloned.individuals.get(str(self.a))
|
|
46
|
+
cloned.set_dynamic_blocking()
|
|
47
|
+
cloned.add_assertion(self.a, self.conc, DegreeNumeric.get_degree(d))
|
|
48
|
+
cloned.solve_assertions()
|
|
49
|
+
if self.f_name not in ind.role_relations:
|
|
50
|
+
Util.warning("Warning: Problem in defuzzification. Answer is 0.")
|
|
51
|
+
return None
|
|
52
|
+
except InconsistentOntologyException:
|
|
53
|
+
return Solution(False)
|
|
54
|
+
|
|
55
|
+
rel_set: list[Relation] = ind.role_relations.get(self.f_name)
|
|
56
|
+
b: CreatedIndividual = typing.cast(
|
|
57
|
+
CreatedIndividual, rel_set[0].get_object_individual()
|
|
58
|
+
)
|
|
59
|
+
q: Variable = cloned.milp.get_variable(b)
|
|
60
|
+
if q is None:
|
|
61
|
+
Util.warning("Warning: Problem in defuzzification. Answer is 0.")
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
try:
|
|
65
|
+
self.ob_expr: Expression = Expression(Term(-1.0, q))
|
|
66
|
+
sol1: Solution = cloned.optimize(self.obj_expr)
|
|
67
|
+
if sol1.get_solution() < 0.0:
|
|
68
|
+
sol1 = Solution(-sol1.get_solution())
|
|
69
|
+
self.obj_expr: Expression = Expression(Term(1.0, q))
|
|
70
|
+
sol2: Solution = cloned.optimize(self.obj_expr)
|
|
71
|
+
if sol2.get_solution() < 0.0:
|
|
72
|
+
sol2 = Solution(-sol2.get_solution())
|
|
73
|
+
if sol1.is_consistent_kb() and sol2.is_consistent_kb():
|
|
74
|
+
value = (sol1.get_solution() + sol2.get_solution()) / 2.0
|
|
75
|
+
kb.milp.print_instance_of_labels(self.f_name, str(self.a), value)
|
|
76
|
+
return Solution(value)
|
|
77
|
+
return sol1
|
|
78
|
+
except FuzzyOntologyException as e:
|
|
79
|
+
traceback.print_exc()
|
|
80
|
+
except InconsistentOntologyException as e:
|
|
81
|
+
traceback.print_exc()
|
|
82
|
+
return None
|
|
83
|
+
|
|
84
|
+
def get_obj_expression(self, variable: Variable) -> Expression:
|
|
85
|
+
return Expression(Term(-1.0, variable))
|
|
86
|
+
|
|
87
|
+
def __str__(self) -> str:
|
|
88
|
+
return f"Middle of the maxima defuzzification of feature {self.f_name} for instance {self.a} = "
|
|
@@ -0,0 +1,20 @@
|
|
|
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 SomDefuzzifyQuery(DefuzzifyQuery):
|
|
12
|
+
|
|
13
|
+
def __init__(self, c: Concept, ind: Individual, f_name: str) -> None:
|
|
14
|
+
super().__init__(c, ind, f_name)
|
|
15
|
+
|
|
16
|
+
def __str__(self) -> str:
|
|
17
|
+
return f"Smallest of the maxima defuzzification of feature {self.f_name} for instance {self.a} = "
|
|
18
|
+
|
|
19
|
+
def get_obj_expression(self, q: Variable) -> Expression:
|
|
20
|
+
return Expression(Term(1.0, q))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC
|
|
4
|
+
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.query.query import Query
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.util.util import Util
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class InstanceQuery(Query, ABC):
|
|
13
|
+
def __init__(self, concept: Concept, individual: Individual) -> None:
|
|
14
|
+
if concept.is_concrete():
|
|
15
|
+
Util.error(f"Error: {concept} cannot be a concrete concept.")
|
|
16
|
+
|
|
17
|
+
self.conc: Concept = concept
|
|
18
|
+
self.ind: Individual = individual
|
|
19
|
+
self.obj_expr: Expression = None
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
4
|
+
InconsistentOntologyException,
|
|
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 KbSatisfiableQuery(Query):
|
|
12
|
+
|
|
13
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
17
|
+
try:
|
|
18
|
+
return Solution(1.0) if self.is_consistent_kb(kb) else Solution(False)
|
|
19
|
+
except InconsistentOntologyException:
|
|
20
|
+
return Solution(False)
|
|
21
|
+
|
|
22
|
+
def is_consistent_kb(self, kb: KnowledgeBase) -> bool:
|
|
23
|
+
kb.solve_abox()
|
|
24
|
+
cloned: KnowledgeBase = kb.clone()
|
|
25
|
+
if len(cloned.individuals) == 0:
|
|
26
|
+
cloned.get_new_individual()
|
|
27
|
+
cloned.solve_assertions()
|
|
28
|
+
sol: Solution = cloned.optimize(None)
|
|
29
|
+
return sol is not None and sol.is_consistent_kb()
|
|
30
|
+
|
|
31
|
+
def __str__(self) -> str:
|
|
32
|
+
return "Is KnowledgeBase satisfiable? = "
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_variable import DegreeVariable
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
6
|
+
InconsistentOntologyException,
|
|
7
|
+
)
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.query.instance_query import InstanceQuery
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class MaxInstanceQuery(InstanceQuery):
|
|
18
|
+
def __init__(self, concept: Concept, individual: Individual) -> None:
|
|
19
|
+
super().__init__(concept, individual)
|
|
20
|
+
|
|
21
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
22
|
+
q: Variable = kb.milp.get_variable(self.ind, self.conc)
|
|
23
|
+
kb.old_01_variables += 1
|
|
24
|
+
self.obj_expr: Expression = Expression(Term(-1.0, q))
|
|
25
|
+
|
|
26
|
+
if "(all " in str(self.conc) or "(not (b-some " in str(self.conc):
|
|
27
|
+
kb.set_dynamic_blocking()
|
|
28
|
+
|
|
29
|
+
kb.add_assertion(self.ind, self.conc, DegreeVariable.get_degree(q))
|
|
30
|
+
kb.solve_assertions()
|
|
31
|
+
|
|
32
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
33
|
+
try:
|
|
34
|
+
self.set_initial_time()
|
|
35
|
+
kb.solve_abox()
|
|
36
|
+
cloned: KnowledgeBase = kb.clone()
|
|
37
|
+
self.preprocess(cloned)
|
|
38
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
39
|
+
self.set_total_time()
|
|
40
|
+
return sol
|
|
41
|
+
except InconsistentOntologyException:
|
|
42
|
+
return Solution(False)
|
|
43
|
+
|
|
44
|
+
def __str__(self) -> str:
|
|
45
|
+
return f"Is {self.ind} instance of {self.conc} ? <= "
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
4
|
+
InconsistentOntologyException,
|
|
5
|
+
)
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.query.query import Query
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MaxQuery(Query):
|
|
13
|
+
def __init__(self, expr: Expression) -> None:
|
|
14
|
+
self.obj_expr: Expression = Expression.negate_expression(expr)
|
|
15
|
+
|
|
16
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
20
|
+
try:
|
|
21
|
+
self.set_initial_time()
|
|
22
|
+
kb.solve_abox()
|
|
23
|
+
cloned: KnowledgeBase = kb.clone()
|
|
24
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
25
|
+
self.set_total_time()
|
|
26
|
+
return sol
|
|
27
|
+
except InconsistentOntologyException:
|
|
28
|
+
return Solution(False)
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
return f"{self.obj_expr} <= "
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.has_value_concept import HasValueConcept
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_variable import DegreeVariable
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
7
|
+
InconsistentOntologyException,
|
|
8
|
+
)
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.query.related_query import RelatedQuery
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MaxRelatedQuery(RelatedQuery):
|
|
19
|
+
def __init__(self, a: Individual, b: Individual, role_name: str) -> None:
|
|
20
|
+
self.ind1: Individual = a
|
|
21
|
+
self.ind2: Individual = b
|
|
22
|
+
self.role: str = role_name
|
|
23
|
+
|
|
24
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
25
|
+
conc: Concept = HasValueConcept(self.role, self.ind2)
|
|
26
|
+
q: Variable = kb.milp.get_variable(self.ind1, conc)
|
|
27
|
+
kb.add_assertion(self.ind1, conc, DegreeVariable.get_degree(q))
|
|
28
|
+
kb.old_01_variables += 1
|
|
29
|
+
self.obj_expr: Expression = Expression(Term(-1.0, q))
|
|
30
|
+
kb.solve_assertions()
|
|
31
|
+
|
|
32
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
33
|
+
try:
|
|
34
|
+
self.set_initial_time()
|
|
35
|
+
kb.solve_abox()
|
|
36
|
+
cloned: KnowledgeBase = kb.clone()
|
|
37
|
+
self.preprocess(cloned)
|
|
38
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
39
|
+
self.set_total_time()
|
|
40
|
+
return sol
|
|
41
|
+
except InconsistentOntologyException:
|
|
42
|
+
return Solution(False)
|
|
43
|
+
|
|
44
|
+
def __str__(self) -> str:
|
|
45
|
+
return f"Is {self.ind1} related to {self.ind2} through {self.role} ? <= "
|
|
@@ -0,0 +1,73 @@
|
|
|
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.degree.degree_variable import DegreeVariable
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
8
|
+
InconsistentOntologyException,
|
|
9
|
+
)
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
16
|
+
from fuzzy_dl_owl2.fuzzydl.query.satisfiable_query import SatisfiableQuery
|
|
17
|
+
from fuzzy_dl_owl2.fuzzydl.util.config_reader import ConfigReader
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MaxSatisfiableQuery(SatisfiableQuery):
|
|
21
|
+
|
|
22
|
+
@typing.overload
|
|
23
|
+
def __init__(self, c: Concept) -> None: ...
|
|
24
|
+
|
|
25
|
+
@typing.overload
|
|
26
|
+
def __init__(self, c: Concept, a: Individual) -> None: ...
|
|
27
|
+
|
|
28
|
+
def __init__(self, *args) -> None:
|
|
29
|
+
assert len(args) in [1, 2]
|
|
30
|
+
assert isinstance(args[0], Concept)
|
|
31
|
+
if len(args) == 1:
|
|
32
|
+
self.__max_sat_query_init_1(*args)
|
|
33
|
+
else:
|
|
34
|
+
assert args[1] is None or isinstance(args[1], Individual)
|
|
35
|
+
self.__max_sat_query_init_2(*args)
|
|
36
|
+
|
|
37
|
+
def __max_sat_query_init_1(self, c: Concept) -> None:
|
|
38
|
+
super().__init__(c)
|
|
39
|
+
|
|
40
|
+
def __max_sat_query_init_2(self, c: Concept, a: Individual) -> None:
|
|
41
|
+
super().__init__(c, a)
|
|
42
|
+
|
|
43
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
44
|
+
if "(all " in str(self.conc) or "(not (b-some " in str(self.conc):
|
|
45
|
+
kb.set_dynamic_blocking()
|
|
46
|
+
q: Variable = kb.milp.get_variable(self.ind, self.conc)
|
|
47
|
+
kb.old_01_variables += 1
|
|
48
|
+
self.obj_expr: Expression = Expression(Term(-1.0, q))
|
|
49
|
+
kb.add_assertion(self.ind, self.conc, DegreeVariable.get_degree(q))
|
|
50
|
+
kb.solve_assertions()
|
|
51
|
+
|
|
52
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
53
|
+
try:
|
|
54
|
+
self.set_initial_time()
|
|
55
|
+
use_abox = self.ind is not None or ConfigReader.OPTIMIZATIONS == 0
|
|
56
|
+
cloned: KnowledgeBase = kb.clone() if use_abox else kb.clone_without_abox()
|
|
57
|
+
if self.ind is None:
|
|
58
|
+
self.ind: Individual = cloned.get_new_individual()
|
|
59
|
+
if use_abox:
|
|
60
|
+
cloned.solve_abox()
|
|
61
|
+
self.preprocess(cloned)
|
|
62
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
63
|
+
if sol.get_solution() < 0.0:
|
|
64
|
+
sol = Solution(-sol.get_solution())
|
|
65
|
+
self.set_total_time()
|
|
66
|
+
return sol
|
|
67
|
+
except InconsistentOntologyException:
|
|
68
|
+
return Solution(False)
|
|
69
|
+
|
|
70
|
+
def __str__(self) -> str:
|
|
71
|
+
if self.ind is not None:
|
|
72
|
+
return f"Is Concept {self.conc} satisfiable? [Individual {self.ind}] <= "
|
|
73
|
+
return f"Is Concept {self.conc} satisfiable? <= "
|
|
@@ -0,0 +1,64 @@
|
|
|
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.implies_concept import ImpliesConcept
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.concept.operator_concept import OperatorConcept
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_variable import DegreeVariable
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
10
|
+
InconsistentOntologyException,
|
|
11
|
+
)
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.individual.created_individual import CreatedIndividual
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
16
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
17
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
18
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
19
|
+
from fuzzy_dl_owl2.fuzzydl.query.subsumption_query import SubsumptionQuery
|
|
20
|
+
from fuzzy_dl_owl2.fuzzydl.util.config_reader import ConfigReader
|
|
21
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import LogicOperatorType
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MaxSubsumesQuery(SubsumptionQuery):
|
|
25
|
+
|
|
26
|
+
def __init__(self, c1: Concept, c2: Concept, type_: LogicOperatorType) -> None:
|
|
27
|
+
super().__init__(c1, c2, type_)
|
|
28
|
+
|
|
29
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
30
|
+
ind: CreatedIndividual = kb.get_new_individual()
|
|
31
|
+
if self.type == LogicOperatorType.LUKASIEWICZ:
|
|
32
|
+
conc: Concept = OperatorConcept.lukasiewicz_or(-self.c2, self.c1)
|
|
33
|
+
elif self.type == LogicOperatorType.GOEDEL:
|
|
34
|
+
conc: Concept = ImpliesConcept.goedel_implies(self.c2, self.c1)
|
|
35
|
+
elif self.type == LogicOperatorType.KLEENE_DIENES:
|
|
36
|
+
conc: Concept = ImpliesConcept.zadeh_implies(self.c2, self.c1)
|
|
37
|
+
else: # LogicOperatorType.ZADEH
|
|
38
|
+
conc: Concept = OperatorConcept.goedel_or(-self.c2, self.c1)
|
|
39
|
+
|
|
40
|
+
q: Variable = kb.milp.get_variable(typing.cast(Individual, ind), conc)
|
|
41
|
+
kb.old_01_variables += 1
|
|
42
|
+
self.obj_expr = Expression(Term(-1.0, q))
|
|
43
|
+
|
|
44
|
+
kb.add_assertion(ind, conc, DegreeVariable.get_degree(q))
|
|
45
|
+
kb.solve_assertions()
|
|
46
|
+
|
|
47
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
48
|
+
try:
|
|
49
|
+
self.set_initial_time()
|
|
50
|
+
if ConfigReader.OPTIMIZATIONS == 0 or kb.has_nominals_in_tbox():
|
|
51
|
+
cloned: KnowledgeBase = kb.clone()
|
|
52
|
+
cloned.solve_abox()
|
|
53
|
+
else:
|
|
54
|
+
cloned: KnowledgeBase = kb.clone_without_abox()
|
|
55
|
+
|
|
56
|
+
self.preprocess(cloned)
|
|
57
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
58
|
+
self.set_total_time()
|
|
59
|
+
return sol
|
|
60
|
+
except InconsistentOntologyException:
|
|
61
|
+
return Solution(False)
|
|
62
|
+
|
|
63
|
+
def __str__(self) -> str:
|
|
64
|
+
return f"{self.c1} subsumes {self.c2} ? <= "
|
|
@@ -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.degree.degree_expression import DegreeExpression
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
6
|
+
InconsistentOntologyException,
|
|
7
|
+
)
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.query.instance_query import InstanceQuery
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import VariableType
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MinInstanceQuery(InstanceQuery):
|
|
19
|
+
def __init__(self, concept: Concept, individual: Individual) -> None:
|
|
20
|
+
super().__init__(concept, individual)
|
|
21
|
+
|
|
22
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
23
|
+
q: Variable = kb.milp.get_new_variable(VariableType.SEMI_CONTINUOUS)
|
|
24
|
+
kb.old_01_variables += 1
|
|
25
|
+
self.obj_expr: Expression = Expression(Term(1.0, q))
|
|
26
|
+
|
|
27
|
+
if "(some " in str(self.conc) or "(b-some " in str(self.conc):
|
|
28
|
+
kb.set_dynamic_blocking()
|
|
29
|
+
|
|
30
|
+
kb.add_assertion(
|
|
31
|
+
self.ind,
|
|
32
|
+
-self.conc,
|
|
33
|
+
DegreeExpression.get_degree(Expression(1.0, Term(-1.0, q))),
|
|
34
|
+
)
|
|
35
|
+
kb.solve_assertions()
|
|
36
|
+
|
|
37
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
38
|
+
try:
|
|
39
|
+
self.set_initial_time()
|
|
40
|
+
kb.solve_abox()
|
|
41
|
+
cloned: KnowledgeBase = kb.clone()
|
|
42
|
+
self.preprocess(cloned)
|
|
43
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
44
|
+
self.set_total_time()
|
|
45
|
+
return sol
|
|
46
|
+
except InconsistentOntologyException:
|
|
47
|
+
return Solution(False)
|
|
48
|
+
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
return f"Is {self.ind} instance of {self.conc} ? >= "
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
4
|
+
InconsistentOntologyException,
|
|
5
|
+
)
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
8
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
9
|
+
from fuzzy_dl_owl2.fuzzydl.query.query import Query
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MinQuery(Query):
|
|
13
|
+
def __init__(self, expr: Expression) -> None:
|
|
14
|
+
self.obj_expr = expr
|
|
15
|
+
|
|
16
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
def solve(self, kb: KnowledgeBase) -> None:
|
|
20
|
+
try:
|
|
21
|
+
self.set_initial_time()
|
|
22
|
+
kb.solve_abox()
|
|
23
|
+
cloned: KnowledgeBase = kb.clone()
|
|
24
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
25
|
+
self.set_total_time()
|
|
26
|
+
return sol
|
|
27
|
+
except InconsistentOntologyException:
|
|
28
|
+
return Solution(False)
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
return f"{self.obj_expr} ? >= "
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from fuzzy_dl_owl2.fuzzydl.concept.concept import Concept
|
|
4
|
+
from fuzzy_dl_owl2.fuzzydl.concept.has_value_concept import HasValueConcept
|
|
5
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_expression import DegreeExpression
|
|
6
|
+
from fuzzy_dl_owl2.fuzzydl.degree.degree_variable import DegreeVariable
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
8
|
+
InconsistentOntologyException,
|
|
9
|
+
)
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
16
|
+
from fuzzy_dl_owl2.fuzzydl.query.related_query import RelatedQuery
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MinRelatedQuery(RelatedQuery):
|
|
20
|
+
|
|
21
|
+
def __init__(self, a: Individual, b: Individual, role_name: str) -> None:
|
|
22
|
+
self.ind1: Individual = a
|
|
23
|
+
self.ind2: Individual = b
|
|
24
|
+
self.role: str = role_name
|
|
25
|
+
|
|
26
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
27
|
+
conc: Concept = HasValueConcept(self.role, self.ind2)
|
|
28
|
+
q: Variable = kb.milp.get_variable(self.ind1, conc)
|
|
29
|
+
kb.add_assertion(self.ind1, conc, DegreeVariable.get_degree(q))
|
|
30
|
+
kb.old_01_variables += 1
|
|
31
|
+
self.obj_expr: Expression = Expression(Term(1.0, q))
|
|
32
|
+
|
|
33
|
+
if "(some " in str(conc) or "(b-some " in str(conc):
|
|
34
|
+
kb.set_dynamic_blocking()
|
|
35
|
+
|
|
36
|
+
kb.add_assertion(
|
|
37
|
+
self.ind1,
|
|
38
|
+
-conc,
|
|
39
|
+
DegreeExpression.get_degree(Expression(1.0, Term(-1.0, q))),
|
|
40
|
+
)
|
|
41
|
+
kb.solve_assertions()
|
|
42
|
+
|
|
43
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
44
|
+
try:
|
|
45
|
+
self.set_initial_time()
|
|
46
|
+
kb.old_binary_variables += 1
|
|
47
|
+
kb.solve_abox()
|
|
48
|
+
cloned: KnowledgeBase = kb.clone()
|
|
49
|
+
self.preprocess(cloned)
|
|
50
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
51
|
+
self.set_total_time()
|
|
52
|
+
return sol
|
|
53
|
+
except InconsistentOntologyException:
|
|
54
|
+
return Solution(False)
|
|
55
|
+
|
|
56
|
+
def __str__(self) -> str:
|
|
57
|
+
return f"Is {self.ind1} related to {self.ind2} through {self.role} ? >= "
|
|
@@ -0,0 +1,80 @@
|
|
|
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.degree.degree_expression import DegreeExpression
|
|
7
|
+
from fuzzy_dl_owl2.fuzzydl.exception.inconsistent_ontology_exception import (
|
|
8
|
+
InconsistentOntologyException,
|
|
9
|
+
)
|
|
10
|
+
from fuzzy_dl_owl2.fuzzydl.individual.individual import Individual
|
|
11
|
+
from fuzzy_dl_owl2.fuzzydl.knowledge_base import KnowledgeBase
|
|
12
|
+
from fuzzy_dl_owl2.fuzzydl.milp.expression import Expression
|
|
13
|
+
from fuzzy_dl_owl2.fuzzydl.milp.solution import Solution
|
|
14
|
+
from fuzzy_dl_owl2.fuzzydl.milp.term import Term
|
|
15
|
+
from fuzzy_dl_owl2.fuzzydl.milp.variable import Variable
|
|
16
|
+
from fuzzy_dl_owl2.fuzzydl.query.satisfiable_query import SatisfiableQuery
|
|
17
|
+
from fuzzy_dl_owl2.fuzzydl.util.config_reader import ConfigReader
|
|
18
|
+
from fuzzy_dl_owl2.fuzzydl.util.constants import VariableType
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MinSatisfiableQuery(SatisfiableQuery):
|
|
22
|
+
|
|
23
|
+
@typing.overload
|
|
24
|
+
def __init__(self, c: Concept) -> None: ...
|
|
25
|
+
|
|
26
|
+
@typing.overload
|
|
27
|
+
def __init__(self, c: Concept, a: Individual) -> None: ...
|
|
28
|
+
|
|
29
|
+
def __init__(self, *args) -> None:
|
|
30
|
+
assert len(args) in [1, 2]
|
|
31
|
+
assert isinstance(args[0], Concept)
|
|
32
|
+
if len(args) == 1:
|
|
33
|
+
self.__min_sat_query_init_1(*args)
|
|
34
|
+
else:
|
|
35
|
+
assert isinstance(args[1], Individual)
|
|
36
|
+
self.__min_sat_query_init_2(*args)
|
|
37
|
+
|
|
38
|
+
def __min_sat_query_init_1(self, c: Concept) -> None:
|
|
39
|
+
super().__init__(c)
|
|
40
|
+
|
|
41
|
+
def __min_sat_query_init_2(self, c: Concept, a: Individual) -> None:
|
|
42
|
+
super().__init__(c, a)
|
|
43
|
+
|
|
44
|
+
def preprocess(self, kb: KnowledgeBase) -> None:
|
|
45
|
+
if "(some " in str(self.conc) or "(b-some " in str(self.conc):
|
|
46
|
+
kb.set_dynamic_blocking()
|
|
47
|
+
q: Variable = kb.milp.get_new_variable(VariableType.SEMI_CONTINUOUS)
|
|
48
|
+
kb.old_01_variables += 1
|
|
49
|
+
self.obj_expr: Expression = Expression(Term(1.0, q))
|
|
50
|
+
kb.add_assertion(
|
|
51
|
+
self.ind,
|
|
52
|
+
-self.conc,
|
|
53
|
+
DegreeExpression.get_degree(Expression(1.0, Term(-1.0, q))),
|
|
54
|
+
)
|
|
55
|
+
kb.solve_assertions()
|
|
56
|
+
|
|
57
|
+
def solve(self, kb: KnowledgeBase) -> Solution:
|
|
58
|
+
try:
|
|
59
|
+
self.set_initial_time()
|
|
60
|
+
kb.old_binary_variables += 1
|
|
61
|
+
use_abox = self.ind is not None or ConfigReader.OPTIMIZATIONS == 0
|
|
62
|
+
cloned: KnowledgeBase = kb.clone() if use_abox else kb.clone_without_abox()
|
|
63
|
+
if self.ind is None:
|
|
64
|
+
self.ind: Individual = cloned.get_new_individual()
|
|
65
|
+
if use_abox:
|
|
66
|
+
cloned.solve_abox()
|
|
67
|
+
self.preprocess(cloned)
|
|
68
|
+
sol: Solution = cloned.optimize(self.obj_expr)
|
|
69
|
+
if sol.get_solution() < 0.0:
|
|
70
|
+
sol = Solution(-sol.get_solution())
|
|
71
|
+
self.set_total_time()
|
|
72
|
+
return sol
|
|
73
|
+
|
|
74
|
+
except InconsistentOntologyException:
|
|
75
|
+
return Solution(False)
|
|
76
|
+
|
|
77
|
+
def __str__(self) -> str:
|
|
78
|
+
if self.ind is not None:
|
|
79
|
+
return f"Is Concept {self.conc} satisfiable? [Individual {self.ind}] >= "
|
|
80
|
+
return f"Is Concept {self.conc} satisfiable? >= "
|