mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-19 08:12:09 +00:00
Librarian side fix
This commit is contained in:
@@ -2,13 +2,13 @@ from queue import Queue, Empty
|
||||
from threading import Thread
|
||||
q = Queue()
|
||||
|
||||
MAXTHREADS = 39
|
||||
#MAXTHREADS = 4
|
||||
#MAXTHREADS = 39
|
||||
MAXTHREADS = 4
|
||||
DATABASE_PATH = r'C:\\Database\\chunks_1\\'
|
||||
ENCODING = "utf-8"
|
||||
CHUNk = "_chunk.txt"
|
||||
_sentinel = object()
|
||||
|
||||
result_list = []
|
||||
#TODO: Doisy wchodzą jako lista krotek (doi, False) - po znalezieniu zaznaczamy na True i potem już nie porównujemy
|
||||
#TODO: lista krotek - jeśli wszystkie mają True dajemy terma
|
||||
|
||||
@@ -35,15 +35,23 @@ def producer(out_q, control_q, filename):
|
||||
#TODO: Change doi to tuple list and only put term when all doi are found => (doi, True)
|
||||
def consumer(in_q, control_q, doi):
|
||||
sentinels = 0
|
||||
for item in doi:
|
||||
result_list.append({"DOI" : item[0], "exists" : False, "data" : item[1]})
|
||||
while True:
|
||||
done_check = True
|
||||
data = in_q.get()
|
||||
if data is _sentinel:
|
||||
print("Worker finished")
|
||||
sentinels += 1
|
||||
elif doi in data:
|
||||
control_q.put(_sentinel)
|
||||
print(data)
|
||||
print("HIT")
|
||||
else:
|
||||
for item in result_list:
|
||||
if item["DOI"] in data:
|
||||
print(data)
|
||||
print("HIT")
|
||||
item["exists"] = True
|
||||
done_check = done_check and item["exists"]
|
||||
if done_check:
|
||||
control_q.put(_sentinel)
|
||||
if sentinels >= MAXTHREADS:
|
||||
print("All workers finished")
|
||||
break
|
||||
@@ -51,31 +59,29 @@ def consumer(in_q, control_q, doi):
|
||||
|
||||
def search_for_doi(doi):
|
||||
threads = []
|
||||
work_q = Queue(maxsize=10000000)
|
||||
work_q = Queue(maxsize=100)
|
||||
control_q = Queue()
|
||||
t_cons = Thread(target = consumer, args = (work_q, control_q, doi))
|
||||
threads.append(t_cons)
|
||||
for i in range(0,MAXTHREADS):
|
||||
#filename = "test" + str(i) + CHUNk
|
||||
filename = "test" + str(i) + CHUNk
|
||||
filename = str(i) + CHUNk
|
||||
print(filename)
|
||||
#print(filename)
|
||||
threads.append(Thread(target = producer, args = (work_q, control_q, filename)))
|
||||
for worker in threads:
|
||||
worker.start()
|
||||
for worker in threads:
|
||||
worker.join()
|
||||
|
||||
try:
|
||||
check = control_q.get(block=False)
|
||||
control_q.put(check)
|
||||
return True
|
||||
except Empty:
|
||||
return False
|
||||
|
||||
return result_list
|
||||
if __name__ == "__main__":
|
||||
if search_for_doi("10.1002/9781118786352.wbieg0998.pub2"):
|
||||
#if search_for_doi("10.1108/gm-02-2016-0025xx"):
|
||||
print("found")
|
||||
exit()
|
||||
else:
|
||||
print("Not found")
|
||||
print(search_for_doi([
|
||||
("10.1002/9781118786352.wbieg0998.pub2","DATA"),
|
||||
("10.1002/j.2050-0416.2002.tb00563.x","DATA"),
|
||||
("10.1111/j.1365-2958.1994.tb00448.x","DATA"),
|
||||
("10.2165/00128415-200309690-00017","DATA"),
|
||||
("10.5772/48313","DATA"),
|
||||
("10.15803/ijnc.7.2_419","DATA"),
|
||||
("10.1051/0004-6361/201321596e","DATA"),
|
||||
("10.2307/40835941","DATA"),
|
||||
]))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user