本文整理汇总了Python中haystack.utils.Highlighter.render_html方法的典型用法代码示例。如果您正苦于以下问题:Python Highlighter.render_html方法的具体用法?Python Highlighter.render_html怎么用?Python Highlighter.render_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haystack.utils.Highlighter
的用法示例。
在下文中一共展示了Highlighter.render_html方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_html
# 需要导入模块: from haystack.utils import Highlighter [as 别名]
# 或者: from haystack.utils.Highlighter import render_html [as 别名]
def test_render_html(self):
highlighter = Highlighter("this test")
highlighter.text_block = self.document_1
self.assertEqual(
highlighter.render_html({"this": [0, 53, 79], "test": [10, 68]}, 0, 200),
'<span class="highlighted">This</span> is a <span class="highlighted">test</span> of the highlightable words detection. <span class="highlighted">This</span> is only a <span class="highlighted">test</span>. Were <span class="highlighted">this</span> an actual emergency, your text would have exploded in mid-air.',
)
highlighter.text_block = self.document_2
self.assertEqual(
highlighter.render_html({"this": [0, 53, 79], "test": [10, 68]}, 0, 200),
"The content of words in no particular order causes nothing to occur.",
)
highlighter.text_block = self.document_3
self.assertEqual(
highlighter.render_html({"this": [0, 53, 79], "test": [10, 68]}, 0, 200),
'<span class="highlighted">This</span> is a <span class="highlighted">test</span> of the highlightable words detection. <span class="highlighted">This</span> is only a <span class="highlighted">test</span>. Were <span class="highlighted">this</span> an actual emergency, your text would have exploded in mid-air. The content of words in no particular order causes no...',
)
highlighter = Highlighter("content detection")
highlighter.text_block = self.document_3
self.assertEqual(
highlighter.render_html({"content": [151], "detection": [42]}, 42, 242),
'...<span class="highlighted">detection</span>. This is only a test. Were this an actual emergency, your text would have exploded in mid-air. The <span class="highlighted">content</span> of words in no particular order causes nothing to occur.',
)
self.assertEqual(
highlighter.render_html({"content": [151], "detection": [42]}, 42, 200),
'...<span class="highlighted">detection</span>. This is only a test. Were this an actual emergency, your text would have exploded in mid-air. The <span class="highlighted">content</span> of words in no particular order causes no...',
)
示例2: test_render_html
# 需要导入模块: from haystack.utils import Highlighter [as 别名]
# 或者: from haystack.utils.Highlighter import render_html [as 别名]
def test_render_html(self):
highlighter = Highlighter('this test')
highlighter.text_block = self.document_1
self.assertEqual(highlighter.render_html({'this': [0, 53, 79], 'test': [10, 68]}, 0, 200), '<span class="highlighted">This</span> is a <span class="highlighted">test</span> of the highlightable words detection. <span class="highlighted">This</span> is only a <span class="highlighted">test</span>. Were <span class="highlighted">this</span> an actual emergency, your text would have exploded in mid-air.')
highlighter.text_block = self.document_2
self.assertEqual(highlighter.render_html({'this': [0, 53, 79], 'test': [10, 68]}, 0, 200), 'The content of words in no particular order causes nothing to occur.')
highlighter.text_block = self.document_3
self.assertEqual(highlighter.render_html({'this': [0, 53, 79], 'test': [10, 68]}, 0, 200), '<span class="highlighted">This</span> is a <span class="highlighted">test</span> of the highlightable words detection. <span class="highlighted">This</span> is only a <span class="highlighted">test</span>. Were <span class="highlighted">this</span> an actual emergency, your text would have exploded in mid-air. The content of words in no particular order causes no...')
highlighter = Highlighter('content detection')
highlighter.text_block = self.document_3
self.assertEqual(highlighter.render_html({'content': [151], 'detection': [42]}, 42, 242), '...<span class="highlighted">detection</span>. This is only a test. Were this an actual emergency, your text would have exploded in mid-air. The <span class="highlighted">content</span> of words in no particular order causes nothing to occur.')
self.assertEqual(highlighter.render_html({'content': [151], 'detection': [42]}, 42, 200), '...<span class="highlighted">detection</span>. This is only a test. Were this an actual emergency, your text would have exploded in mid-air. The <span class="highlighted">content</span> of words in no particular order causes no...')
# Regression for repetition in the regular expression.
highlighter = Highlighter('i++')
highlighter.text_block = 'Foo is i++ in most cases.'
self.assertEqual(highlighter.render_html({'i++': [7]}, 0, 200), 'Foo is <span class="highlighted">i++</span> in most cases.')
highlighter = Highlighter('i**')
highlighter.text_block = 'Foo is i** in most cases.'
self.assertEqual(highlighter.render_html({'i**': [7]}, 0, 200), 'Foo is <span class="highlighted">i**</span> in most cases.')
highlighter = Highlighter('i..')
highlighter.text_block = 'Foo is i.. in most cases.'
self.assertEqual(highlighter.render_html({'i..': [7]}, 0, 200), 'Foo is <span class="highlighted">i..</span> in most cases.')
highlighter = Highlighter('i??')
highlighter.text_block = 'Foo is i?? in most cases.'
self.assertEqual(highlighter.render_html({'i??': [7]}, 0, 200), 'Foo is <span class="highlighted">i??</span> in most cases.')