Debian Codegraph @

FaCT++.Python/coras/bin/coras-query

raw symbols SCIP
1 #!/usr/bin/env python3
2 #
3 # Coras - OWL reasoning system
4 #
5 # Copyright (C) 2018 by Artur Wroblewski <[email protected]>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import argparse
22 import logging
23 import os.path
24 import sys
25
26 import pyfactxx.coras
27 from pyfactxx.coras.cli import load_and_parse
28
29 parser = argparse.ArgumentParser()
30 parser.add_argument(
31 '-v', '--verbose', dest='verbose', help='Make a bunch of noise',
32 action='store_true'
33 )
34 parser.add_argument(
35 'query',
36 help='File with SPARQL query to run against the ontology',
37 )
38 parser.add_argument('input', nargs='+', help='Ontology files')
39
40 args = parser.parse_args()
41
42 if args.verbose:
43 log_level = logging.DEBUG
44 else:
45 log_level = logging.INFO
46 logging.basicConfig(
47 format='%(levelname)s:%(asctime)s:%(name)s:%(message)s',
48 level=log_level
49 )
50
51 # silence very noisy parser debug statements; use `coras-debug` script instead
52 for item in ('coras.debug', 'coras.parser'):
53 logger = logging.getLogger(item)
54 logger.setLevel(logging.INFO)
55
56 crs = pyfactxx.coras.Coras()
57 load_and_parse(crs, *args.input)
58 crs.realise()
59
60 with open(args.query) as f:
61 sq = f.read()
62
63 for row in crs.query(sq):
64 print(' '.join(str(s) for s in row))
65
66 # vim: sw=4:et:ai