gvterm - This library translates complex Prolog terms into Graphviz (dot) output for graphical rendering.
While gvterm works for a quick and fast way see: SWISH - The term render plugin
Thanks Jan W. (ref)
This example is done using Windows 10.
Directory: C:/Users/Groot/Documents
- Change as needed.
Using your favorite editor
a. Create file: example_001.pl
:- module(example_001,
[test/0]).
:- use_module(library(gvterm)).
:-op(500, yfx, [bool1, bool2, bool3]).
:-op(700, xfx, [my_and]). % my_and == logic and
eq(a bool1 b my_and c bool2 d).
test :-
eq(E),
term_to_dot(E).
Using SWI-Prolog
a. Install pack gvterm
?- pack_install(gvterm).
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
Install gvterm@1.1 from http://www.swi-prolog.org/download/pack/gvterm-1.1.tgz Y/n?
% Contacting server at https://www.swi-prolog.org/pack/query ... ok
% "gvterm-1.1.tgz" was downloaded 122 times
Package: gvterm
Title: Show Prolog terms using graphviz
Installed version: 1.1
Author: Jan Wielemaker <J.Wielemaker@vu.nl>
Download URL: http://www.swi-prolog.org/download/pack/gvterm-*.tgz
Install "gvterm-1.1.tgz" (22,333 bytes) Y/n?
true.
b. Change to directory with example_001.pl
?- working_directory(_,'C:/Groot/Groot/Documents').
true.
c. Load Prolog code
?- ['example_001'].
true.
d. Create dot file: test.dot
?- tell('./test.dot'),test,told.
true.
- Using command line
a. Ensure GraphViz installed and dot command can run
Note: For this to work the location of the dot
command needs to be known. An easy way to just set the path, e.g. C:\Users\Groot>SET PATH="C:\Program Files (x86)\Graphviz2.38\bin"
C:\Users\Groot>dot -V
dot - graphviz version 2.38.0 (20140413.2041)
b. Change to directory with file test.dot
C:\Users\Groot>cd "C:\Users\Groot\Documents"
c. Convert dot file to SVG
C:\Users\Groot\Documents>dot -Tsvg test.dot -o test.svg
d. View SVG file
Note: This should start up your preferred SVG viewer, probably an Internet browser, and show the file test.svg
C:\Users\Groot\Documents>start test.svg
Notes:
This is a derivative work of Operands and equation questions
xdot is a Python application included in gvterm for displaying the output; it was not used for this demonstration, see gvterm readme.md.
GitHub repository: gvterm