Ejemplo n.º 1
0
def runrive():
    bot = RiveScript(utf8=True)
    bot.load_directory('./mybrain')
    bot.sort_replies()
    while True:
        msg = input('You> ')
        if msg == 'q':
            break
        reply = bot.reply("localuser", msg)
        print('Bot>', reply)
    bot.deparse()
Ejemplo n.º 2
0
#!/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))
Ejemplo n.º 3
0
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)