當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。