Created
February 2, 2021 10:09
-
-
Save Koura/8596633401a37386f093b750c22b7fab to your computer and use it in GitHub Desktop.
Visualizing relations with Prolog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Prerequite: graphviz, prolog | |
Install (ubuntu): apt install graphviz swi-prolog | |
Usage: | |
- launch `prolog` from the terminal in the same folder as this file | |
- consult(relations). | |
- tell('./relations.gv'), graph(relation),told. | |
- halt. | |
- dot -Tjpg relations.gv | display | |
*/ | |
%Replace with your own relations | |
relation(a, b). | |
relation(a, c). | |
%You can leave this as is | |
graph(Fact2) :- | |
format('digraph ~s {~n', [Fact2]), | |
forall(call(Fact2, From, To), format(' ~s -> ~s;~n', [From, To])), | |
format('}\n'). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Following these instructions you should now be shown an image that looks like this:
#