Ejemplo n.º 1
0
    def createGraphviz(self):
#         self.getTableDetail()
        nodes = list()
        idx = 0
        for  k, columns in self.tables.iteritems():
            node = list()
#             print(idx, k, columns)
            nodeColumnName = dict()
            label = ''
            for index, column_name in enumerate(columns):
#                 print(column_name)
                label = label + '| <f' + str(index + 1) + '> ' + column_name
            nodeColumnName['label'] = '<f0> ' + k + label
#             print(nodeColumnName)
            node.append('node' + str(idx))
            node.append(nodeColumnName)
            nodes.append(tuple(node))
            idx += 1
            
        logger.debug(nodes)
        gd = GraphvizDiagram()
        
        g6 = gd.add_edges(
                          gd.add_nodes(Digraph(format='svg'), nodes
                                       ), [
                                          (('node0:f0', 'node1:f0'), {'id': '0'}),
                                          (('node0:f1', 'node2:f0'), {'id': '1'}),
                                                        #         ('B:f0', 'C:f0')
                                                            ]
        )
        g6 = gd.apply_styles(g6)
        g6.render(tempfile.gettempdir() + os.sep + 'g6')
Ejemplo n.º 2
0
    def to_dot(self):
        dot = Digraph(name=self.name,
                      graph_attr=[("overlap", "scalexy"), ("splines", "true"), ("rankdir", "LR"), ("ranksep", "0.8"),
                                  ("nodesep", "0.5")],
                      node_attr=[("shape", "circle")],
                      edge_attr=[("fontname", "mono")],
                      engine='dot',
                      format='svg')

        dot.node("init", "", [("shape", "point")])
        for s in self.states:
            dot.node(str(s))

        dot.edge("init", str(self.initial_state), style="solid")

        for t in self.transitions:
            if t.output is None:
                outputs = ""
            else:
                outputs = str(t.output)

            label = str(t.condition) + "\n>> " + str(t.action) + "\n>> " + outputs
            dot.edge(str(t.src), str(t.tgt), label=label)

        return dot
Ejemplo n.º 3
0
def output_parent_function_graph(rule_classification_data_bundle):
    report_dict, reference_dict = rule_classification_data_bundle

    identifier_dict = {
        parent: f"p{index}"
        for index, parent in enumerate(report_dict.keys())
    }

    dot = Digraph(**_GRAPH_SETTINGS)

    for parent, identifier in identifier_dict.items():
        descriptions = "\l".join(report_dict[parent]) + "\l"

        with dot.subgraph(
                name=f"cluster_{identifier}",
                graph_attr={
                    "label": _get_function_display_name(parent),
                    "fontsize": "16",
                },
        ) as sub:
            sub.node(identifier, label=descriptions)

    edge_list = []
    for parent, identifier in identifier_dict.items():
        edge_list.extend([(identifier, identifier_dict[function])
                          for function in reference_dict[parent]])

    dot.edges(edge_list)

    dot.render()
Ejemplo n.º 4
0
 def draw(self, path=None, show=True):
     dot = Digraph()
     dot.graph_attr.update(label=self._formula)
     for node in self._graph.nodes():
         num_peripheries = '2' if self._graph.node[node]['accept'] else '1'
         dot.node(node, node, shape='circle', peripheries=num_peripheries)
     for src, dst, label in self._graph.edges(data='print_label'):
         dot.edge(src, dst, label)
     if path is None:
         dot.render(view=show)
     else:
         dot.render(path, view=show)
Ejemplo n.º 5
0
    def render(self):
        """Call graphviz to do the schema """
        self.dot = Digraph(name=self.name,
                           format=self.format,
                           node_attr={
                               'shape': 'record',
                               'style': 'filled',
                               'fillcolor': 'gray95'
                           })
        for _, cls in self._nodes.items():
            cls.render(self.dot)

        for _, edge in self._edges.items():
            self.dot.edge(edge['from'], edge['to'], _attributes=edge['attr'])
Ejemplo n.º 6
0
 def graphviz(self):
     try:
         return self._graphviz
     except AttributeError:
         g = Digraph()
         g.attr(rankdir='LR')
         g.node('BEGIN', shape='point')
         for i in self.outputs_of(BEGIN):
             g.edge('BEGIN', str(i))
         for ix in self.topologically_sorted_indexes:
             g.node(str(ix), label=get_name(self[ix]))
             for iy in self.outputs_of(ix):
                 g.edge(str(ix), str(iy))
         self._graphviz = g
         return self._graphviz
Ejemplo n.º 7
0
 def finalgraph(self, filename=None):
     finaldb = Database(self.prac.mln)
     for step in self.inference_steps:
         for db in step.output_dbs:
             for atom, truth in list(db.evidence.items()):
                 if truth == 0: continue
                 _, predname, args = self.prac.mln.logic.parseLiteral(atom)
                 if predname in self.prac.roles.union(
                     ['has_sense', 'action_core', 'achieved_by']):
                     finaldb << atom
                 #         finaldb.write(sys.stdout, color=True)
     g = Digraph(format='svg', engine='dot')
     g.attr('node', shape='box', style='filled')
     for res in finaldb.query('action_core(?w, ?a) ^ has_sense(?w, ?s)'):
         actioncore = res['?a']
         sense = res['?s']
         predname = 'action_core'
         g.node(actioncore, fillcolor='#bee280')
         g.node(sense)
         g.edge(actioncore, sense, label='is_a')
         roles = self.prac.actioncores[actioncore].roles
         for role in roles:
             for res in db.query('{}(?w, {}) ^ has_sense(?w, ?s)'.format(
                     role, actioncore)):
                 sense = res['?s']
                 g.node(sense)
                 g.edge(actioncore, sense, label=role)
     for res in finaldb.query('achieved_by(?a1, ?a2)'):
         a1 = res['?a1']
         a2 = res['?a2']
         g.node(a1, fillcolor='#bee280')
         g.node(a2, fillcolor='#bee280')
         g.edge(a1, a2, label='achieved_by')
         actioncore = a2
         roles = self.prac.actionroles[actioncore].roles
         for role in roles:
             for res in db.query('{}(?w, {}) ^ has_sense(?w, ?s)'.format(
                     role, actioncore)):
                 sense = res['?s']
                 g.node(sense)
                 g.edge(actioncore, sense, label=role)
     return render_gv(g, filename)
