本文整理汇总了Python中trie.Trie.add_phrases_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.add_phrases_from_file方法的具体用法?Python Trie.add_phrases_from_file怎么用?Python Trie.add_phrases_from_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.add_phrases_from_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Flask
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import add_phrases_from_file [as 别名]
from flask import Flask, render_template, request, redirect, url_for, make_response
from trie import Trie
app = Flask(__name__)
'''
Build a Trie using the appropriate data
'''
# t = Trie()
# t.add_words_from_file("stories.txt")
# t = Trie(low=True)
# t.add_words_from_file("chamber_of_secrets.txt")
t = Trie()
t.add_phrases_from_file("designers.txt")
t.add_phrases_from_file("dresses.txt")
'''
Get user input and request suggestions for autocomplete
'''
@app.route('/', methods=['GET', 'POST'])
def index():
word = request.args.get('word')
if word:
wordlist = t.show_matches(word)
# print wordlist
if wordlist == [''] or wordlist == []:
wordlist = ['No matches found']
return make_response(render_template('index.html', word=word, wordlist=wordlist))
else:
return render_template('index.html')