-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsnet_test_client.py
122 lines (69 loc) · 2.54 KB
/
snet_test_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Tested on python3.6
import logging
import os
import pathlib
import json
import csv
import numpy as np
import grpc
from service_spec import topic_analysis_pb2, topic_analysis_pb2_grpc
import subprocess
def sample_data():
path = str(pathlib.Path(os.path.abspath('')).parents[0])+'/appData/misc/extracted.json'
docs = []
with open(path, "r") as read_file:
fileList = json.load(read_file)
for k in fileList:
docs.append(fileList[k])
return docs
def sample_data_2():
path = str(pathlib.Path(os.path.abspath('')).parents[0])+'/topic-analysis/docs/tests/test_doc_2.txt'
docs = []
with open(path, "r") as read_file:
text = read_file.read().splitlines()
for k in text:
if k != "":
docs.append(k)
return docs
def csv_reader():
path = str(pathlib.Path(os.path.abspath('')).parents[0]) + '/appData/misc/topic-by-doc-matirx.csv'
resp = []
with open(path) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
docs_list = next(csv_reader)
print(docs_list[1:])
for row in csv_reader:
print('^^^^^^^^^^^^^^^^^^^^^^^^^^')
print(len(row))
# print(row[1:])
resp.append(list((np.array(row[1:])).astype(np.float)))
print('`````````````````````````````````')
print(resp)
def try_plsa():
channel = grpc.insecure_channel('localhost:5001')
# channel = grpc.insecure_channel('172.17.0.75:5001')
stub = topic_analysis_pb2_grpc.TopicAnalysisStub(channel)
plsa_request = topic_analysis_pb2.PLSARequest(docs=sample_data(),num_topics=2,maxiter=22,beta=1)
resp = stub.PLSA(plsa_request)
print(resp.status)
print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
print(resp.message)
print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
print(resp.handle)
def try_plsa_2():
channel = grpc.insecure_channel('localhost:5000')
# channel = grpc.insecure_channel('172.17.1.53:5001')
# channel = grpc.insecure_channel('172.17.0.75:5001')
stub = topic_analysis_pb2_grpc.TopicAnalysisStub(channel)
plsa_request = topic_analysis_pb2.PLSARequest(docs=sample_data_2(),num_topics=2,maxiter=22,beta=1)
resp = stub.PLSA(plsa_request)
print(resp.status)
print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
print(resp.message)
print('^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^')
print(resp.handle)
if __name__ == '__main__':
# try_plsa()
# print(sample_data_2())
try_plsa_2()
# csv_reader()