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


Python RiveScript.deparse方法代码示例

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


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

示例1: RiveScript

# 需要导入模块: from rivescript import RiveScript [as 别名]
# 或者: from rivescript.RiveScript import deparse [as 别名]
#!/usr/bin/env python

# Manipulate sys.path to be able to import rivescript from this local git
# repository.
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))

from rivescript import RiveScript
import json

bot = RiveScript()
bot.load_file("example.rive")

dep = bot.deparse()
print(json.dumps(dep, indent=2))
开发者ID:aichaos,项目名称:rivescript-python,代码行数:18,代码来源:example.py

示例2: RiveScript

# 需要导入模块: from rivescript import RiveScript [as 别名]
# 或者: from rivescript.RiveScript import deparse [as 别名]
import sys
import os
import json
from rivescript import RiveScript
bot = RiveScript(utf8=True)
bot.load_file(sys.argv[1])
bot.sort_replies()
deparsed = bot.deparse()
full_dump = {"sub_clause": [], "array_clauses": [], "include_clauses": [], "raw_rule_clauses": []}
for raw_rule_topic in deparsed["topic"].keys():
  for raw_rule_key in deparsed["topic"][raw_rule_topic].keys():
    raw_rule = {"topic": raw_rule_topic, "name": raw_rule_key, "reply": [], "condition": [], "previous": []}
    if "reply" in deparsed["topic"][raw_rule_topic][raw_rule_key].keys():
      for reply in deparsed["topic"][raw_rule_topic][raw_rule_key]["reply"]:
        raw_rule["reply"].append(reply)
    if "condition" in deparsed["topic"][raw_rule_topic][raw_rule_key].keys():
      for reply in deparsed["topic"][raw_rule_topic][raw_rule_key]["condition"]:
        raw_rule["condition"].append(reply)
    if "previous" in deparsed["topic"][raw_rule_topic][raw_rule_key].keys():
      raw_rule["previous"].append(deparsed["topic"][raw_rule_topic][raw_rule_key]["previous"])
    full_dump["raw_rule_clauses"].append(raw_rule)

for raw_rule_topic in deparsed["that"].keys():
  for raw_rule_key in deparsed["that"][raw_rule_topic].keys():
    raw_rule = {"topic": raw_rule_topic, "name": raw_rule_key, "reply": [], "condition": [], "previous": []}
    if "reply" in deparsed["that"][raw_rule_topic][raw_rule_key].keys():
      for reply in deparsed["that"][raw_rule_topic][raw_rule_key]["reply"]:
        raw_rule["reply"].append(reply)
    if "condition" in deparsed["that"][raw_rule_topic][raw_rule_key].keys():
      for reply in deparsed["that"][raw_rule_topic][raw_rule_key]["condition"]:
        raw_rule["condition"].append(reply)
开发者ID:degaph,项目名称:goo,代码行数:33,代码来源:rive_parser.py


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