Example #1
0
class TestParameters(TestCase):
    def setUp(self):
        self.parameters = Parameters()
        self.parameters.params_file = "test_files/parameters.json"

    def test_write_to_parameters_file(self):
        params_ = {
            "norm_term_count": {
                "abc": float(np.int64(0.2))
            },
            "norm_document_count": {
                "edc": 12
            },
            "unigrams_cosine_similarity_with_orig": {
                "def": 1.2
            },
        }
        self.parameters.params = params_
        self.parameters.write_to_parameters_file(self.parameters.params_file)
        self.parameters.read_from_params_file()
        print(type(self.parameters.params["norm_term_count"]["abc"]),
              file=sys.stderr)
        self.assertEqual(params_, self.parameters.params)
Example #2
0
        self.check_indri_run_query_exception(run_file_name)

        evals = self.run_trec_eval_1(trec_eval_bin, run_file_name,
                                     qrels_file_name)
        eval_file_name = self.gen_configs_file_name(query_cfg_file, "evals",
                                                    ".dsv")
        self.write_evals_to_files(evals, eval_file_name)

        self.evals_file_to_dict(eval_file_name)
        return self.evals_d[measure]['all']

    def get_all_measures(self):
        return self.evals_d

    @staticmethod
    def gen_configs_file_name(query_cfg_file, configs_dir, ext):
        dir_q, file_name = os.path.split(query_cfg_file)
        dir_c, dir_q = os.path.split(dir_q)
        dir_r = os.path.join(dir_c, configs_dir)
        if not os.path.exists(dir_r):
            raise ValueError("file " + dir_r + " does NOT exist.")
        file_name_r = os.path.splitext(file_name)[0] + ext
        return os.path.join(dir_r, file_name_r)


if __name__ == "__main__":
    parameters_ = Parameters()
    parameters_.read_from_params_file()
    eval_res = QueriesEvaluator(parameters_).run()
    print(eval_res)