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


Python Markov.tokenize_text方法代码示例

本文整理汇总了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()
开发者ID:wlstrickland,项目名称:botty-bot-bot-bot,代码行数:32,代码来源:generate_chains_db.py


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