def get_top_words(dirs, top_size=10, format_data='list', lang_category='verb'): if not type(dirs) == list: project_dirs = [dirs] else: project_dirs = dirs words = get_ungrouped_list_words(project_dirs, lang_category) data = collections.Counter(make_list_flat(words)).most_common(top_size) if format_data == 'json': data = convert_list_of_tuples_to_json_dict(data) return data
def main(): if DEBUG: colored_print('Start script in debug mode', mode='warning') args = parse_args() dirs = args.dirs if args.extension != 'py': text = f'Is mode in develop. Analysis files with extension {args.extension} is not yet.' colored_print(text, mode='warning') return if args.repo: tmp_dir = tempfile.mkdtemp() clone_to_dir(args.repo, tmp_dir) dirs = [tmp_dir] words = get_ungrouped_list_words(dirs, args.lang_category, args.code_element, args.extension) if args.output == 'file': create_report_file( make_list_flat(words), args.top_size, args.report_path, args.lang_category, args.code_element, args.format_file ) else: print_top_words_in_console( make_list_flat(words), args.top_size, args.lang_category, args.code_element ) if args.repo: delete_created_repo_dir(dirs[0])
def test_get_top_verbs_send_list_dir(fixtures_path): list_dirs = [fixtures_path] verbs = get_top_words(list_dirs) assert 'get' in make_list_flat(verbs) assert 'say' in make_list_flat(verbs) assert len(verbs) == 2
def test_get_top_verbs(fixtures_path): verbs = get_top_words(fixtures_path) assert 'get' in make_list_flat(verbs) assert 'say' in make_list_flat(verbs) assert len(verbs) == 2
def test_make_list_flat(): assert make_list_flat([(1, 2)]) == [1, 2] assert make_list_flat([[1, 2, 3]]) == [1, 2, 3] assert make_list_flat([(1, 2), (3, 4)]) == [1, 2, 3, 4]
def get_nouns(function_name_list): nouns = [get_nouns_from_function_name(function_name) for function_name in function_name_list] return make_list_flat(nouns)
def get_verbs(function_name_list): verbs = [get_verbs_from_function_name(function_name) for function_name in function_name_list] return make_list_flat(verbs)
def get_all_variables_names(trees): name_lists = [get_variables_names_from_tree(tree) for tree in trees] return make_list_flat(name_lists)
def get_all_function_names(trees): name_lists = [get_functions_from_tree(tree) for tree in trees] return make_list_flat(name_lists)