-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_ontology_axiom.py
45 lines (37 loc) · 1.73 KB
/
add_ontology_axiom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from owlready2 import *
from common import ConceptAssertion, RoleAssertion, TBoxAxiom
from nl_2_owl import make_concept, special_axiom, make_special_axiom
from types import new_class
def KB_union_unknown_axiom(axiom):
# The axiom would be a false question if KB U {Axiom} -> Inconsistent KB
# Load the current ontology
onto = get_ontology("./ALCQ_ontology.owl").load()
# Add the "unknown" question axiom to it
with onto:
if isinstance(axiom, ConceptAssertion): # Class Assertion ##
assertion_concept = axiom.concept
indName = axiom.individual
concept, _ = make_concept(onto, assertion_concept)
ind = Thing(str(indName))
ind.is_a.append(concept)
elif isinstance(axiom, RoleAssertion): # Role Assertion ##
role_name = axiom.RoleName
leftIndName = axiom.Individual_l
rightIndName = axiom.Individual_r
role = new_class(str(role_name), (ObjectProperty,))
role.domain = [Thing]
role.range = [Thing]
leftInd = Thing(str(leftIndName))
rightInd = Thing(str(rightIndName))
role[leftInd].append(rightInd)
elif isinstance(axiom, TBoxAxiom):
special_check, special_type = special_axiom(axiom)
if special_check:
make_special_axiom(onto, axiom, special_type)
else:
lhs_concept, _ = make_concept(onto, axiom.LHS_concept)
rhs_concept, _ = make_concept(onto, axiom.RHS_concept)
lhs_concept.is_a.append(rhs_concept)
AllDifferent(list(onto.individuals()))
onto.save(f"./ALCQCC.owl", "rdfxml")
onto.destroy(update_is_a=True, update_relation=True)