Add a class attribute to HTML pprint_entity
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 27 Jun 2013 18:40:53 +0200
changeset 337 500ad60dd86a
parent 336 45c21dd506eb
child 338 d019dae05df4
Add a class attribute to HTML pprint_entity
dataio.py
test/test_dataio.py
--- a/dataio.py	Thu Jun 27 17:02:30 2013 +0200
+++ b/dataio.py	Thu Jun 27 18:40:53 2013 +0200
@@ -114,7 +114,8 @@
 
     def pprint_entity(self, uri, word, **kwargs):
         """ Pretty print an entity """
-        return u'<a href="%s">%s</a>' % (uri, word)
+        klass = ' class="%s"' % kwargs['html_class'] if 'html_class' in kwargs else ''
+        return u'<a href="%s"%s>%s</a>' % (uri, klass, word)
 
 
 class NerdyValidXHTMLPrettyPrint(NerdyHTMLPrettyPrint):
--- a/test/test_dataio.py	Thu Jun 27 17:02:30 2013 +0200
+++ b/test/test_dataio.py	Thu Jun 27 18:40:53 2013 +0200
@@ -53,6 +53,18 @@
                                 u'this is   <a href="http://example.com/me">me</a> speaking. '
                                 u'And <a href="http://example.com/me">me</a>.'))
 
+    def test_prettyprint_class(self):
+        text = 'Hello everyone, this is   me speaking. And me.'
+        source = core.NerdySourceLexical({'everyone': 'http://example.com/everyone',
+                                          'me': 'http://example.com/me'})
+        nerdy = core.NerdyProcess((source,))
+        named_entities = nerdy.process_text(text)
+        html = dataio.NerdyHTMLPrettyPrint().pprint_text(text, named_entities, html_class='ner')
+        self.assertEqual(html, (u'Hello <a href="http://example.com/everyone" class="ner">everyone</a>, '
+                                u'this is   <a href="http://example.com/me" class="ner">me</a> speaking. '
+                                u'And <a href="http://example.com/me" class="ner">me</a>.'))
+
+
 class NerdyValidXHTMLPrettyPrintTest(unittest2.TestCase):
 
     def test_valid(self):