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