Allow kwargs to be passed to pretty printers pprint_entity and pprint_text
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 27 Jun 2013 17:02:30 +0200
changeset 336 45c21dd506eb
parent 335 601731a76796
child 337 500ad60dd86a
Allow kwargs to be passed to pretty printers pprint_entity and pprint_text This makes overloading easier (i.e. add custom link attributes)
dataio.py
--- a/dataio.py	Wed Jun 26 15:27:20 2013 +0200
+++ b/dataio.py	Thu Jun 27 17:02:30 2013 +0200
@@ -80,7 +80,7 @@
     """ Pretty print the output of a Nerdy process
     """
 
-    def pprint_text(self, text, named_entities):
+    def pprint_text(self, text, named_entities, **kwargs):
         newtext = u''
         indice = 0
         tindices = dict([(t.start, (uri, t)) for uri, p, t in named_entities])
@@ -88,7 +88,7 @@
             if indice in tindices:
                 uri, t = tindices[indice]
                 words = text[t.start:t.end]
-                fragment = self.pprint_entity(uri, words)
+                fragment = self.pprint_entity(uri, words, **kwargs)
                 if not self.is_valid(newtext+fragment+text[t.end:]):
                     fragment = words
                 newtext += fragment
@@ -98,7 +98,7 @@
                 indice += 1
         return newtext
 
-    def pprint_entity(self, uri, word):
+    def pprint_entity(self, uri, word, **kwargs):
         """ Pretty print an entity """
         raise NotImplementedError
 
@@ -112,7 +112,7 @@
     """ Pretty print the output of a Nerdy process
     """
 
-    def pprint_entity(self, uri, word):
+    def pprint_entity(self, uri, word, **kwargs):
         """ Pretty print an entity """
         return u'<a href="%s">%s</a>' % (uri, word)