-
Notifications
You must be signed in to change notification settings - Fork 132
/
correct_client.py
executable file
·59 lines (45 loc) · 1.33 KB
/
correct_client.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
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
#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
import os
import time
import threading
import socket
import sys
# Server Side Configuration
#HOST = "192.168.1.163"
HOST = "127.0.0.1"
PORT = 10244
def correct_me(str_test):
if not str_test:
return None
sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sk.connect((HOST, PORT))
req_url = {'CLIENT':7789,'TYPE':'REQ_COR','DATA':str_test}
jreq_url = repr(req_url) + ','
sk.sendall((jreq_url).encode())
# 等待服务器返回
try:
rep_url = sk.recv(1024).decode()
except Exception as e:
print("Socket Error:", str(e))
return None
finally:
# 关闭,节约资源
sk.close()
if not rep_url:
print("服务器处理失败!")
return None
else:
jrep_url = eval(rep_url)[0]
if jrep_url and jrep_url['CLIENT'] == 7789 and jrep_url['TYPE'] == 'REP_COR':
return (jrep_url['DATA'])
if __name__ == '__main__':
if len(sys.argv) > 1:
for i in range(1, len(sys.argv)):
print("原语句:" + sys.argv[i])
print("纠正句:" + correct_me(sys.argv[i]))
else:
str_test = "对京东新人度大打折扣"
print("原语句:" + str_test)
print("纠正句:" + correct_me(str_test))