def edges(self): """ overrides the edges() function of digraph, to maintain the nodes mapping @rtype list(edge) @return the edges stored in this graph """ return [(self.nodesMap[u], self.nodesMap[v]) for (u, v) in digraph.edges(self)]
def getJson(self): """ @return: json representation of this graph """ # format: (unique id, (isPredicate, (minIndex, maxIndex))) entities = dict([(uid, {'predicate': bool(node.isPredicate), 'feats': self.getFeatsDic(node), 'charIndices': (0,0) if not node.text else self.nodeToCharIndices(node)}) for uid, node in self.nodesMap.items()]) edges = [(src, dest, self.edge_label((src, dest))) for (src, dest) in digraph.edges(self)] return (entities, edges)
def writeToDot(self, filename, writeLabel): """ @deprecated: use getJson instead Outputs a dot file representing this graph @type filename: string @param filename: the file in which to save the dot text """ dot = pygraph.readwrite.dot.pydot.Dot() if writeLabel: label = "\n".join([self.originalSentence]) dot.set_label(label) dot.set_labelloc("bottom") dot.set_labeljust("center") for uid in self.nodesMap: curNode = self.nodesMap[uid] dotNode = pygraph.readwrite.dot.pydot.Node() dotNode.set_shape(curNode.nodeShape) dotNode.set_name(str(uid)) dotNode.set_label("<{0}>".format(curNode)) if curNode.isPredicate: dotNode.set_color(PREDICATE_COLOR) dotNode.set_fontcolor(PREDICATE_COLOR) if curNode.features.get("top", False): dotNode.set_color(TOPNODE_COLOR) dotNode.set_fontcolor(TOPNODE_COLOR) ##### for debug ##### if curNode.features.has_key("Nominal"): dotNode.set_color("blue") dotNode.set_fontcolor("blue") if curNode.features.has_key("VADAS"): dotNode.set_color("green") dotNode.set_fontcolor("green") if curNode.features.has_key("traces"): dotNode.set_color("orange") dotNode.set_fontcolor("orange") if curNode.features.has_key("LV"): dotNode.set_color("purple") dotNode.set_fontcolor("purple") if curNode.features.has_key("heuristics"): dotNode.set_color("teal") dotNode.set_fontcolor("teal") if curNode.features.has_key("debug"): dotNode.set_color("blue") dotNode.set_fontcolor("blue") dot.add_node(dotNode) for (src, dst) in digraph.edges(self): curEdge = pygraph.readwrite.dot.pydot.Edge(src=src, dst=dst) curEdge.set_fontsize("11") label = self.edge_label((src, dst)) if label: if self.is_aux_edge((src, dst)): curEdge.set_style("dashed") curEdge.set_label(label) dot.add_edge(curEdge) if not filename: return dot dot.write(filename)