Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tree diagrams in Tcl/Tk?

Status
Not open for further replies.

maglabber

Technical User
Oct 4, 2008
1
CA
I'm not a programmer (though I've managed to cobble together useful Tcl/Tk and perl scripts, and a few simple C programs for my work). I'm a cognitive neuroscientist studying language. I want to make diagrams to visualize aspects of the phonological structure of lexicons. What I want to do is make tree diagrams that branch at each new phoneme from the beginning of a word.

I've written perl code that creates a description of the tree structure. Here's a snippet of the output for a mini-lexicon used with a neural network model. The columns are "node label", "words subordinate (words below this node, including itself)", "branches below", "terminal (does this node correspond to a word)", and then the node structure (for 'kip' below, the structure is 8.2.1, saying this node's ancestor from the 0 order level is node 8, then branch 2, then branch 1). The words in the list are 'ki (key)', 'kip (keep)', 'klak (clock)', 'klu (clue)', and 'klxb (club)'.

ki 2 1 1 8.2.
kip 1 0 1 8.2.1.
kl 3 3 0 8.3.
kla 1 1 0 8.3.1.
klak 1 0 1 8.3.1.1.
klu 1 0 1 8.3.2.
klx 1 1 0 8.3.3.
klxb 1 0 1 8.3.3.1.

I also have code that takes this as input and makes a vector of node labels compatible with the matlab treeplot command (which is inadequate for my purposes for various reasons).

I would like to graph this. The examples of tree diagrams I've found are either specific to directory hierarchies or do not allow arbitrary degrees of branching (in the simple lexicon I'm using, some nodes have as many as 14 branches).

I'd rather not re-invent the wheel. Does anyone know of any code that I could apply to this?

Thanks very much!
 
It sounds like the tree widget in the BWidgets library will do what you want:
Tree widget uses canvas to display a hierarchical list of items (called nodes). Each node is composed of a label with its own font and foreground attributes, and an optional image or window. Each node can have a list of subnodes, which can be collapsed or expanded. Each node is drawn in a single line, whose height is defined by the deltay option, so they must have at most this height. A node is uniquely identified by a string given at creation (by the insert command). The node named root is the root of the tree and is not drawn. The tree structure is directly maintained by the widget.

Do you know how to use libraries (hint: package require)?

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top