-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatbot.py
28 lines (23 loc) · 1008 Bytes
/
chatbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python3
import argparse
import json
import gluply
from oracle import Oracle
# Parse arguments for the program
parser = argparse.ArgumentParser(description='Runs an English-speaking chatbot that answers questions about your website')
parser.add_argument('conf_file', metavar='JSON_FILE', type=str, help='Read parameters for the program')
# Under which mode will the app run. There is no default mode, you need to choose one
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--train', dest='train', action='store_true', help='Precalculates everything')
group.add_argument('--run', metavar='SENTENCE', type=str, help="Answers to the given input")
args = parser.parse_args()
# Time to read the program parameters
with open(args.conf_file) as f:
params = json.load(f)
if args.train:
print(params['bibtex'])
else:
parsed_input = gluply.read_input(args.run)
print(parsed_input)
chatbot = Oracle(params['bibtex'])
print(chatbot.ask(parsed_input))