petter2025 commited on
Commit
75019b9
·
verified ·
1 Parent(s): 39cd578

Create ontology_reasoner.py

Browse files
Files changed (1) hide show
  1. ontology_reasoner.py +30 -0
ontology_reasoner.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ontology_reasoner.py
2
+ import logging
3
+ logger = logging.getLogger(__name__)
4
+
5
+ try:
6
+ from owlready2 import *
7
+ OWLREADY_AVAILABLE = True
8
+ except ImportError:
9
+ OWLREADY_AVAILABLE = False
10
+
11
+ class InfraOntology:
12
+ def __init__(self, path="infra.owl"):
13
+ self.available = OWLREADY_AVAILABLE
14
+ if self.available:
15
+ try:
16
+ self.onto = get_ontology(path).load()
17
+ except:
18
+ self.available = False
19
+ logger.warning("Ontology load failed, using mock")
20
+ else:
21
+ logger.info("Owlready2 not installed, ontology disabled")
22
+
23
+ def classify(self, component_type):
24
+ if not self.available:
25
+ return {"inferred": [], "consistent": True}
26
+ # Run reasoner and return results
27
+ with self.onto:
28
+ sync_reasoner()
29
+ # ... extract inferences
30
+ return {"inferred": ["NetworkDevice"], "consistent": True}