Spaces:
Runtime error
Runtime error
Update ontology_reasoner.py
Browse files- ontology_reasoner.py +0 -47
ontology_reasoner.py
CHANGED
|
@@ -5,53 +5,6 @@ Provides classification and consistency checking.
|
|
| 5 |
import logging
|
| 6 |
logger = logging.getLogger(__name__)
|
| 7 |
|
| 8 |
-
try:
|
| 9 |
-
from owlready2 import *
|
| 10 |
-
OWLREADY_AVAILABLE = True
|
| 11 |
-
except ImportError:
|
| 12 |
-
OWLREADY_AVAILABLE = False
|
| 13 |
-
|
| 14 |
-
class InfraOntology:
|
| 15 |
-
def __init__(self, path="infra.owl"):
|
| 16 |
-
self.available = OWLREADY_AVAILABLE
|
| 17 |
-
self.onto = None
|
| 18 |
-
if self.available:
|
| 19 |
-
try:
|
| 20 |
-
self.onto = get_ontology(path).load()
|
| 21 |
-
logger.info(f"Ontology loaded from {path}")
|
| 22 |
-
except Exception as e:
|
| 23 |
-
logger.warning(f"Failed to load ontology: {e}")
|
| 24 |
-
self.available = False
|
| 25 |
-
else:
|
| 26 |
-
logger.info("Owlready2 not installed, ontology disabled")
|
| 27 |
-
|
| 28 |
-
def classify(self, component_type: str) -> dict:
|
| 29 |
-
"""
|
| 30 |
-
Run reasoner and return inferred classes for a given component type.
|
| 31 |
-
Returns dict with 'inferred' list and 'consistent' bool.
|
| 32 |
-
"""
|
| 33 |
-
if not self.available or self.onto is None:
|
| 34 |
-
return {"inferred": [], "consistent": True}
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
with self.onto:
|
| 38 |
-
sync_reasoner()
|
| 39 |
-
# Find all individuals of the given type (simplified)
|
| 40 |
-
inferred = []
|
| 41 |
-
# Example: if component_type == "server", get all Server instances
|
| 42 |
-
if hasattr(self.onto, component_type.capitalize()):
|
| 43 |
-
cls = getattr(self.onto, component_type.capitalize())
|
| 44 |
-
inferred = [str(i) for i in cls.instances()]
|
| 45 |
-
return {"inferred": inferred, "consistent": True}
|
| 46 |
-
except Exception as e:
|
| 47 |
-
logger.error(f"Reasoning error: {e}")
|
| 48 |
-
return {"inferred": [], "consistent": False, "error": str(e)}"""
|
| 49 |
-
Owlready2 wrapper for a small infrastructure ontology.
|
| 50 |
-
Provides classification and consistency checking.
|
| 51 |
-
"""
|
| 52 |
-
import logging
|
| 53 |
-
logger = logging.getLogger(__name__)
|
| 54 |
-
|
| 55 |
try:
|
| 56 |
from owlready2 import *
|
| 57 |
OWLREADY_AVAILABLE = True
|
|
|
|
| 5 |
import logging
|
| 6 |
logger = logging.getLogger(__name__)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
from owlready2 import *
|
| 10 |
OWLREADY_AVAILABLE = True
|