-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
32 lines (22 loc) · 832 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from glob import glob
from json import dumps
from inverted_index import InvertedIndex
def fetch_content(filename: str):
with open(filename, encoding='utf-8', mode='r') as file:
content = file.read()
file.close()
return content
def as_json(data: dict, indent=3):
return dumps(data, indent=indent)
if __name__ == '__main__':
path = "tmp/*.txt" # can be changed.
files = glob(path)
documents = {}
for filename in files:
documents[filename] = fetch_content(filename)
inverted_index = InvertedIndex()
inverted_index.build_index(documents)
resultSet = inverted_index.find('different system should results are in cost and can only computing elements')
print(as_json(resultSet))
termInfo = inverted_index.term_info("agile")
print(as_json(termInfo))