Mercurial > code > home > repos > homeauto
comparison service/mqtt_to_rdf/inference.py @ 1650:2061df259224
move graphDump (on its way out, since reprs are getting better)
author | drewp@bigasterisk.com |
---|---|
date | Sat, 18 Sep 2021 23:53:59 -0700 |
parents | bb5d2b5370ac |
children | 20474ad4968e |
comparison
equal
deleted
inserted
replaced
1649:bb5d2b5370ac | 1650:2061df259224 |
---|---|
15 from rdflib.term import Node, URIRef, Variable | 15 from rdflib.term import Node, URIRef, Variable |
16 | 16 |
17 from candidate_binding import BindingConflict, CandidateBinding | 17 from candidate_binding import BindingConflict, CandidateBinding |
18 from inference_types import BindingUnknown, ReadOnlyWorkingSet, Triple | 18 from inference_types import BindingUnknown, ReadOnlyWorkingSet, Triple |
19 from lhs_evaluation import functionsFor, lhsStmtsUsedByFuncs, rulePredicates | 19 from lhs_evaluation import functionsFor, lhsStmtsUsedByFuncs, rulePredicates |
20 from rdf_debug import graphDump | |
20 | 21 |
21 log = logging.getLogger('infer') | 22 log = logging.getLogger('infer') |
22 INDENT = ' ' | 23 INDENT = ' ' |
23 | 24 |
24 INFER_CALLS = Summary('inference_infer_calls', 'calls') | 25 INFER_CALLS = Summary('inference_infer_calls', 'calls') |
469 log.debug(f'{INDENT*2}-applying rule {i}') | 470 log.debug(f'{INDENT*2}-applying rule {i}') |
470 log.debug(f'{INDENT*3} rule def lhs:') | 471 log.debug(f'{INDENT*3} rule def lhs:') |
471 for stmt in sorted(r.lhsGraph, reverse=True): | 472 for stmt in sorted(r.lhsGraph, reverse=True): |
472 log.debug(f'{INDENT*4} {stmt}') | 473 log.debug(f'{INDENT*4} {stmt}') |
473 log.debug(f'{INDENT*3} rule def rhs: {graphDump(r.rhsGraph)}') | 474 log.debug(f'{INDENT*3} rule def rhs: {graphDump(r.rhsGraph)}') |
474 | |
475 | |
476 def graphDump(g: Union[Graph, List[Triple]], oneLine=True): | |
477 # this is very slow- debug only! | |
478 if not log.isEnabledFor(logging.DEBUG): | |
479 return "(skipped dump)" | |
480 if not isinstance(g, Graph): | |
481 g2 = Graph() | |
482 g2 += g | |
483 g = g2 | |
484 g.bind('', ROOM) | |
485 g.bind('ex', Namespace('http://example.com/')) | |
486 lines = cast(bytes, g.serialize(format='n3')).decode('utf8').splitlines() | |
487 lines = [line for line in lines if not line.startswith('@prefix')] | |
488 if oneLine: | |
489 lines = [line.strip() for line in lines] | |
490 return ' '.join(lines) |