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