Skip to content

Instantly share code, notes, and snippets.

@Koura
Created February 2, 2021 10:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koura/8596633401a37386f093b750c22b7fab to your computer and use it in GitHub Desktop.
Save Koura/8596633401a37386f093b750c22b7fab to your computer and use it in GitHub Desktop.
Visualizing relations with Prolog
/*
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').
@Koura
Copy link
Author

Koura commented Feb 2, 2021

Following these instructions you should now be shown an image that looks like this:
#

abc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment