Mercurial > code > home > repos > homeauto
diff service/mqtt_to_rdf/rdflib_debug_patches.py @ 1671:2b905c07e82b
try a bnode test mode improvement, but it's not so useful if you parse graphs with reused bnodes in them
author | drewp@bigasterisk.com |
---|---|
date | Tue, 21 Sep 2021 23:21:38 -0700 |
parents | 82ddd3e6b227 |
children | 37710d28890b |
line wrap: on
line diff
--- a/service/mqtt_to_rdf/rdflib_debug_patches.py Tue Sep 21 23:20:41 2021 -0700 +++ b/service/mqtt_to_rdf/rdflib_debug_patches.py Tue Sep 21 23:21:38 2021 -0700 @@ -37,14 +37,18 @@ rdflib.term.Variable.__repr__ = vr -def patchBnodeCounter(): - """From: rdflib.terms.BNode('ne7bb4a51624993acdf51cc5d4e8add30e1' +def patchBnodeCounter(always=False): + """From: rdflib.terms.BNode('ne7bb4a51624993acdf51cc5d4e8add30e1' To: BNode('f-6-1') + + BNode creation can override this, which might matter when adding BNodes that + are known to be the same as each other. Set `always` to disregard this and + always get short ids. """ serial = itertools.count() def n(cls, value=None, _sn_gen='', _prefix='') -> BNode: - if value is None: + if always or value is None: value = 'N-%s' % next(serial) return rdflib.term.Identifier.__new__(cls, value)