-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
46 lines (29 loc) · 1.38 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fire
from tts.search import VectorSimilaritySearch, MinHashSimilaritySearch
all_methods = [VectorSimilaritySearch, MinHashSimilaritySearch]
def find_method_class(method_name):
for cls in all_methods:
if cls.__name__.lower().find(method_name.lower()) != -1:
return cls
def create_method_instance(method_name, source_path, kwargs):
method_cls = find_method_class(method_name)
source_data = method_cls.read_source_data(source_path)
if not isinstance(source_data, tuple):
source_data = (source_data,)
ss = method_cls(*source_data, **kwargs)
return ss
class Runner:
def __init__(self, method, source_path):
self._source_path = source_path
self._method_name = method
def search(self, query_path, output_path, **kwargs):
method_instance = create_method_instance(self._method_name, self._source_path, kwargs)
query = find_method_class(self._method_name).read_query(query_path)
result = method_instance.search(query)
method_instance.save_search_result(result, output_path)
def create_pair_dataset(self, output_path, **kwargs):
method_instance = create_method_instance(self._method_name, self._source_path, kwargs)
pairs = method_instance.create_pair_dataset()
method_instance.save_pair_dataset(pairs, output_path)
if __name__ == '__main__':
fire.Fire(Runner)