Untitled
unknown
plain_text
2 years ago
1.1 kB
16
Indexable
from typing import List
class Document:
def __init__(self, title: str, text: str):
self.title = title
self.text = text
class SearchEngine:
def __init__(self, documents: List[List[str]]):
self.documents = self._parse_documents(documents=documents)
def _parse_documents(self, documents: List[List[str]]) -> List[Document]:
document_list = []
# TODO Implement parsing here
return document_list
def search(self, query: str) -> List[Document]:
""" Implement a function to search for a query in the document text
:returns
Sublist of the original list of documents matching the query
"""
# TODO Implement search here
pass
documents = [
['Why I love Football', 'Football is my life and ...'],
['My sporting interests', 'Tennis, football and rugby are sports I love...'],
['Football, football, football', 'This is a guide to the best things about...']
]
se = SearchEngine(documents=documents)
if __name__ == '__main__':
query = "football"
se.search(query=query)Editor is loading...
Leave a Comment