Ejemplo n.º 1
0
    def generate_project_similarity_plots(self):
        plots = []
        identifier = "Similarities"
        title = "Similarities to other Projects"
        plots.append(
            viz.get_table(self.similar_projects, identifier + ' table',
                          title + ' table'))
        plots.append(
            viz.get_sankey_plot(self.similar_projects,
                                identifier,
                                args={
                                    'source': 'current',
                                    'target': 'other',
                                    'weight': 'similarity_pearson',
                                    'orientation': 'h',
                                    'valueformat': '.0f',
                                    'width': 800,
                                    'height': 800,
                                    'font': 12,
                                    'title': title
                                }))

        plots.append(self.get_similarity_network())

        return plots
Ejemplo n.º 2
0
 def generate_report(self, visualization='sankey'):
     report = rp.Report(identifier="knowledge")
     if visualization == 'network':
         plots = [self.get_knowledge_graph_plot()]
     elif visualization == 'sankey':
         if self.graph is None:
             self.generate_knowledge_graph()
         df = nx.to_pandas_edgelist(self.graph).fillna(1)
         plots = [
             viz.get_sankey_plot(df,
                                 self.identifier,
                                 args={
                                     'source': 'source',
                                     'target': 'target',
                                     'source_colors': 'source_color',
                                     'target_colors': 'target_color',
                                     'hover': 'type',
                                     'pad': 10,
                                     'weight': 'weight',
                                     'orientation': 'h',
                                     'valueformat': '.0f',
                                     'width': 1600,
                                     'height': 2200,
                                     'font': 10,
                                     'title': 'Knowledge Graph'
                                 })
         ]
     report.plots = {("Knowledge Graph", "Knowledge Graph"): plots}
     self.report = report
Ejemplo n.º 3
0
    def generate_report(self, visualizations=['sankey'], summarize=True):
        report = rp.Report(identifier="knowledge")
        plots = []
        for visualization in visualizations:
            if visualization == 'network':
                plots.append(
                    self.get_knowledge_graph_plot(summarize=summarize))
            elif visualization == 'sankey':
                remove_edges = []
                if self.graph is None:
                    self.generate_knowledge_graph()
                G = self.graph.copy()
                new_type_edges = {}
                new_type_nodes = {}
                for n1, n2 in G.edges():
                    if G.nodes[n1]['type'] == G.nodes[n2]['type']:
                        remove_edges.append((n1, n2))
                    else:
                        if G.nodes[n1]['type'] in self.entities:
                            color = G.nodes[n1]['color']
                            new_type_edges.update({
                                (n1, G.nodes[n1]['type']): {
                                    'type':
                                    'is_a',
                                    'weight':
                                    0.0,
                                    'width':
                                    1.0,
                                    'source_color':
                                    color,
                                    'target_color':
                                    self.colors[G.nodes[n1]['type']]
                                }
                            })
                            new_type_nodes.update({
                                G.nodes[n1]['type']: {
                                    'type': 'entity',
                                    'color': self.colors[G.nodes[n1]['type']]
                                }
                            })
                        if G.nodes[n2]['type'] in self.entities:
                            color = G.nodes[n2]['color']
                            new_type_edges.update({
                                (n2, G.nodes[n2]['type']): {
                                    'type':
                                    'is_a',
                                    'weight':
                                    0.0,
                                    'width':
                                    1.0,
                                    'source_color':
                                    color,
                                    'target_color':
                                    self.colors[G.nodes[n2]['type']]
                                }
                            })
                            new_type_nodes.update({
                                G.nodes[n2]['type']: {
                                    'type': 'entity',
                                    'color': self.colors[G.nodes[n2]['type']]
                                }
                            })

                G.remove_edges_from(remove_edges)
                G.add_edges_from(new_type_edges.keys())
                nx.set_edge_attributes(G, new_type_edges)
                G.add_nodes_from(new_type_nodes.items())
                df = nx.to_pandas_edgelist(G).fillna(1)
                plots.append(
                    viz.get_sankey_plot(df,
                                        self.identifier,
                                        args={
                                            'source': 'source',
                                            'target': 'target',
                                            'source_colors': 'source_color',
                                            'target_colors': 'target_color',
                                            'hover': 'type',
                                            'pad': 10,
                                            'weight': 'width',
                                            'orientation': 'h',
                                            'valueformat': '.0f',
                                            'width': 1600,
                                            'height': 2200,
                                            'font': 10,
                                            'title': 'Knowledge Graph'
                                        }))

        report.plots = {("Knowledge Graph", "Knowledge Graph"): plots}
        self.report = report
Ejemplo n.º 4
0
    def generate_knowledge_sankey_plot(self, graph=None):
        remove_edges = []
        if graph is None:
            graph = self.graph.copy()
        new_type_edges = {}
        new_type_nodes = {}
        for n1, n2 in graph.edges():
            if graph.nodes[n1]['type'] == graph.nodes[n2]['type']:
                remove_edges.append((n1, n2))
            else:
                if graph.nodes[n1]['type'] in self.entities:
                    color = graph.nodes[n1]['color']
                    new_type_edges.update({
                        (n1, graph.nodes[n1]['type']): {
                            'type': 'is_a',
                            'weight': 0.0,
                            'width': 1.0,
                            'source_color': color,
                            'target_color':
                            self.colors[graph.nodes[n1]['type']]
                        }
                    })
                    new_type_nodes.update({
                        graph.nodes[n1]['type']: {
                            'type': 'entity',
                            'color': self.colors[graph.nodes[n1]['type']]
                        }
                    })
                if graph.nodes[n2]['type'] in self.entities:
                    color = graph.nodes[n2]['color']
                    new_type_edges.update({
                        (n2, graph.nodes[n2]['type']): {
                            'type': 'is_a',
                            'weight': 0.0,
                            'width': 1.0,
                            'source_color': color,
                            'target_color':
                            self.colors[graph.nodes[n2]['type']]
                        }
                    })
                    new_type_nodes.update({
                        graph.nodes[n2]['type']: {
                            'type': 'entity',
                            'color': self.colors[graph.nodes[n2]['type']]
                        }
                    })

        graph.remove_edges_from(remove_edges)
        graph.add_edges_from(new_type_edges.keys())
        nx.set_edge_attributes(graph, new_type_edges)
        graph.add_nodes_from(new_type_nodes.items())
        df = nx.to_pandas_edgelist(graph).fillna(0.5)
        plot = viz.get_sankey_plot(df,
                                   self.identifier,
                                   args={
                                       'source': 'source',
                                       'target': 'target',
                                       'source_colors': 'source_color',
                                       'target_colors': 'target_color',
                                       'hover': 'type',
                                       'pad': 10,
                                       'weight': 'width',
                                       'orientation': 'h',
                                       'valueformat': '.0f',
                                       'width': 1600,
                                       'height': 2200,
                                       'font': 10,
                                       'title': 'Knowledge Graph'
                                   })

        return plot