contents index next

13. hdrug_show: Visualization

The libraries contain predicates to visualize trees, feature-structures and Prolog terms (including Prolog clauses). A number of different output media are available: LaTeX, Tcl/Tk, CLiG, DOT, and ordinary text output. The visualization tools are all available by means of a single generic predicate show/3.

Viewing Prolog Terms representing Feature Structures

Note that a couple of predicates are available to view Prolog terms as feature structures. Again, the predicate show/3 is available as an interface to this functionality. For example, you might try the conjunction:

Y:cat:agr <=> Y:cat:subj:cat:agr, show(fs,tk,[value(Y)]).

Instead of tk, any of the identifiers latex, user, clig, dot can be used to direct the output to a different medium. For instance, the query

Y:cat:agr <=> Y:cat:subj:cat:agr, show(fs,latex,[value(Y)]).

But if you insist on ordinary output, try:


This produces:

|cat {verb}
|    |agr <A>
|    |subj {sign}
|    |     |cat {cat}
|    |     |    |agr <A>.

Not only can you view feature structures this way, but also clauses; cf. show/3 below.

Tree Formats

The libraries contain extensive possibilities to produce output in the form of trees. Only a few declarations are needed to define what things you want to see in the tree. In effect, such declarations define a `tree format'.

In Hdrug, there can be any number of tree formats. These tree formats are named by a ground identifier. A tree format consists of three parts: the path definition indicates what part of the object you want to view as a tree; the label definition indicates how you want to print the node of a tree; and the daughter definition indicates what you consider the daughters of a node.

Because we want to be able to have multiple tree formats around, we must declare the corresponding predicates `multifile', as otherwise existing tree formats would be erased.

For example, the following predicates define a tree-format called `s' (this example is taken from the `Dcg' application).

:- multifile graphic_path/3.
:- multifile graphic_label/3.
graphic_label(s,Term,Label) :-
:- multifile graphic_daughter/4.
graphic_daughter(s,1,Term,D) :-
graphic_daughter(s,2,Term,D) :-

The first predicate defines that we want to take the semantics part of a node as the term that we want to view as a tree. The second predicate defines that for a given tree Term we want to print its functor as the node label. Finally the third predicate defines that for a given tree Term the first daughter is to be the first argument of the term, and the second daughter is to be the second argument.

As another example of a tree format definition, consider the constraint-based Categorial Grammar application. application. Here we find:

:- multifile graphic_path/3.
:- multifile graphic_label/3.
graphic_label(syn,tree(Sign,_,[_|_]),Label) :-
:- multifile graphic_daughter/4.
graphic_daughter(syn,No,tree(_,_,[H|T]),D) :-

Here, objects generally are of the form tree(Node,_,ListOfDs). Therefore, the path part of the tree format definition simply unifies the object and the tree part. The label part of the tree format definition distinguishes two cases. If there are no more daughters, then the node is a terminal, and this terminal is simply taken to be the node label. In the other case the node label is defined by a seperate predicate `cat_symbol'. This predicate changes the internal representation into some more readable format. Finally, the daughter part of the tree format definition uses the Sicstus library predicate `nth'. The effect of the definition is that the first daughter is the first element of the daughter list, etc.

Tk Output

The library defines the predicate show/3 index{show (predicate)} as a generic interface to the visualization tools. If a tree is to be displayed on the Tcl/Tk Canvas widget, then we can use this predicate by taking the desired tree format as the first argument, the atom { t tk} as the second argument, and a list of objects we want to be displayed as the third and final argument. For instance:

?- findall(object(A,B), object(A,B), Objects),

If the tree is output thru the Tk/Tcl canvas, then the nodes of the trees are buttons. For each tree format we can define what action should be undertaken if a button is pressed. This is defined by the predicate show_node/2. The first argument is the identifier of the tree format, the second argument is the current node (note: this is not the label as defined by graphic_label, but the term on the basis of which graphic_label is defined).

The following definition, from the Constraint-based Categorial Grammar application, prints the node as a feature structure in a separate Tk window.

show_node(syn,tree(Sign,[_|_],_)) :-

If this predicate is not defined then the label will simply be written out as a Prolog term to standard output.

Similarly, the predicates show_node2/2 and show_node3/2 can be used to define an action for pressing the second and third mouse-button respectively. Generally these predicates should be defined multifile.

LaTeX output

The predicate show/3 is also used to produce LaTeX output of trees. A variant of the previous example produces LaTeX:

?- findall(object(A,B), object(A,B), Objects),

This ensures that a LaTeX file is created and the appropriate shell commands are called to get ghostview to display the tree. The first argument is the name of a tree-format.

CLiG Output

A further possibility concerns is to use the CLiG system for displaying output. In that case the example becomes;

?- findall(object(A,B), object(A,B), Objects),

Dot Output

For trees, you can also use the DOT graph visualization programme.

ASCII Art Output

Ordinary text (to standard output) is available as well; in that case the identifier user is used:

?- findall(object(A,B), object(A,B), Objects),

Trees of feature structures

Trees in which each of the nodes is a feature-structure are supported for Tk output and LaTeX output. Nodes are interpreted as a description of a feature-structure if the tree format identifier matches matrix(_).

User defined action for a given node can be obtained using a tree format which matches user(_). In such a case you are responsible for displaying a given node by defining the predicate tk_tree_user_node/2 where the first argument is the label of the current node, and the second argument is a Tcl/Tk frame identifier already packed as part of the tree, which can be further worked upon.

Visualization of clauses

The third argument of the predicate show can be a clause. An is example is clause.png

Visualization of the type declarations

Refer to the predicates pretty_type/0, pretty_type/1.

contents index next