当前位置: 首页>>代码示例>>Python>>正文


Python highlight.HtmlFormatter方法代码示例

本文整理汇总了Python中whoosh.highlight.HtmlFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python highlight.HtmlFormatter方法的具体用法?Python highlight.HtmlFormatter怎么用?Python highlight.HtmlFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在whoosh.highlight的用法示例。


在下文中一共展示了highlight.HtmlFormatter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_html_format

# 需要导入模块: from whoosh import highlight [as 别名]
# 或者: from whoosh.highlight import HtmlFormatter [as 别名]
def test_html_format():
    terms = frozenset(("bravo", "india"))
    sa = analysis.StandardAnalyzer()
    cf = highlight.ContextFragmenter(surround=6)
    hf = highlight.HtmlFormatter()
    htext = highlight.highlight(_doc, terms, sa, cf, hf)
    assert htext == 'alfa <strong class="match term0">bravo</strong> charlie...hotel <strong class="match term1">india</strong> juliet' 
开发者ID:securesystemslab,项目名称:zippy,代码行数:9,代码来源:test_highlighting.py

示例2: test_html_escape

# 需要导入模块: from whoosh import highlight [as 别名]
# 或者: from whoosh.highlight import HtmlFormatter [as 别名]
def test_html_escape():
    terms = frozenset(["bravo"])
    sa = analysis.StandardAnalyzer()
    wf = highlight.WholeFragmenter()
    hf = highlight.HtmlFormatter()
    htext = highlight.highlight(u('alfa <bravo "charlie"> delta'), terms, sa,
                                wf, hf)
    assert htext == 'alfa &lt;<strong class="match term0">bravo</strong> "charlie"&gt; delta' 
开发者ID:securesystemslab,项目名称:zippy,代码行数:10,代码来源:test_highlighting.py

示例3: test_maxclasses

# 需要导入模块: from whoosh import highlight [as 别名]
# 或者: from whoosh.highlight import HtmlFormatter [as 别名]
def test_maxclasses():
    terms = frozenset(("alfa", "bravo", "charlie", "delta", "echo"))
    sa = analysis.StandardAnalyzer()
    cf = highlight.ContextFragmenter(surround=6)
    hf = highlight.HtmlFormatter(tagname="b", termclass="t", maxclasses=2)
    htext = highlight.highlight(_doc, terms, sa, cf, hf)
    assert htext == '<b class="match t0">alfa</b> <b class="match t1">bravo</b> <b class="match t0">charlie</b>...<b class="match t1">delta</b> <b class="match t0">echo</b> foxtrot' 
开发者ID:securesystemslab,项目名称:zippy,代码行数:9,代码来源:test_highlighting.py

示例4: test_query_highlight

# 需要导入模块: from whoosh import highlight [as 别名]
# 或者: from whoosh.highlight import HtmlFormatter [as 别名]
def test_query_highlight():
    qp = QueryParser("a", None)
    hf = highlight.HtmlFormatter()

    def do(text, terms):
        q = qp.parse(text)
        tks = [tk for tk in q.all_tokens() if tk.text in terms]
        for tk in tks:
            if tk.startchar is None or tk.endchar is None:
                assert False, tk
        fragment = highlight.Fragment(text, tks)
        return hf.format_fragment(fragment)

    assert do("a b c d", ["b"]) == 'a <strong class="match term0">b</strong> c d'
    assert do('a (x:b OR y:"c d") e', ("b", "c")) == 'a (x:<strong class="match term0">b</strong> OR y:"<strong class="match term1">c</strong> d") e' 
开发者ID:securesystemslab,项目名称:zippy,代码行数:17,代码来源:test_spelling.py

示例5: test_correct_query

# 需要导入模块: from whoosh import highlight [as 别名]
# 或者: from whoosh.highlight import HtmlFormatter [as 别名]
def test_correct_query():
    schema = fields.Schema(a=fields.TEXT(spelling=True), b=fields.TEXT)
    ix = RamStorage().create_index(schema)
    w = ix.writer()
    w.add_document(a=u("alfa bravo charlie delta"))
    w.add_document(a=u("delta echo foxtrot golf"))
    w.add_document(a=u("golf hotel india juliet"))
    w.add_document(a=u("juliet kilo lima mike"))
    w.commit()

    s = ix.searcher()
    qp = QueryParser("a", ix.schema)
    qtext = u('alpha ("brovo november" OR b:dolta) detail')
    q = qp.parse(qtext, ix.schema)

    c = s.correct_query(q, qtext)
    assert c.query.__unicode__() == '(a:alfa AND (a:"bravo november" OR b:dolta) AND a:detail)'
    assert c.string == 'alfa ("bravo november" OR b:dolta) detail'

    qtext = u('alpha b:("brovo november" a:delta) detail')
    q = qp.parse(qtext, ix.schema)
    c = s.correct_query(q, qtext)
    assert c.query.__unicode__() == '(a:alfa AND b:"brovo november" AND a:delta AND a:detail)'
    assert c.string == 'alfa b:("brovo november" a:delta) detail'

    hf = highlight.HtmlFormatter(classname="c")
    assert c.format_string(hf) == '<strong class="c term0">alfa</strong> b:("brovo november" a:delta) detail' 
开发者ID:securesystemslab,项目名称:zippy,代码行数:29,代码来源:test_spelling.py

示例6: highlight

# 需要导入模块: from whoosh import highlight [as 别名]
# 或者: from whoosh.highlight import HtmlFormatter [as 别名]
def highlight(self, text, words):
        fragmenter = ContextFragmenter()
        formatter = HtmlFormatter()
        analyzer = self.project_schema['text'].analyzer
        return highlight(text, words, analyzer, fragmenter, formatter, top=1) 
开发者ID:devpi,项目名称:devpi,代码行数:7,代码来源:whoosh_index.py


注:本文中的whoosh.highlight.HtmlFormatter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。