def test_read_config_cmd(): # this file does not exist invalid_config = read_config_file('config.xml', '') # ...so the config is invalid assert invalid_config.is_valid() == False # make temp directory Path('librec_auto/test/temp').mkdir(exist_ok=True) Path('librec_auto/test/temp/conf').mkdir(exist_ok=True) # copy the config into the temp directory current_config = Path('librec_auto/test/test-config.xml') new_config = Path('librec_auto/test/temp/conf/test-config.xml') shutil.copy(current_config, new_config) # this file exists invalid_config = read_config_file('test-config.xml', 'librec_auto/test/temp') # so the config is valid assert invalid_config.is_valid() == True # and the ._var_data attribute has been initialized assert invalid_config._var_data == defaultdict(list) # break down the temp dir shutil.rmtree(Path('librec_auto/test/temp'))
def load_config(args): config_file = Files.DEFAULT_CONFIG_FILENAME if args['conf']: # User requested a different configuration file config_file = args['conf'] target = "" if (args['target'] != None): target = args['target'] return read_config_file(config_file, target)
def load_config(args: dict) -> ConfigCmd: config_file = Files.DEFAULT_CONFIG_FILENAME if args['conf']: # User requested a different configuration file from the default config_file = args['conf'] target = "" if (args['target'] != None): target = args['target'] log_file = args['log_name'] # create a path: return read_config_file(config_file, target, log_file)
def main(): args = read_args() config = read_config_file(args['conf'], '.') original_results_path = Path(args['original']) result_files = enumerate_results(original_results_path) dest_results_path = Path(args['result']) data_dir = single_xpath(config.get_xml(), '/librec-auto/data/data-dir').text data_path = Path(data_dir) data_path = data_path.resolve() item_feature_df = load_item_features(config, data_path) if item_feature_df is None: exit(-1) # item_helper = set_item_helper(item_feature_df) # rerank_helper = set_rerank_helper(args, config, item_helper) rerank_helper = Rerank_Helper() rerank_helper.set_rerank_helper(args, config, item_feature_df) split_path = data_path / 'split' pat = re.compile(RESULT_FILE_PATTERN) method = args['method'] p = [] for file_path in result_files: p1 = multiprocessing.Process(target=execute, args=(rerank_helper, pat, file_path, split_path, dest_results_path)) p.append(p1) p1.start() for p1 in p: p1.join()
def main(): args = read_args() config = read_config_file(args['conf'], '.') original_results_path = Path(args['original']) result_files = enumerate_results(original_results_path) dest_results_path = Path(args['result']) data_dir = single_xpath(config.get_xml(), '/librec-auto/data/data-dir').text data_path = Path(data_dir) data_path = data_path.resolve() item_feature_df = load_item_features(config, data_path) protected = single_xpath(config.get_xml(), '/librec-auto/metric/protected-feature').text if item_feature_df is None: exit(-1) alpha = float(args['alpha']) max_len = int(args['max_len']) binary = args['binary'] == 'True' # protected = str(args['protected']) helper = set_helper(alpha, max_len, binary, protected, item_feature_df) for file_path in result_files: results_df = pd.read_csv(file_path, names=['userid', 'itemid', 'rating']) fair = generate_fairstar(helper) reranked_df = rerank(results_df, fair, helper) output_reranked(reranked_df, dest_results_path, file_path)
super().__init__(params, conf, test_data, result_data, output_file) self._name = "Test" # def def read_args(): """ Parse command line arguments. """ parser = argparse.ArgumentParser(description='My custom metric') parser.add_argument('--conf', help='Path to config file') parser.add_argument('--test', help='Path to test.') parser.add_argument('--result', help='Path to results.') parser.add_argument('--output-file', help='The output pickle file.') # Custom params defined in the config go here parser.add_argument('--list_size', help='Size of the list for NDCG.') input_args = parser.parse_args() print(vars(input_args)) return vars(input_args) if __name__ == '__main__': args = read_args() config = read_config_file(args['conf'], '.') temp_directory = config.get_files().get_temp_dir_path() protected_feats = ProtectedFeature( ProtectedFeature.parse_protected(config), temp_dir=temp_directory)
RESULT_FILE_PATTERN = 'out-\d+.txt' INPUT_FILE_PATTERN = 'cv_\d+' def enumerate_results(result_path): files = os.listdir(result_path) pat = re.compile(RESULT_FILE_PATTERN) return [file for file in files if pat.match(file)] if __name__ == '__main__': args = read_args() #print(args) config = read_config_file(args['conf'], args['target']) result_files = enumerate_results(args['original']) split_path = config.get_files().get_split_path() # split_names = os.listdir(split_path) data_dir = config.get_prop_dict()['dfs.data.dir'] item_feature_file = config.get_prop_dict()['data.itemfeature.path'] protected = config.get_prop_dict()['data.protected.feature'] item_feature_path = Path(data_dir) / item_feature_file item_feature_df = None if not item_feature_path.exists(): print("Cannot locate item features. Path: " + item_feature_path)
boxes) webbrowser.open('file://' + str(html_file.absolute()), new=1, autoraise=True) def read_args(): """ Parse command line arguments. :return: """ parser = argparse.ArgumentParser( description='Generic post-processing script') parser.add_argument('conf', help='Path to configuration file') parser.add_argument('--browser', help='Show graphics in browser', choices=['true', 'false']) input_args = parser.parse_args() return vars(input_args) if __name__ == '__main__': args = read_args() config = read_config_file(args['conf'], ".") print(f"librec-auto: Creating summary visualizations") display = args['browser'] == 'true' create_graphics(config, display)