| Did you know ... | Search Documentation: |
| Hierarchy |
Generate a tree from facts
The example below will create a graphical representation from facts
of the form is_a(Parent, Son), which are supposed to span a
single-inheritance tree.
Modern (2002 :-) Explorer-like hierarchies can be created using this
class too. A high-level library is in library(pce_toc)
(Table Of Contents). This library is also used by most hierarchies in
the XPCE and Prolog development tools.
% display_hierarchy(+Root)
% Show a window with the hierarchy described by is_a(Parent, Son)
% starting from the given root.
display_hierarchy(Root) :-
new(P, picture(string('Hierarchy from %s', Root))),
send(P, open),
send(P, display, tree(new(Node, node(text(Root))))),
expand_hierarchy(Root, Node).
expand_hierarchy(Root, Node) :-
forall(is_a(Root, Sub),
(send(Node, son, new(Son, node(text(Sub)))),
expand_hierarchy(Sub, Son))).
% Example database
is_a(species, plant).
is_a(species, animal).
is_a(animal, mamal).
is_a(mamal, monkey).
is_a(mamal, horse).
% Start the demo
:- display_hierarchy(species).