<commit_before>'''
Created on Sep 6, 2015

@author: levi
'''

from util.ecore_utils import *
from core.himesis_utils import graph_to_dot
class Pruner(object):
    '''
    checks whether a path condition can be removed from the set of path conditions being built
    based on the fact that missing containment relations cannot be built by the rules that are
    left to symbolically execute
    '''

    def __init__(self, metamodel, transformation, rule_names):
        '''
        Constructor
        '''

        self.debug = True

        self.eu = EcoreUtils(metamodel)
        self.mmContainmentLinks = self.eu.getContaimentLinksForClasses()
        
        self.ruleContainmentLinks = {}
        self.ruleMissingContLinks = {}

        self.linksToRules = {}

        for layer in transformation:
            for rule in layer:
                self.ruleContainmentLinks[rule.name] = self.eu.getBuiltContainmentLinks(rule)
                self.ruleMissingContLinks[rule.name] = self.eu.getMissingContainmentLinks(rule)

                for contain_link in self.ruleContainmentLinks[rule.name]:

                    try:
                        self.linksToRules[contain_link].append(rule_names[rule.name])
                    except KeyError:
                        self.linksToRules[contain_link] = [rule_names[rule.name]]

                if self.debug:
                    rule_name = rule_names[rule.name]
                    print("Rule containment links: " + rule_name + " = " + str(self.ruleContainmentLinks[rule.name]))
                    print("Missing rule containment links: " + rule_name + " = " + str(self.ruleMissingContLinks[rule.name]))
                    print()

        #test containment links and see if any are missing

        for layer in transformation:
            for rule in layer:

                required_rules = []

                for className in self.ruleMissingContLinks[rule.name]:

                    found_class = False
                    for contain_rule_name, contain_links in self.ruleContainmentLinks.items():
                        if className in contain_links.keys():
                            found_class = True
                            required_rules.append([contain_rule_name, className])

                    if not found_class:
                        raise Exception("Error: No rule builds containment link for class " + className + " from rule.name " + rule_names[rule.name])



        self.mmClassParents = self.eu.getSuperClassInheritanceRelationForClasses()

        # print("mm class parents:")
        # for mm in self.mmClassParents:
        #     print(mm + " : " + str(self.mmClassParents[mm]))

        

    def getContainmentLinksBuiltByRuleSet(self, ruleNames):
        '''
        get all the containment links built by a set of rules
        '''
        builtContainmentLinks = {}<commit_msg>Downgrade exception when no rule builds containment link.<commit_after>'''
Created on Sep 6, 2015

@author: levi
'''

from util.ecore_utils import *
from core.himesis_utils import graph_to_dot
class Pruner(object):
    '''
    checks whether a path condition can be removed from the set of path conditions being built
    based on the fact that missing containment relations cannot be built by the rules that are
    left to symbolically execute
    '''

    def __init__(self, metamodel, transformation, rule_names):
        '''
        Constructor
        '''

        self.debug = True

        self.eu = EcoreUtils(metamodel)
        self.mmContainmentLinks = self.eu.getContaimentLinksForClasses()
        
        self.ruleContainmentLinks = {}
        self.ruleMissingContLinks = {}

        self.linksToRules = {}

        for layer in transformation:
            for rule in layer:
                self.ruleContainmentLinks[rule.name] = self.eu.getBuiltContainmentLinks(rule)
                self.ruleMissingContLinks[rule.name] = self.eu.getMissingContainmentLinks(rule)

                for contain_link in self.ruleContainmentLinks[rule.name]:

                    try:
                        self.linksToRules[contain_link].append(rule_names[rule.name])
                    except KeyError:
                        self.linksToRules[contain_link] = [rule_names[rule.name]]

                if self.debug:
                    rule_name = rule_names[rule.name]
                    print("Rule containment links: " + rule_name + " = " + str(self.ruleContainmentLinks[rule.name]))
                    print("Missing rule containment links: " + rule_name + " = " + str(self.ruleMissingContLinks[rule.name]))
                    print()

        #test containment links and see if any are missing

        for layer in transformation:
            for rule in layer:

                required_rules = []

                for className in self.ruleMissingContLinks[rule.name]:

                    found_class = False
                    for contain_rule_name, contain_links in self.ruleContainmentLinks.items():
                        if className in contain_links.keys():
                            found_class = True
                            required_rules.append([contain_rule_name, className])

                    if not found_class:
                        message = "Error: No rule builds containment link for class " + className + " from rule.name " + rule_names[rule.name]
                        if self.debug:
                            raise Exception(message)
                        else:
                            print(message)



        self.mmClassParents = self.eu.getSuperClassInheritanceRelationForClasses()

        # print("mm class parents:")
        # for mm in self.mmClassParents:
        #     print(mm + " : " + str(self.mmClassParents[mm]))

        

    def getContainmentLinksBuiltByRuleSet(self, ruleNames):
        '''
        get all the containment links built by a set of rules
        '''
        builtContainmentLinks = {}
{'fraction_non_alphanumeric': 0.07910648303661404, 'fraction_numerical': 0.0016795431642593216, 'mean_word_length': 1.8949927078269324, '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': '3035762', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1466, 'n_words': 385}