-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir.py
43 lines (33 loc) · 1.22 KB
/
ir.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
33
34
35
36
37
38
39
40
41
42
import os
import argparse
from Tokenize import Tokenize
from InvertedIndex import InvertedIndex
from PositionalIndex import PositionalIndex
def ir():
parser = argparse.ArgumentParser(
prog='IR System',
description='Preprocessing documents and searching system',)
parser.add_argument('-t', '--tokens', action='store_true')
parser.add_argument('-p', '--pos-index', action='store_true')
parser.add_argument('-i', '--inv-index', action='store_true')
parser.add_argument('-a', '--all', action='store_true')
args = parser.parse_args()
tokens = args.tokens or args.all
inv_index = args.inv_index or args.all
pos_index = args.pos_index or args.all
if tokens:
for file in os.listdir('./docs/'):
tokenize = Tokenize(file, './.out/tokens')
tokenize.save()
if inv_index:
index = InvertedIndex('./.out/tokens',
'./.out/indexing/inv_index.json')
index.get_terms_docs()
index.create_index()
index.save_index()
if pos_index:
i = PositionalIndex('.out/indexing/inv_index.json',
'.out/indexing/pos_index.json')
i.save()
if __name__ == "__main__":
ir()