Commit d3bb5264 authored by Haj Rezvan's avatar Haj Rezvan

Add Subtract operator and write logs in other thread.

parent 0580e7f7
import json
import threading
def subtract(a, b):
return [*(item for item in a if item not in b)]
def union_two(a, b):
......@@ -39,7 +44,6 @@ def normalize_list(lst):
def union(inp):
n = len(inp)
vl = None
vl = normalize_list(inp)
while n >= 2:
if n == 2:
......@@ -93,12 +97,13 @@ def get_info(inp):
def write_logs(string):
file = open(f"./logs/log.txt", "a", encoding="utf-8")
file.write(string)
file.write(string + "\n")
file.close()
def enter(it):
write_logs(it)
t1 = threading.Thread(target=write_logs, args=(it,))
t1.start()
spl = list(it.split(" "))
file = open("./index/ii.json", "r", encoding="utf-8")
index = json.load(file)
......@@ -111,22 +116,32 @@ def enter(it):
ld = dict()
for i in range(len(rs)):
ld[rs[i]] = index.get(rs[i])
print(ld[rs[i]])
ld_copy = ld.copy()
opt = list()
if len(rs) > 1:
flag = operations(spl)
while len(flag) > 0:
if "&" in flag:
_and = spl.index("AND")
opt.append(intersect(ld[spl[_and + 1]], ld[spl[_and - 1]]))
nxt_word = spl[_and + 1]
prv_word = spl[_and - 1]
opt.extend(intersect(ld[nxt_word], ld[prv_word]))
spl.pop(_and)
ld.pop(nxt_word)
ld.pop(prv_word)
ld["opt"] = opt
flag = operations(spl)
elif "!" in flag:
_not = spl.index("NOT")
nxt_word = spl[_not + 1]
prv_word = spl[_not - 1]
opt = subtract(ld[prv_word], ld[nxt_word])
print(opt)
spl.pop(_not)
flag = operations(spl)
pass
out_data = get_info(ld)
t1.join()
return out_data
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment