■ ■ ■ ■ ■ ■
maryam/modules/iris/iris_cluster.py
| 1 | + | """ |
| 2 | + | OWASP Maryam! |
| 3 | + | This program is free software: you can redistribute it and/or modify |
| 4 | + | it under the terms of the GNU General Public License as published by |
| 5 | + | the Free Software Foundation, either version 3 of the License, or |
| 6 | + | any later version. |
| 7 | + | This program is distributed in the hope that it will be useful, |
| 8 | + | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | + | GNU General Public License for more details. |
| 11 | + | You should have received a copy of the GNU General Public License |
| 12 | + | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 13 | + | """ |
| 14 | + | |
| 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': ('kneed', 'mlxtend, numpy, sklearn'), |
| 21 | + | 'options': ( |
| 22 | + | ('query', None, True, 'Query string', '-q', 'store', str), |
| 23 | + | ), |
| 24 | + | 'examples': ('iris_cluster -q <QUERY>') |
| 25 | + | } |
| 26 | + | |
| 27 | + | |
| 28 | + | def module_api(self): |
| 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()} |
| 39 | + | |
| 40 | + | self._mode = mode |
| 41 | + | # Resetting options for iris_search_module |
| 42 | + | self.options = {} |
| 43 | + | self.options['query'] = query |
| 44 | + | self.options['output'] = output_option_value |
| 45 | + | |
| 46 | + | self.save_gather(output, 'iris/iris_cluster', query, output=self.options['output']) |
| 47 | + | return output |
| 48 | + | |
| 49 | + | def module_run(self): |
| 50 | + | output = module_api(self)['results'] |
| 51 | + | |
| 52 | + | print('\n\nCLUSTER RESULT: ') |
| 53 | + | for index, title in enumerate(output): |
| 54 | + | print('\n') |
| 55 | + | print(f"CLUSTER {index+1}") |
| 56 | + | print(f"TITLE: {title}") |
| 57 | + | print(' '+'\n '.join(output[title])) |
| 58 | + | |