Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In the Python console run indexing_process with the location of msmarco_passage_dev_rel_docs.json as the argument. Save the outputs into a pair of variables doc_store, index
In the Python console run indexing_process with the location of msmarco_passage_dev_rel_docs.json as the argument. Save the outputs into a pair of variables doc_store, index. Run query_process with these as arguments and query='Credit Card' and number_of_results=10. NOTE: Each of these functions may take a while to run.
import json from documents import Document, Transformed Document, ListDocumentStore, DictDocumentStore from index import Index def docs_from_json (json_file): with open (json_file, 'r') as f: docs = json.load(f) doc_store= DictDocument Store () for doc_id, text in docs.items(): doc_store.add_document (Document (doc_id=doc_id, text=text)) return doc_store def text_acquisition() -> ListDocument Store: doc_store = ListDocumentStore() doc_store.add_document ( Document (doc_id='0', text='red is a color')) doc_store.add_document( Document (doc_id='1', text='red and blue')) return doc_store def transform_documents (documents: list [Document]): return [Transformed Document (doc_id=doc.doc_id, terms=doc. text. lower().split()) for doc in documents] def create_index (transformed_documents: list [Transformed Document]) -> Index: Takes a list of Transformed Document and creates an index out of them. :param transformed_documents: list of Transformed Documents. return: Index |||||| index= Index() for doc in transformed_documents: index.add_document (doc) return index def indexing_process (json_file_location: str) -> tuple: documents = docs_from_json (json_file_location) transformed_documents = transform_documents (documents.list_all()) index = create_index(transformed_documents) return documents, index
Step by Step Solution
★★★★★
3.36 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Heres a stepbystep explanation of the provided code Import Statements Import necessary modules and classes Function Definitions docsfromjsonjsonfile T...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started