<commit_before>from __future__ import division

class Evaluator():
    def __init__(self):
        self.unlabeled_correct_num = 0
        self.unlabeled_gold_set_size = 0
        return
        
    def reset(self):
        self.unlabeled_correct_num = 0
        self.unlabeled_gold_set_size = 0
        return

    def get_statistics(self):
        return self.unlabeled_correct_num, self.unlabeled_gold_set_size

    def _sent_unlabeled_accuracy(self, result_edge_set, gold_edge_set):      
        if isinstance(result_edge_set, list):
            result_edge_set = set(result_edge_set)
        
        if isinstance(gold_edge_set, list):
            gold_edge_set = set(gold_edge_set)
        
        intersect_set = result_edge_set.intersection(gold_edge_set)
        correct_num = len(intersect_set)
        gold_set_size = len(gold_edge_set)
        
        return correct_num, gold_set_size
    
    
    def unlabeled_accuracy(self, result_edge_set, gold_edge_set, accumulate=False):
        """
        calculate unlabeled accuracy of the glm-parser
        unlabeled accuracy = # of corrected edge in result / # of all corrected edge
        
        :param result_edge_set: the edge set that needs to be evaluated
        :type result_edge_set: list/set
        
        :param gold_edge_set: the gold edge set used for evaluating<commit_msg>reorganized version<commit_after>from __future__ import division

class Evaluator():
    def __init__(self):
        self.unlabeled_correct_num = 0
        self.unlabeled_gold_set_size = 0
        return
        
    def reset(self):
        self.unlabeled_correct_num = 0
        self.unlabeled_gold_set_size = 0
        return

    def get_statistics(self):
        return self.unlabeled_correct_num, self.unlabeled_gold_set_size

    def _sent_unlabeled_accuracy(self, result_edge_set, gold_edge_set):      
        if isinstance(result_edge_set, list):
            result_edge_set = set(result_edge_set)
        
        if isinstance(gold_edge_set, list):
            gold_edge_set = set(gold_edge_set)
        
        intersect_set = result_edge_set.intersection(gold_edge_set)
        correct_num = len(intersect_set)
        gold_set_size = len(gold_edge_set)
        
        return correct_num, gold_set_size

    def evaluate(self, data_pool, parser, fset):        
        while data_pool.has_next_data():  
            dep_tree = data_pool.get_next_data()
            
            gold_edge_set = \
                set([(head_index,dep_index) for head_index,dep_index,_ in dep_tree.get_edge_list()])
            
            fset.switch_tree(dep_tree)
            sent_len = len(dep_tree.get_word_list())
            test_edge_set = \
               parser.parse(sent_len, fset.get_edge_score)
             
            #print "sent acc:", 
            self.unlabeled_accuracy(test_edge_set, gold_edge_set, True)
            #print "acc acc:", self.evlt.get_acc_unlabeled_accuracy()
        print "Unlabeled accuracy:", self.get_acc_unlabeled_accuracy()

    
    def unlabeled_accuracy(self, result_edge_set, gold_edge_set, accumulate=False):
        """
        calculate unlabeled accuracy of the glm-parser
        unlabeled accuracy = # of corrected edge in result / # of all corrected edge
        
        :param result_edge_set: the edge set that needs to be evaluated
        :type result_edge_set: list/set
        
        :param gold_edge_set: the gold edge set used for evaluating
{'fraction_non_alphanumeric': 0.06524249422632794, 'fraction_numerical': 0.0023094688221709007, 'mean_word_length': 2.4003925417075562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2728527', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1028, 'n_words': 219}