TkDAG

Denys Duchier

provides
x-ozlib://duchier/coli/TkDAG.ozf

Purpose

This module implements support for graphically displaying word-DAGs. A word-DAG is a Directed Acyclic Graph where the nodes correspond to the words of a sentence. Essentially, this means that we will present the nodes arranged horizontally in a sequential fashion, but at different heights depending on their depth in the DAG, and with down-slanted (directed) edges between them.

Usage

TkDAG Frame Objects

A frame for displaying word-DAGs is created as follows: {New TkDAG.'class' init(parent:WINDOW tkDAG:OPTIONS) ?FRAME} where the tkDAG:OPT is optional. OPTIONS is an options database (documented later) and permits to control the way word-DAGs are displayed. It's role at frame-creation time is minimal (stipulates a color for the canvas background while it is still empty).

Now your FRAME is ready for displaying word-DAGs: {FRAME show(NODES EDGES OPTIONS)} where NODES is a list of node descriptions, EDGES a list of edge descriptions, and OPTIONS is an options database.

NODES is a list of records of the form: o(index:I string:S1 label:S2) The index feature represents the position of the word in the sentence and uniquely identifies the node: nodes are assumed to be numbered consecutively from 1 to N (although they do not need to be given in this order in list NODES). The string feature provides a string which is the written form of the word. Finally, feature label is optional, and, when given, provides a node label.

EDGES is a list of records of the form: o(src:I dst:J label:S) where feature src gives the index of the source node and feature dst the index of the destination node. Feature label is optional, and, when given, provides a label for the edge.

Options Databases

An option database can be created as follows: {TkDAG.newOptions ?OPTIONS} or by invoking the clone operation of an existing options database: {OPTIONS.clone ?OPTIONS2} Such a database consists essentially of nested dictionaries which can be modified through feature assignment. The keys meaningful to TkDAG together with their default values are described below:

OPTIONS.table.bg : ivory
background color for the canvas in which word-DAGs are displayed

OPTIONS.table.word.font.family : helvetica
OPTIONS.table.word.font.weight : bold
OPTIONS.table.word.font.size : 12
font for the written form of words

OPTIONS.table.word.color : black
color for the written form of words

OPTIONS.table.word.vsep : 20
minimum height of the vertical line drawn between the written form of a word and its corresponding node

OPTIONS.table.label.font.family : courier
OPTIONS.table.label.font.weight : normal
OPTIONS.table.label.font.size : 12
font for the labels

OPTIONS.table.edge.color : black
color for the labels

OPTIONS.table.edge.pos : edge
where to place an edge label. If the value is edge, then the label is centered in the middle of the edge. If the value is node, then the label is displayed just above the destination node

OPTIONS.table.vstep : 20
vertical distance between two consecutive nesting levels in the DAG

OPTIONS.table.hstep : 20
minimum separation between consecutive words

OPTIONS.table.margin.top : 20
OPTIONS.table.margin.bottom : 20
OPTIONS.table.margin.left : 20
OPTIONS.table.margin.right : 20
margins to leave in the canvas around the graphical display of the DAG

OPTIONS.table.vline.color : orange
OPTIONS.table.vline.width : 2
color and width of the vertical line drawn between the written form of a word and its corresponding node

OPTIONS.table.vline.omitable : true
whether to omit drawing the vertical line if the node is isolated

OPTIONS.table.sline.color : slateblue
OPTIONS.table.vline.width : 2
color and width of the slanted edges drawn between nodes

Example

First, let's create a TkDAG frame hosted in a toplevel Tk window:

declare [TkDAG]={Link ['x-ozlib://duchier/coli/TkDAG.ozf']}
W1={New Tk.toplevel tkInit(title:'Foo')}
W2={New TkDAG.'class' tkInit(parent:W1)}
{Tk.batch [grid(columnconfigure W1 0 weight:1)
           grid(rowconfigure W1 0 weight:1)
           grid(W2 row:0 column:0 sticky:nswe)]}
OPT={TkDAG.newOptions}
Now, we can display a dependency analysis of the sentence mary pretends to read a book as follows:

{W2 show([o(index:1 string:mary)
          o(index:2 string:pretends)
          o(index:3 string:to)
          o(index:4 string:read)
          o(index:5 string:a)
          o(index:6 string:book)]
         [o(src:2 dst:1 label:subj)
          o(src:2 dst:4 label:vinf)
          o(src:4 dst:3 label:part)
          o(src:4 dst:6 label:obj)
          o(src:6 dst:5 label:det)]
         OPT)}

A corresponding graph of thematic role dependencies is obtained as follows:

{W2 show([o(index:1 string:mary)
          o(index:2 string:pretends)
          o(index:3 string:to)
          o(index:4 string:read)
          o(index:5 string:a)
          o(index:6 string:book)]
         [o(src:2 dst:1 label:agent)
          o(src:2 dst:4 label:'prop')
          o(src:4 dst:1 label:agent)
          o(src:4 dst:6 label:patient)]
         OPT)}

Installation

This package can be installed using ozmake: ozmake -U tkDAG.pkg


Denys Duchier