Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference/rdf_debug.py @ 1727:23e6154e6c11
file moves
author | drewp@bigasterisk.com |
---|---|
date | Tue, 20 Jun 2023 23:26:24 -0700 |
parents | service/mqtt_to_rdf/rdf_debug.py@7d3797ed6681 |
children |
comparison
equal
deleted
inserted
replaced
1726:7d3797ed6681 | 1727:23e6154e6c11 |
---|---|
1 import logging | |
2 from typing import List, Union | |
3 | |
4 from rdflib.graph import Graph | |
5 from rdflib.namespace import Namespace | |
6 | |
7 from inference.inference_types import Triple | |
8 | |
9 log = logging.getLogger('infer') | |
10 | |
11 ROOM = Namespace("http://projects.bigasterisk.com/room/") | |
12 | |
13 | |
14 def graphDump(g: Union[Graph, List[Triple]], oneLine=True): | |
15 # this is very slow- debug only! | |
16 if not log.isEnabledFor(logging.DEBUG): | |
17 return "(skipped dump)" | |
18 try: | |
19 if not isinstance(g, Graph): | |
20 g2 = Graph() | |
21 g2 += g | |
22 g = g2 | |
23 g.bind('', ROOM) | |
24 g.bind('ex', Namespace('http://example.com/')) | |
25 lines = g.serialize(format='n3').splitlines() | |
26 lines = [line for line in lines if not line.startswith('@prefix')] | |
27 if oneLine: | |
28 lines = [line.strip() for line in lines] | |
29 return ' '.join(lines) | |
30 except TypeError: | |
31 return repr(g) |