def test_k_fold_cross(self):
     method.configure(experiment.method_config)
     result = experiment.k_fold_cross(2, 10, 'my_method', 'my-method')
     self.assertEqual(len(result), 3)
     file_pattern = 'data/2-fold-cross-*'
     for f in glob(file_pattern):
         os.remove(f)
 def test_k_fold_cross_dataset(self):
     method.configure(experiment.method_config)
     result = experiment.k_fold_cross_dataset(2, 10)
     self.assertEqual(len(result), 2)
     for i in result:
         for f in i.itervalues():
             os.remove(f)
 def test_analyze_feature(self):
     method.configure(experiment.method_config)
     feature_names = method.ImprovedMethod.feature_names
     expectation = {'origin': 0}
     i = 0
     for feature_name in feature_names:
         i += 1
         expectation[feature_name] = i
     mock_k_fold_cross = Mock()
     mock_k_fold_cross.side_effect = range(0, 9)
     experiment.k_fold_cross = mock_k_fold_cross
     result = experiment.analyze_feature(2, 10, 'my_method')
     self.assertDictEqual(result, expectation)
 def test_has_pronoun(self):
     method_config = {
         'essentials': {
             'third_person_pronoun': 'data/third-person-pronoun.txt',
             'demonstrative_pronoun': 'data/demonstrative-pronoun.txt',
             'cue_word': 'data/cue-word.txt',
             'stop_word': 'data/stop-word.txt'
         },
         'word_similarity_calculators': {
             'how_net': {
                 'class': 'HowNetCalculator',
                 'sememe_tree_file': 'data/whole.dat',
                 'glossary_file': 'data/glossary.dat'
             }
         },
         'sentence_similarity_calculator': {
             'ssc_with_how_net': {
                 'word_similarity_calculator': 'how_net',
                 'score_filename': 'data/how-net-sentence.score'
             }
         },
         'feature_manager': {
             'fm': {
                 'sentence_similarity_calculator': 'ssc_with_how_net'
             }
         },
         'method': {
             'de_boni': {
                 'class': 'DeBoni',
                 'feature_manager': 'fm',
                 'q_q_threshold': 0.89,
                 'q_a_threshold': 0.89
             }
         }
     }
     configure(method_config)
     analyzed_sentence = AnalyzedSentence(
         u'fb070223efa1b565414c30bd4343c56e',
         u'[[[{"id": 0, "cont": "我", "pos": "r", "ne": "O", "parent": 1, "relate": "SBV", "arg": []},{ "id": 1, "cont": "是", "pos": "v", "ne": "O", "parent": -1, "relate": "HED", "arg": [{ "id": 0, "type": "A0", "beg": 0, "end": 0}, { "id": 1, "type": "A1", "beg": 2, "end": 3}]}, { "id": 2, "cont": "中国", "pos": "ns", "ne": "S-Ns", "parent": 3, "relate": "ATT", "arg": []}, { "id": 3, "cont": "人", "pos": "n", "ne": "O", "parent": 1, "relate": "VOB", "arg": []}], [{"cont": "那", "parent": 1, "relate": "ATT", "ne": "O", "pos": "r", "arg": [], "id": 0}, {"cont": "手机", "parent": 2, "relate": "SBV", "ne": "O", "pos": "n", "arg": [], "id": 1}, {"cont": "可以", "parent": -1, "relate": "HED", "ne": "O", "pos": "v", "arg": [], "id": 2}, {"cont": "吗", "parent": 2, "relate": "RAD", "ne": "O", "pos": "u", "arg": [], "id": 3}, {"cont": "?", "parent": 2, "relate": "WP", "ne": "O", "pos": "wp", "arg": [], "id": 4}]]]')
     mock_index = Mock()
     mock_index.return_value = (0, 11)
     analyzed_sentence.index = mock_index
     result = analyzed_sentence.has_pronoun()
     self.assertFalse(result)