■ ■ ■ ■ ■ ■
maryam/modules/iris/iris_cluster.py
| skipped 12 lines |
13 | 13 | | """ |
14 | 14 | | |
15 | 15 | | meta = { |
16 | | - | 'name': 'Iris_Cluster', |
17 | | - | 'author': 'Shaad', |
18 | | - | 'version': '0.1', |
19 | | - | 'description': 'Get Iris Search result and clustered results for your query', |
20 | | - | 'required': ('Same as Iris and Cluster module'), |
21 | | - | 'options': ( |
22 | | - | ('query', None, True, 'Query string', '-q', 'store', str), |
23 | | - | ), |
24 | | - | 'examples': ('iris_cluster -q <QUERY>') |
| 16 | + | 'name': 'Iris_Cluster', |
| 17 | + | 'author': 'Shaad', |
| 18 | + | 'version': '0.1', |
| 19 | + | 'description': 'Get Iris Search result and clustered results for your query', |
| 20 | + | 'required': ('kneed', 'mlxtend'), |
| 21 | + | 'options': ( |
| 22 | + | ('query', None, True, 'Query string', '-q', 'store', str), |
| 23 | + | ), |
| 24 | + | 'examples': ('iris_cluster -q <QUERY>') |
25 | 25 | | } |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | def module_api(self): |
29 | | - | query = self.options['query'] |
30 | | - | output_option_value = self.options['output'] |
31 | | - | output = {} |
32 | | - | |
33 | | - | # Computing iris search result |
34 | | - | self._mode = 'api_mode' |
35 | | - | iris_search_result = self.opt_proc('iris', args=f'-q "{query}" --api', output='web_api') |
36 | | - | output['iris_search_result'] = iris_search_result |
37 | | - | |
38 | | - | # Computing cluster results |
39 | | - | clusterer = self.cluster(iris_search_result) |
40 | | - | output['cluster_result'] = {'json': clusterer.perform_clustering()} |
41 | | - | |
42 | | - | # Resetting options for iris_cluster_module |
43 | | - | self.options = {} |
44 | | - | self.options['query'] = query |
45 | | - | self.options['output'] = output_option_value |
46 | | - | |
47 | | - | self.save_gather(output, 'iris/iris_cluster', query, output=self.options['output']) |
| 29 | + | query = self.options['query'] |
| 30 | + | output_option_value = self.options['output'] |
| 31 | + | output = {} |
| 32 | + | mode = self._mode |
| 33 | + | # Computing iris search result |
| 34 | + | self._mode = 'api_mode' |
| 35 | + | iris_search_result = self.opt_proc('iris', args=f'-q "{query}" --api', output='web_api') |
| 36 | + | # Computing cluster results |
| 37 | + | clusterer = self.cluster(iris_search_result) |
| 38 | + | output = {'results': clusterer.perform_clustering()} |
48 | 39 | | |
49 | | - | return output |
| 40 | + | self._mode = mode |
| 41 | + | self.save_gather(output, 'iris/iris_cluster', query, output=self.options['output']) |
50 | 42 | | |
| 43 | + | return output |
51 | 44 | | |
52 | 45 | | def module_run(self): |
53 | | - | output = module_api(self) |
54 | | - | iris_search_result = output['iris_search_result'] |
55 | | - | cluster_result = output['cluster_result']['json'] |
| 46 | + | output = module_api(self) |
56 | 47 | | |
57 | | - | print('IRIS SEARCH RESULT: ') |
58 | | - | self.search_engine_results(iris_search_result) |
59 | | - | |
60 | | - | print('\n\nCLUSTER RESULT: ') |
61 | | - | for index, title in enumerate(cluster_result): |
62 | | - | print('\n') |
63 | | - | print(f"CLUSTER {index+1}") |
64 | | - | print(f"TITLE: {title}") |
65 | | - | print(' '+'\n '.join(cluster_result[title])) |
| 48 | + | print('\n\nCLUSTER RESULT: ') |
| 49 | + | for index, title in enumerate(cluster_result): |
| 50 | + | print('\n') |
| 51 | + | print(f"CLUSTER {index+1}") |
| 52 | + | print(f"TITLE: {title}") |
| 53 | + | print(' '+'\n '.join(cluster_result[title])) |
66 | 54 | | |