本文整理匯總了Python中markov.Markov.tokenize_text方法的典型用法代碼示例。如果您正苦於以下問題:Python Markov.tokenize_text方法的具體用法?Python Markov.tokenize_text怎麽用?Python Markov.tokenize_text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類markov.Markov
的用法示例。
在下文中一共展示了Markov.tokenize_text方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: server_text_to_sendable_text
# 需要導入模塊: from markov import Markov [as 別名]
# 或者: from markov.Markov import tokenize_text [as 別名]
return server_text_to_sendable_text(message["message"]["text"])
return None
connection = sqlite3.connect(SQLITE_DATABASE)
connection.execute("DROP TABLE IF EXISTS counts")
connection.execute("DROP TABLE IF EXISTS chain")
connection.execute("CREATE TABLE counts (key TEXT PRIMARY KEY, count INTEGER)")
connection.execute("CREATE TABLE chain (key TEXT, next_word TEXT, occurrences INTEGER)")
connection.execute("CREATE INDEX chain_key_index ON chain (key)")
markov = Markov(2) # Markov model with 2 word look-behind
for channel_name, history_file in get_history_files().items():
with open(history_file, "r") as f:
for entry in f:
text = get_message_text(json.loads(entry))
if text is not None:
markov.train(Markov.tokenize_text(sendable_text_to_text(text)))
connection.executemany(
"INSERT INTO counts VALUES (?, ?)",
(("\n".join(key), occurrences) for key, occurrences in markov.counts.items())
)
connection.executemany(
"INSERT INTO chain VALUES (?, ?, ?)",
(("\n".join(key), next_word, occurrences) for key, next_mapping in markov.chain.items()
for next_word, occurrences in next_mapping.items())
)
connection.commit()
connection.close()