# coding: utf-8
-import yaml
+#import yaml
+import json
import collections
import random
'me': 'you',
'my': 'your',
'mine': 'yours',
- 'am': 'are'
+ 'am': 'are',
+ 'you': 'i',
+ 'your': 'my',
+ 'yours': 'mine'
}
+halt_words = 'quit halt exit stop'.split()
+
+# def read_rules(rules_file):
+# with open(rules_file) as f:
+# rules = [{'pattern': r['pattern'].split(),
+# 'responses': [t.split() for t in r['responses']]}
+# for r in yaml.safe_load(f)]
+# return rules
+
def read_rules(rules_file):
with open(rules_file) as f:
rules = [{'pattern': r['pattern'].split(),
'responses': [t.split() for t in r['responses']]}
- for r in yaml.load(f)]
+ for r in json.load(f)]
return rules
def is_var(word):
print("Hello. I'm Eliza. What seems to be the problem?")
while True:
c = input("> ")
- if c.strip() in 'quit halt exit stop'.split(): break
+ if c.strip() in halt_words: break
comment = c.split()
rule, bindings = candidate_rules(rules, comment)[0]
swapped_bindings = pronoun_person_swap(bindings)
print(' '.join(respond(rule, swapped_bindings)))
-all_rules = read_rules('rules.yaml')
+all_rules = read_rules('rules.json')
eliza_loop(all_rules)