#!/usr/bin/env python3 # # Coras - OWL reasoning system # # Copyright (C) 2018 by Artur Wroblewski # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # import argparse import logging import os.path import sys import pyfactxx.coras from pyfactxx.coras.cli import load_and_parse parser = argparse.ArgumentParser() parser.add_argument( '-v', '--verbose', dest='verbose', help='Make a bunch of noise', action='store_true' ) parser.add_argument( 'query', help='File with SPARQL query to run against the ontology', ) parser.add_argument('input', nargs='+', help='Ontology files') args = parser.parse_args() if args.verbose: log_level = logging.DEBUG else: log_level = logging.INFO logging.basicConfig( format='%(levelname)s:%(asctime)s:%(name)s:%(message)s', level=log_level ) # silence very noisy parser debug statements; use `coras-debug` script instead for item in ('coras.debug', 'coras.parser'): logger = logging.getLogger(item) logger.setLevel(logging.INFO) crs = pyfactxx.coras.Coras() load_and_parse(crs, *args.input) crs.realise() with open(args.query) as f: sq = f.read() for row in crs.query(sq): print(' '.join(str(s) for s in row)) # vim: sw=4:et:ai