Commit 02cbb32f authored by Haj Rezvan's avatar Haj Rezvan

Complete functions

parent e63793e9
......@@ -67,27 +67,27 @@ def __double_quotation(i: int, query: list, dictionary: dict, finish: bool, doc_
while True: # Find end of "
selected = list()
length = len(query[i + 1])
if query[i][length - 1] == '"':
query[i + 1] = query[i + 1][0:length - 1]
if query[i + 1][len(query[i + 1]) - 1] == '"':
query[i + 1] = query[i + 1][0:len(query[i + 1]) - 1]
finish = True
# Find docID
for aP in range(0, len(dictionary[query[i]])):
# document ID
doc = list(dictionary[query[i]].keys())[aP] # Number of document in dictionary.
if dictionary[query[i + 1]].keys().__contains__(doc):
doc = list(dictionary[query[i]]).__getitem__(aP) # Number of document in dictionary.
if dictionary[query[i + 1]].__contains__(doc):
# Array of this word in the query.
presentPointer = dictionary[query[i]][doc]
# presentPointer = dictionary[query[i]][doc]
# Array of next word in query.
nextPointer = list()
for bP in range(0, len(dictionary[query[i + 1]][doc])): # Iterate from end to begin.
nextPointer.append(dictionary[query[i + 1]][doc].__getitem__(bP) - 1)
for bP in range(0, len(dictionary[query[i + 1]])): # Iterate from end to begin.
nextPointer.append(dictionary[query[i + 1]].__getitem__(bP) - 1)
# Position of documents.
for p in dictionary[query[i]][doc]:
if nextPointer.__contains__(dictionary[query[i]][doc].__getitem__(p)):
for p in range(0, len(dictionary[query[i]])):
if nextPointer.__contains__(dictionary[query[i]].__getitem__(p)):
selected.append(doc)
break
# intersect of documents.
......@@ -106,7 +106,7 @@ def __not(i: int, query: list, dictionary: dict, doc_id: list):
query[i] = query[i][1:length] # length of phrase query.
if dictionary.keys().__contains__(query[i]):
for term in range(0, file_numbers):
if not dictionary.keys().__contains__(query[term]):
if not dictionary[query[i]].__contains__(term):
selected.append(term)
else: # Not in dictionary.
......@@ -148,9 +148,11 @@ def __checker(query: str, dictionary: dict, size: int):
while i < size:
if query[i][0] == '"':
content = (__double_quotation(i, query, dictionary, finish, content))
lst_ctn[i] = content.copy()
elif query[i][0] == '!':
content = (__not(i, query, dictionary, content))
lst_ctn[i] = content.copy()
else:
content = __simple_check(i, query, dictionary, content)
lst_ctn[i] = content.copy()
......@@ -175,7 +177,6 @@ def enter(it: str):
split = it.split(" ")
size = len(split)
rs = __checker(it, dictionary, size)
out_list = list()
intersect = [set() for _ in range(size)]
i = 0
......@@ -185,13 +186,10 @@ def enter(it: str):
i = i + 1
break
for ls in rs:
for item in ls:
out_list.append(item)
rs = set.intersection(*intersect)
rs = list(set.intersection(*intersect))
rs.sort()
out_data = get_info(list(rs))
out_data = get_info(rs[0:10])
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