Skip to content

Commit cbedf27

Browse files
committed
Add lab 2 implementation for TF-IDF ranking
1 parent 24db5c6 commit cbedf27

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lab_2.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
3+
from index import Index
4+
from ranking.tf_idf_ranker import TfIdfRanker
5+
6+
7+
def main():
8+
file = sys.argv[1]
9+
print('Loading index from %s' % file)
10+
index = Index.from_file(file)
11+
while True:
12+
try:
13+
query = input('Enter query: ')
14+
documents = TfIdfRanker.search(index, query)
15+
for doc, score in documents:
16+
print('%s : %s' % (doc, score))
17+
except KeyboardInterrupt:
18+
break
19+
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)