Пример #1
0
    def aggregate_graph(mapper, ignore_external, exceptions, file_graph):
        assert (isinstance(mapper, AggregateMapper))
        pseudomodule_graph = MutableAttributeGraph()
        for edge in file_graph.edges():
            from_node = mapper.get_output_aggregate_for_individual(
                edge.get_from_node())
            if mapper.is_file_in_input_aggregates(edge.get_to_node()):
                to_node = mapper.get_output_aggregate_for_individual(
                    edge.get_to_node())
                if not (from_node == to_node or
                        (from_node, to_node) in exceptions):
                    pseudomodule_graph.add_edge_and_nodes(from_node, to_node)
                else:
                    pseudomodule_graph.add_node(from_node)
                    pseudomodule_graph.add_node(to_node)
            elif not ignore_external:
                to_node = edge.get_to_node()
                pseudomodule_graph.add_edge_and_nodes(from_node, to_node)
            else:
                pseudomodule_graph.add_node(from_node)

        # TODO warum wird das gemacht?
        for node in pseudomodule_graph.nodes_raw():
            pseudomodule_graph.set_node_attrs(node, {NodeAttributes.LABEL: ""})

        return pseudomodule_graph
 def get_cluster_dependency_graph(self, clustering_result,
                                  base_dependency_graph):
     """
     @param clustering_result: 
     @param base_dependency_graph: A BasicGraph whose nodes are the elements of the clusters.
     @return: An AttributeGraph whose nodes are groups of nodes of the base_dependency_graph according to 
     the clusters.
     """
     cluster_graph = MutableAttributeGraph()
     clusters = clustering_result.values()
     for cluster in clusters:
         pseudomodule = self.__to_pseudomodule_list(cluster)
         cluster_graph.set_node_attrs(
             self.__make_nodename(pseudomodule), {
                 NodeAttributes.GROUPED_NODES: pseudomodule,
                 NodeAttributes.LABEL: ""
             }, True)
     for cluster_pair in product(clusters, clusters):
         if cluster_pair[0] != cluster_pair[1]:
             pseudomodule_pair = map(self.__to_pseudomodule_list,
                                     cluster_pair)
             if any(
                     base_dependency_graph.has_edge(edge[0], edge[1])
                     for edge in product(pseudomodule_pair[0],
                                         pseudomodule_pair[1])):
                 cluster_graph.add_edge_and_nodes(
                     self.__make_nodename(pseudomodule_pair[0]),
                     self.__make_nodename(pseudomodule_pair[1]))
     return cluster_graph
Пример #3
0
    def filter_graph(full_graph, dependency_filter_config, internal_modules):
        """
        
        @param full_graph:
        @param dependency_filter_config:
        @param internal_modules: All internal modules are added to the graph even if they are not 
            connected to any other module. If the graph is focused on a particular module group, 
            this applies only if they belong to this module group.
        """
        graph = MutableAttributeGraph()
        for module in internal_modules:
            if not dependency_filter_config.skip_module(module) and not dependency_filter_config.skip_module_as_source(module):
                graph.add_node(module)
        for edge in full_graph.edges():
            source = str(edge.get_from_node())
            target = str(edge.get_to_node())
            if not (dependency_filter_config.skip_module(source) \
                    or dependency_filter_config.skip_module(target) \
                    or dependency_filter_config.skip_module_as_source(source) \
                    or dependency_filter_config.skip_module_as_target(target) \
                    or dependency_filter_config.skip_edge(source, target)):
                graph.add_edge_and_nodes(source, target)
            else:
                if dependency_filter_config.skip_module_as_source(source) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge source %s->%s", source, target)
                    graph.set_node_attrs(source, {NodeAttributes.SKIPPED_FROM_EDGE: True}, True)
                if dependency_filter_config.skip_module_as_target(target) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge target %s->%s", source, target)
                    graph.set_node_attrs(target, {NodeAttributes.SKIPPED_TO_EDGE: True}, True)

        if dependency_filter_config.focus_on_node_groups:
            node_grouper = dependency_filter_config.get_module_grouper()
            exception_func = lambda node: node_grouper.get_node_group_prefix(node) in dependency_filter_config.focus_on_node_groups
        else:
            exception_func = lambda node: False
        graph.delete_unconnected_nodes(exception_func)
        return graph