예제 #1
0
    def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):

        if (ctx.getChildCount() == 2):
            g = ctx.getChildren()
            l = [next(g) for i in range(2)]
            self.digraph.add_edge(self.anterior,
                                  self.item[l[0].getText()],
                                  color='black',
                                  name="",
                                  tipus='enquesta')
            self.anterior = self.item[l[0].getText()]
            self.visit(l[1])

        else:
            g = ctx.getChildren()
            l = [next(g) for i in range(1)]
            self.digraph.add_edge(self.anterior,
                                  self.item[l[0].getText()],
                                  color='black',
                                  name="",
                                  tipus='enquesta')
            self.digraph.add_edge(self.item[l[0].getText()],
                                  'END',
                                  color='black',
                                  name="",
                                  tipus='enquesta')

        self.visitChildren(ctx)


#del EnquestesParser
예제 #2
0
    def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
        self.G.add_node(next(ctx.getChildren()).getText(), tipus='id', id=next(ctx.getChildren()).getText())
        self.nodePreg.insert(0, next(ctx.getChildren()).getText())
        n = ctx.getChildren()
        l = [next(n) for i in range(ctx.getChildCount())]
        self.G.add_node(l[ctx.getChildCount()-1].getText(), tipus='end', end=l[ctx.getChildCount()-1].getText())
        self.nodePreg.append(l[ctx.getChildCount()-1].getText())
        nodes = [x for x in self.nodePreg if x not in self.prohibits]
        for i in range(len(nodes)-1):
            self.edgePreg.append(tuple([nodes[i], nodes[i+1]]))
            self.G.add_edge(nodes[i], nodes[i+1], tipus='normal')
        labels = nx.get_edge_attributes(self.G, 'range')
        number = nx.get_edge_attributes(self.G, 'number')
        pos = nx.circular_layout(self.G)
        P = self.G.subgraph(self.nodePreg)
        R = self.G.subgraph(self.nodeRes)
        nx.draw_networkx_nodes(self.G, pos, nodelist=self.nodePreg)
        nx.draw_networkx_nodes(self.G, pos, nodelist=self.nodeRes)
        nx.draw_networkx_edges(self.G, pos, edgelist=self.edgePreg, edge_color='black')
        nx.draw_networkx_edges(self.G, pos, edgelist=self.edgeItem, edge_color='blue')
        nx.draw_networkx_edge_labels(self.G, pos, edgelist=self.edgeItem, edge_labels=labels, font_color='blue')
        nx.draw_networkx_edges(self.G, pos, edgelist=self.edgeAltern, edge_color='green')
        nx.draw_networkx_edge_labels(self.G, pos, edgelist=self.edgeAltern, edge_labels=number, font_color='green')
        nx.write_gpickle(self.G, "test.gpickle")
        nx.draw_networkx_labels(P, pos)
        nx.draw_networkx_labels(R, pos)
        plt.savefig('graf.png')
        plt.show()

        return self.visitChildren(ctx)
예제 #3
0
 def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
     l = ctx.getChildren()
     f = [next(l) for i in range(ctx.getChildCount())]
     enquesta = f[0].getText()
     self.graph.add_node(enquesta)
     self.graph.add_edge(f[0].getText(), self.items[f[3].getText()])
     for i in range(3, ctx.getChildCount() - 1):
         nx.set_node_attributes(
             self.graph,
             {self.items[f[i].getText()]: {
                  'enquesta': enquesta
              }})
         propagaEnquestaAlternatives(self.graph, self.items[f[i].getText()],
                                     enquesta)
         self.graph.add_edge(self.items[f[i].getText()],
                             self.items[f[i + 1].getText()])
     nx.set_node_attributes(
         self.graph, {
             self.items[f[ctx.getChildCount() - 1].getText()]: {
                 'enquesta': enquesta
             }
         })
     propagaEnquestaAlternatives(
         self.graph, self.items[f[ctx.getChildCount() - 1].getText()],
         enquesta)
     self.graph.add_edge(self.items[f[ctx.getChildCount() - 1].getText()],
                         "END")
예제 #4
0
 def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
     g = ctx.getChildren()
     n = ctx.getChildCount()
     l = [next(g) for i in range(n)]
     first = l[0].getText()
     self.AST.graph["name"] = first
     for i in range(3, n - 1):
         self.AST.add_edge(first, self.items[l[i].getText()])
         first = self.items[l[i].getText()]
     self.AST.add_edge(first, l[n - 1].getText())
     return self.visitChildren(ctx)
예제 #5
0
    def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
        g = ctx.getChildren()  #obtenir els fills [ID ':' 'ENQUESTA' ID*]
        fills = ctx.getChildCount()
        l = [(next(g)).getText() for i in range(fills)]
        pre = l[0]
        suc = self.items[l[3]][0]
        self.ast.add_edge(pre, suc, color='black', tag="")
        pre = suc
        for i in range(4, fills):
            suc = self.items[l[i]][0]
            self.ast.add_edge(pre, suc, color='black', tag="")
            pre = suc

        self.ast.add_edge(pre, 'END', color='black', tag="")
예제 #6
0
 def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
     num = ctx.getChildCount()
     g = ctx.getChildren()
     L = [next(g) for i in range(num)]
     title = L[0].getText()
     end = L[num - 1].getText()
     self.G.add_node(title, type='enquesta_init')
     self.G.add_node(end, type='enquesta_end')
     anterior = title
     for j in range(3, num - 1):
         id = self.items[L[j].getText()]
         self.G.add_edge(anterior, id, type='enquesta')
         anterior = id
     self.G.add_edge(anterior, end, type='enquesta')
     self.G.graph['title'] = title
예제 #7
0
 def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
     g = ctx.getChildren()
     n = ctx.getChildCount()
     ll = [next(g) for i in range(n)]
     # nombre de la enquesta en first
     first = ll[0].getText()
     self.startNode = first
     for i in range(3, n):
         self.AST.add_edge(first,
                           self.items[ll[i].getText()],
                           color="black",
                           labelAlternativa="",
                           labelItem="")
         first = self.items[ll[i].getText()]
     self.AST.add_edge(first,
                       "END",
                       color="black",
                       labelAlternativa="",
                       labelItem="")
     return self.visitChildren(ctx)
예제 #8
0
 def visitEnquesta(self, ctx: EnquestesParser.EnquestaContext):
     print("Visit Enquesta: count=" + str(ctx.getChildCount()))
     g = ctx.getChildren()
     l = [next(g) for i in range(ctx.getChildCount())]
     EnquestesVisitor.idEnquesta = (l[0]).getText()
     for x in l:
         print("enquesta text=" + x.getText())
     EnquestesVisitor.myGraph.add_node((l[0]).getText())
     parentNode = (l[0]).getText()
     for y in range(5, ctx.getChildCount() - 1, 2):
         EnquestesVisitor.myGraph.add_edge(
             parentNode,
             EnquestesVisitor.dictItems[(l[y]).getText()],
             label='',
             color='black')
         parentNode = EnquestesVisitor.dictItems[(l[y]).getText()]
         self.visit(l[y])
     EnquestesVisitor.myGraph.add_edge(parentNode,
                                       "END",
                                       label='',
                                       color='black')