Exemple #1
0
 def _parseVertexID(self, token, graph):
     """
     Parses the given token (ID) into a text label and optional
     vertex number (e.g., "A1"). If a vertex with these two data don't 
     exist in the given graph, it is added. Otherwise, the existing 
     vertex from the graph is returned.
     """
     label = re.match('[A-z]+', token.text).group(0)
     match = re.search('[0-9]+$', token.text)
     number = match.group(0) if match is not None else None
     name = Vertex.makeName(label, number)
     vertex = graph.findVertex(name)
     if vertex == None:
         # graph doesn't contain a vertex with the label.
         vertex = Vertex(
             'v%d' % graph.numVertices,  # vertex id
             label,
             number)
         graph.addVertex(vertex)
     return vertex
Exemple #2
0
 def testMakeName(self):
     name = Vertex.makeName('A', 1)
     self.assertEqual(name, 'A1')