-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
99 lines (73 loc) · 2.56 KB
/
test.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May 12 18:46:37 2021
@author: cbadenes
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 10 11:32:27 2021
@author: cbadenes
"""
import worker.test as worker
import pysolr
import multiprocessing as mp
import time
import json
import requests
def get_content(url):
content = {}
try:
response = requests.get(url)
content = response.json()
except:
print("Error getting from url: ",url)
return content
if __name__ == '__main__':
print("reading test documents..")
solr = pysolr.Solr('http://librairy.linkeddata.es/data/mesinesp', always_commit=True, timeout=50)
# print report
f = open('../results/test-results.json', mode='w')
print("Number of processors: ", mp.cpu_count())
pool = mp.Pool(6)
print("reading from solr..")
counter = 0
completed = False
window_size=200
cursor = "*"
level0_result = {}
level0_result.setdefault('documents',[])
level1_result = {}
level1_result.setdefault('documents',[])
level2_result = {}
level2_result.setdefault('documents',[])
while (not completed):
old_counter = counter
solr_query="scope_s:Test"
try:
articles = solr.search(q=solr_query,rows=window_size,cursorMark=cursor,sort="id asc")
cursor = articles.nextCursorMark
results = pool.map(workers.test,articles.docs)
for result in results:
doc0 = { 'id':result['id'], 'labels':result['labels0']}
level0_result.append(doc0)
doc1 = { 'id':result['id'], 'labels':result['labels1']}
level1_result.append(doc1)
doc2 = { 'id':result['id'], 'labels':result['labels2']}
level2_result.append(doc2)
counter += len(results)
print(counter,"docs evaluated")
if (old_counter == counter):
print("done!")
break
except:
print("Solr query error. Wait for 5secs..")
time.sleep(5.0)
print("writing json files...")
with open("../results/test_level0.json", "w") as write_file:
json.dump(level0_result, write_file)
with open("../results/test_level1.json", "w") as write_file:
json.dump(level1_result, write_file)
with open("../results/test_level2.json", "w") as write_file:
json.dump(level2_result, write_file)