-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe7c3fa
commit 61d6cb4
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |