swi-prolog から graphviz を利用
prolog で得た実行結果をグラフィカルに示す方法の実験をしてみた。
prolog から graphviz を呼び出して、svg ファイルを生成。
(ぜんぜん prolog らしくないアプローチだけど。
グラフ生成は graphviz という専門プログラムの任せるのが簡単だし).
$ cat link.pl
link(a,b).
link(a,c).
link(b,d).
link(c,d).
link(d,a).draw:-
tell('temp.dot'),
writeln('digraph sample {'),
forall((link(X,Y), concat_atom([X,Y],' -> ', W)), writeln(W)),
writeln('}'),
told.genSVG :- draw, shell('dot -Tsvg temp.dot -o temp.svg', _Status).
$ swipl
Welcome to SWI-Prolog (Multi-threaded, Version 5.6.47)
Copyright (c) 1990-2007 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.For help, use ?- help(Topic). or ?- apropos(Word).
?- [link].
% link compiled 0.01 sec, 1,844 bytesYes
?- genSVG.(process:734): Pango-WARNING **: Error loading GDEF table 85
(process:734): Pango-WARNING **: Error loading GSUB table 85
(process:734): Pango-WARNING **: Error loading GPOS table 85
Yes
?-
temp.dot, temp.svg が生成される。
temp.svg を firefox で表示させると、こんなふうになる。
同じ事を erlang でもやってみつもりだ。(erlang の説明書籍を買ったし)
« ピックアップ:グーグルのサーバ数は日本の年間サーバ出荷台数より多い, 「MacBook」でハードドライブ問題, etc... | トップページ | google.co.jp での "xfy” 検索 100 位の圏外へ »
この記事へのコメントは終了しました。
« ピックアップ:グーグルのサーバ数は日本の年間サーバ出荷台数より多い, 「MacBook」でハードドライブ問題, etc... | トップページ | google.co.jp での "xfy” 検索 100 位の圏外へ »
コメント