| # ontology_reasoner.py | |
| import logging | |
| logger = logging.getLogger(__name__) | |
| try: | |
| from owlready2 import * | |
| OWLREADY_AVAILABLE = True | |
| except ImportError: | |
| OWLREADY_AVAILABLE = False | |
| class InfraOntology: | |
| def __init__(self, path="infra.owl"): | |
| self.available = OWLREADY_AVAILABLE | |
| if self.available: | |
| try: | |
| self.onto = get_ontology(path).load() | |
| except: | |
| self.available = False | |
| logger.warning("Ontology load failed, using mock") | |
| else: | |
| logger.info("Owlready2 not installed, ontology disabled") | |
| def classify(self, component_type): | |
| if not self.available: | |
| return {"inferred": [], "consistent": True} | |
| # Run reasoner and return results | |
| with self.onto: | |
| sync_reasoner() | |
| # ... extract inferences | |
| return {"inferred": ["NetworkDevice"], "consistent": True} |