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.
TkDAG
Frame ObjectsA 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.
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
OPTIONS.table.word.font.family : helvetica
OPTIONS.table.word.font.weight : bold
OPTIONS.table.word.font.size : 12
OPTIONS.table.word.color : black
OPTIONS.table.word.vsep : 20
OPTIONS.table.label.font.family : courier
OPTIONS.table.label.font.weight : normal
OPTIONS.table.label.font.size : 12
OPTIONS.table.edge.color : black
OPTIONS.table.edge.pos : edge
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
OPTIONS.table.hstep : 20
OPTIONS.table.margin.top : 20
OPTIONS.table.margin.bottom : 20
OPTIONS.table.margin.left : 20
OPTIONS.table.margin.right : 20
OPTIONS.table.vline.color : orange
OPTIONS.table.vline.width : 2
OPTIONS.table.vline.omitable : true
OPTIONS.table.sline.color : slateblue
OPTIONS.table.vline.width : 2
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:
|
|
This package can be installed using ozmake
:
ozmake -U tkDAG.pkg