Debian Codegraph @

FaCT++.Python/pyfactxx/coras/debug.py

raw symbols SCIP
1 #
2 # Coras - OWL reasoning system
3 #
4 # Copyright (C) 2018 by Artur Wroblewski <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 import os
21 import functools
22 import itertools
23 import logging
24 from copy import deepcopy
25
26 from rdflib.namespace import DC, RDF, RDFS, OWL, Namespace
27
28 logger = logging.getLogger(__name__)
29
30 DEBUG_ENABLED = int(os.environ.get('CORAS_PARSER_DEBUG', 0))
31
32 VS = Namespace('http://www.w3.org/2003/06/sw-vocab-status/ns#')
33 META = {
34 DC.description,
35 DC.title,
36 (RDF.type, RDF.Property),
37 RDFS.comment,
38 RDFS.label,
39 RDFS.isDefinedBy,
40 OWL.versionInfo,
41 (RDF.type, OWL.AnnotationProperty),
42 (RDF.type, OWL.Ontology),
43 VS.term_status,
44 }
45
46 def register(f):
47 @functools.wraps(f)
48 def func(graph, *args):
49 start_debug(graph)
50 result = f(graph, *args)
51 end_debug()
52 return result
53 return func
54
55 def start_debug(graph):
56 global GRAPH
57 GRAPH = deepcopy(graph)
58
59 def triples(f):
60 global GRAPH
61
62 @functools.wraps(f)
63 def func(*args):
64 triples = f(*args)
65
66 triples, to_remove = itertools.tee(triples, 2)
67 for t in to_remove:
68 GRAPH.remove(t)
69
70 return triples
71
72 return func
73
74 def end_debug():
75 global GRAPH
76
77 for s, p, o in GRAPH:
78 prefix = 'meta' if p in META or (p, o) in META else 'unsupported'
79 logger.debug('{}: {}, {}, {}'.format(prefix, s, p, o))
80 del GRAPH
81
82 # vim: sw=4:et:ai