Skip to content

Commit

Permalink
Create check_reasoner.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jsimonclark authored Jun 22, 2024
1 parent fe7c3fa commit 61d6cb4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions docs/scripts/check_reasoner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import rdflib
from owlrl import DeductiveClosure, OWLRL_Semantics
import logging
import sys
import os

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Path to the ontology file in the root directory of the repository
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
ontology_path = os.path.join(repo_root, "electrochemistry.ttl")

# Check if the file exists
if not os.path.isfile(ontology_path):
logger.error(f"Ontology file not found at {ontology_path}")
sys.exit(1)

# Load the ontology using rdflib
g = rdflib.Graph()
try:
g.parse(ontology_path, format='ttl')
logger.info("Ontology loaded successfully")
except Exception as e:
logger.error(f"Error loading ontology: {e}")
sys.exit(1)

# Perform OWL 2 RL reasoning
try:
DeductiveClosure(OWLRL_Semantics).expand(g)
logger.info("Reasoning completed successfully")
except Exception as e:
logger.error(f"Reasoning error: {e}")
sys.exit(1)

# Check for inconsistencies
# Note: OWL-RL does not inherently provide inconsistency detection.
# Here we just count the triples and ensure some reasoning happened.
inferred_triples = len(g)
if inferred_triples > 0:
logger.info(f"Inferred {inferred_triples} triples.")
else:
logger.error("No triples inferred, something might be wrong.")
sys.exit(1)

sys.exit(0)

0 comments on commit 61d6cb4

Please sign in to comment.