# This code generates a dictionary with the query id as it's key and it's top 100 documents
# generated by bm25 model, which does not consider the relevance judgement, as it's corresponding value

import pickle
import os

# make the directory if it doesn't exist already
newpath = r'../../Encoded Data Structures (Phase 3)/'
if not os.path.exists(newpath):
    os.makedirs(newpath)


path = r'../../../Phase 1/Task 1/Encoded Data Structures/Encoded-BM25-NoRelevance-Top100Docs-perQuery'
queryID_top100Docs = {}                          # dictionary to store query id as key and it's corresponding
                                                 # top 100 documents as it's value
for file in os.listdir(path):
    doc_bm25Score = {}
    current_file = os.path.join(path,file)
    string = current_file.split("Encoded-Top100Docs-BM25-NoRelevance_")
    id = string[1].split(".")[0]                 # gives the query id, example: id =1, id = 2, etc.
    with open(current_file, 'rb') as f:
        doc_bm25Score = pickle.loads(f.read())
    all_docs = list(doc_bm25Score.keys())
    top_100_docs = all_docs[:100]                # gets the top 100 documents
    queryID_top100Docs[id] = top_100_docs

# write the dictionary to a file, in encoded format using pickle library of python
output = open(newpath + 'Encoded-QueryID_Top100Docs_BM25_NoRelevance.txt', 'wb')
pickle.dump(queryID_top100Docs, output)
output.close()

b5719fb5981f14de33d5c7873df957aeeba18247
<mask token>

<mask token>
if not os.path.exists(newpath):
    os.makedirs(newpath)
<mask token>
for file in os.listdir(path):
    doc_bm25Score = {}
    current_file = os.path.join(path, file)
    string = current_file.split('Encoded-Top100Docs-BM25-NoRelevance_')
    id = string[1].split('.')[0]
    with open(current_file, 'rb') as f:
        doc_bm25Score = pickle.loads(f.read())
    all_docs = list(doc_bm25Score.keys())
    top_100_docs = all_docs[:100]
    queryID_top100Docs[id] = top_100_docs
<mask token>
pickle.dump(queryID_top100Docs, output)
output.close()

<mask token>
newpath = '../../Encoded Data Structures (Phase 3)/'
if not os.path.exists(newpath):
    os.makedirs(newpath)
path = (
    '../../../Phase 1/Task 1/Encoded Data Structures/Encoded-BM25-NoRelevance-Top100Docs-perQuery'
    )
queryID_top100Docs = {}
for file in os.listdir(path):
    doc_bm25Score = {}
    current_file = os.path.join(path, file)
    string = current_file.split('Encoded-Top100Docs-BM25-NoRelevance_')
    id = string[1].split('.')[0]
    with open(current_file, 'rb') as f:
        doc_bm25Score = pickle.loads(f.read())
    all_docs = list(doc_bm25Score.keys())
    top_100_docs = all_docs[:100]
    queryID_top100Docs[id] = top_100_docs
output = open(newpath + 'Encoded-QueryID_Top100Docs_BM25_NoRelevance.txt', 'wb'
    )
pickle.dump(queryID_top100Docs, output)
output.close()

import pickle
import os
newpath = '../../Encoded Data Structures (Phase 3)/'
if not os.path.exists(newpath):
    os.makedirs(newpath)
path = (
    '../../../Phase 1/Task 1/Encoded Data Structures/Encoded-BM25-NoRelevance-Top100Docs-perQuery'
    )
queryID_top100Docs = {}
for file in os.listdir(path):
    doc_bm25Score = {}
    current_file = os.path.join(path, file)
    string = current_file.split('Encoded-Top100Docs-BM25-NoRelevance_')
    id = string[1].split('.')[0]
    with open(current_file, 'rb') as f:
        doc_bm25Score = pickle.loads(f.read())
    all_docs = list(doc_bm25Score.keys())
    top_100_docs = all_docs[:100]
    queryID_top100Docs[id] = top_100_docs
output = open(newpath + 'Encoded-QueryID_Top100Docs_BM25_NoRelevance.txt', 'wb'
    )
pickle.dump(queryID_top100Docs, output)
output.close()

# This code generates a dictionary with the query id as it's key and it's top 100 documents
# generated by bm25 model, which does not consider the relevance judgement, as it's corresponding value

import pickle
import os

# make the directory if it doesn't exist already
newpath = r'../../Encoded Data Structures (Phase 3)/'
if not os.path.exists(newpath):
    os.makedirs(newpath)


path = r'../../../Phase 1/Task 1/Encoded Data Structures/Encoded-BM25-NoRelevance-Top100Docs-perQuery'
queryID_top100Docs = {}                          # dictionary to store query id as key and it's corresponding
                                                 # top 100 documents as it's value
for file in os.listdir(path):
    doc_bm25Score = {}
    current_file = os.path.join(path,file)
    string = current_file.split("Encoded-Top100Docs-BM25-NoRelevance_")
    id = string[1].split(".")[0]                 # gives the query id, example: id =1, id = 2, etc.
    with open(current_file, 'rb') as f:
        doc_bm25Score = pickle.loads(f.read())
    all_docs = list(doc_bm25Score.keys())
    top_100_docs = all_docs[:100]                # gets the top 100 documents
    queryID_top100Docs[id] = top_100_docs

# write the dictionary to a file, in encoded format using pickle library of python
output = open(newpath + 'Encoded-QueryID_Top100Docs_BM25_NoRelevance.txt', 'wb')
pickle.dump(queryID_top100Docs, output)
output.close()