Ejemplo n.º 8
0
def test_label_html():
    """http://www.graphviz.org/doc/info/shapes.html#html"""
    dot = Digraph('structs', node_attr={'shape': 'plaintext'})
    dot.node(
        'struct1', '''<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
  <TR>
    <TD>left</TD>
    <TD PORT="f1">middle</TD>
    <TD PORT="f2">right</TD>
  </TR>
</TABLE>>''')
    dot.node(
        'struct2', '''<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
  <TR>
    <TD PORT="f0">one</TD>
    <TD>two</TD>
  </TR>
</TABLE>>''')
    dot.node(
        'struct3', '''<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ROWSPAN="3">hello<BR/>world</TD>
    <TD COLSPAN="3">b</TD>
    <TD ROWSPAN="3">g</TD>
    <TD ROWSPAN="3">h</TD>
  </TR>
  <TR>
    <TD>c</TD>
    <TD PORT="here">d</TD>
    <TD>e</TD>
  </TR>
  <TR>
    <TD COLSPAN="3">f</TD>
  </TR>
</TABLE>>''')
    dot.edge('struct1:f1', 'struct2:f0')
    dot.edge('struct1:f2', 'struct3:here')
    assert dot.source == '''digraph structs {
Ejemplo n.º 9
0
    def constructDot(self) -> Digraph:
        '''
        Transforms the memory graph into an instance of class `Dot.Digraph`.
        '''
        dot = Digraph(comment='', format='dot')

        for vertex in self.vertices():
            dot.node(vertex['id'], '{}@{}'.format(vertex['id'],
                                                  vertex['struct']))

        for vertex in self.vertices():
            for assignment in vertex['assignment']:
                if assignment['value'] != constants.NULL_UPPER:
                    dot.edge(vertex['id'],
                             assignment['value'],
                             label=assignment['name'])

        for entrypoint in self.entrypoints():
            dot.node(entrypoint['name'], entrypoint['name'])
            dot.edge(entrypoint['name'], entrypoint['target'])

        return dot
Ejemplo n.º 10
0
    def test_label_html(self):
        dot = Digraph('structs', node_attr={'shape': 'plaintext'})
        dot.node(
            'struct1', '''<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
  <TR>
    <TD>left</TD>
    <TD PORT="f1">middle</TD>
    <TD PORT="f2">right</TD>
  </TR>
</TABLE>>''')
        dot.node(
            'struct2', '''<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
  <TR>
    <TD PORT="f0">one</TD>
    <TD>two</TD>
  </TR>
</TABLE>>''')
        dot.node(
            'struct3', '''<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ROWSPAN="3">hello<BR/>world</TD>
    <TD COLSPAN="3">b</TD>
    <TD ROWSPAN="3">g</TD>
    <TD ROWSPAN="3">h</TD>
  </TR>
  <TR>
    <TD>c</TD>
    <TD PORT="here">d</TD>
    <TD>e</TD>
  </TR>
  <TR>
    <TD COLSPAN="3">f</TD>
  </TR>
</TABLE>>''')
        dot.edge('struct1:f1', 'struct2:f0')
        dot.edge('struct1:f2', 'struct3:here')
        self.assertEqual(
            dot.source, '''digraph structs {
	node [shape=plaintext]
		struct1 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
  <TR>
    <TD>left</TD>
    <TD PORT="f1">middle</TD>
    <TD PORT="f2">right</TD>
  </TR>
</TABLE>>]
		struct2 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0">
  <TR>
    <TD PORT="f0">one</TD>
    <TD>two</TD>
  </TR>
</TABLE>>]
		struct3 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ROWSPAN="3">hello<BR/>world</TD>
    <TD COLSPAN="3">b</TD>
    <TD ROWSPAN="3">g</TD>
    <TD ROWSPAN="3">h</TD>
  </TR>
  <TR>
    <TD>c</TD>
    <TD PORT="here">d</TD>
    <TD>e</TD>
  </TR>
  <TR>
    <TD COLSPAN="3">f</TD>
  </TR>
</TABLE>>]
			struct1:f1 -> struct2:f0
			struct1:f2 -> struct3:here
}''')
        dot.render('test-output/html.gv')
Ejemplo n.º 11
0
    def test_subgraph_invalid(self):
        with self.assertRaises(ValueError):
            Graph().subgraph(Digraph())

        with self.assertRaises(ValueError):
            Digraph().subgraph(Graph())
Ejemplo n.º 12
0
 def test_strict(self):
     self.assertEqual(Graph(strict=True).source, 'strict graph {\n}')
     self.assertEqual(Digraph(strict=True).source, 'strict digraph {\n}')
Ejemplo n.º 13
0
def test_iter_strict():
    assert Graph(strict=True).source == 'strict graph {\n}'
    assert Digraph(strict=True).source == 'strict digraph {\n}'
Ejemplo n.º 14
0
 def __init__(self):
     self.dot = Digraph()