def test_compute_moving_averages(self): config = FeaturesGenerationConfig(include_irrelevant=False, examples_per_file=20, review_start_range=2, review_end_range=1, group_size=5, cochrane_search_range=15, remove_stance=True) primary_paper = Paper('1', 'title1', 'journal1', '', ['2', '3', '4', '5'], 1, '1234', 1987) p2 = Paper('2', 'title1', 'journal1', '', ['12', '13', '14', '15'], 5, '1234', 1989) p3 = Paper('3', 'title1', 'journal1', '', ['12', '13', '14', '15'], 6, '1234', 1991) p4 = Paper('4', 'title1', 'journal1', '', ['12', '13', '14', '15'], 4, '1234', 1991) p5 = Paper('5', 'title1', 'journal1', '', ['12', '13', '14', '15'], 30, '1234', 1993) paper_builder_mock = MagicMock() paper_builder_mock.build_paper = mock_responses({ '2': p2, '3': p3, '4': p4, '5': p5 }) fg = FeaturesGenerator(paper_builder_mock) avg = fg.compute_moving_averages(primary_paper, 1990, config) self.assertTrue(avg == 5.0)
def test_generate_examples_by_group_include_ir(self): actual_dir = '../resources/output/group_include_ir/actual/' self.setup_actual_dir(actual_dir) config = FeaturesGenerationConfig(include_irrelevant=True, examples_per_file=20, review_start_range=2, review_end_range=1, group_size=3, cochrane_search_range=2, remove_stance=True) fg = self.setup_feature_generator() fg.generate_examples(actual_dir, '../resources/queries.csv', '', '../resources/examples/', config) expected_dir = '../resources/output/group_include_ir/expected/' self.compare_files(actual_dir, expected_dir)
def test_single_paper_feature_generator(self): config = FeaturesGenerationConfig(include_irrelevant=False, examples_per_file=20, review_start_range=2, review_end_range=1, group_size=5, cochrane_search_range=15, remove_stance=True) primary_paper = Paper('1', 'title1', 'journal1', '', ['2', '3', '4', '5'], 3, '1234', 1987) primary_paper.set_stance_score(5) c2 = Paper('2', 'title1', 'journal1', '', ['12', '13', '14', '15'], 5, '1234', 1989) c2.set_stance_score(1) c3 = Paper('3', 'title1', 'journal1', '', ['12', '13', '14', '15'], 6, '1234', 1991) c4 = Paper('4', 'title1', 'journal1', '', ['12', '13', '14', '15'], 4, '1234', 1991) c5 = Paper('5', 'title1', 'journal1', '', ['12', '13', '14', '15'], 30, '1234', 1993) paper_builder_mock = MagicMock() paper_builder_mock.build_paper = mock_responses({ '2': c2, '3': c3, '4': c4, '5': c5 }) fg = FeaturesGenerator(paper_builder_mock) #paper, review_year, config, papers expected_paper = PaperFeatures(3, 5) expected_paper.set_contradicted_by_later(int(True)) expected_paper.add_citations_hIndex_weighted_feature(5.0) expected_paper.add_citation_feature(4) expected_paper.add_year_gap_feature(4) actual_paper = fg.single_paper_feature_generator( primary_paper, 1990, config, {'2': c2}) self.assertEqual(expected_paper, actual_paper)