[Pyparsing] parsing a string that represents a tree
Brought to you by:
ptmcg
From: gyro f. <gyr...@gm...> - 2011-09-05 00:47:11
|
Hi, I have a set of strings that look similar to this: N1-(N2,N3-(N4,N5),N6-(N7,N8-(N9,N10),N11)) Each string essentially represents a tree structure, where the 'N#' represent nodes and the '-' are connections or edges. Entries in parentheses represent branches from the previous node. I would like to parse the string and then enumerate all of the paths through the tree, starting at the root and out to each leaf. In the case of the above string, the desired output would be as follows: N1-N2 N1-N3-N4 N1-N3-N5 N1-N6-N7 N1-N6-N11 N1-N6-N8-N9 N1-N6-N8-N10 I would greatly appreciate hints on how to use Pyparsing to help achieve this functionality. Thank you. -g |