This repository has been archived by the owner on Aug 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client
executable file
·79 lines (60 loc) · 2.02 KB
/
client
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
import sys
import click
import requests
host = 'localhost'
port = '5000'
@click.command()
@click.option('-l', help='Gurobi license key.')
@click.option('-s', type=click.Path(exists=True),
help='File containing a sentence.')
@click.option('-p', type=click.Path(exists=True),
help='File containing a parsed sentence.')
@click.option('-k', type=click.Path(exists=True),
help='File containing a knowledge base.')
@click.option('-q', is_flag=True,
help='Quiet; do not print link for proof graph.')
@click.argument('sent', nargs=-1, metavar='<sentence>')
def main(l, s, p, k, q, sent):
"""Interpret a sentence or a parsed sentence. Sentences can be read
from a file (-s) or passed as the argument <sentence>. Parses must be read
from a file (-p)."""
if l:
query = {'license': l}
r = requests.post('http://' + host + ':' + port + '/license',
json=query)
if not r:
sys.stderr.write('Error receiving response from server.\n')
sys.exit(1)
print(r.json()['response'])
if not s and not p and not k and not sent:
sys.exit()
query = {}
if k:
query['kb'] = open(k).read()
if sent:
query['s'] = ' '.join(sent)
elif s:
query['s'] = open(s).read()
elif p:
query['p'] = open(p).read()
r = requests.post('http://' + host + ':' + port + '/interpret', json=query)
if not r:
sys.stderr.write('Error receiving response from server.\n')
sys.exit(1)
response = r.json()
if 'parse' in response and not p:
print('Parse:')
print(response['parse'])
if 'interpret' in response:
print('Interpret:')
print(response['interpret'])
if 'graph' in response and not q:
print()
print('Proof graph URL:')
print(response['graph'])
if 'error' in response:
print('Error:')
print(response['error'])
if __name__ == '__main__':
main()