Dependency graph Prolog

56 Views Asked by At

I have a prolog file in which I have predicates of the type:

nondet_(A,B,C,D,E,F,G,H) :-
    (I = 0),
    summary_5(A,B,C,D,J,K,L,G,H),
    nondet(I,B,C,D,E,F,K,L).  

summary_5(A,B,C,D,E,F,G,H,I) :-
    (K = F),(M = 0),(N = G),
    block_10(M,B,C,D,E,F,G,K,N),
    summary_4(A,B,C,D,E,J,N,H,I).

interface_0(A,B,C,D,E) :-
    (F = 0),
    summary_5(F,A,B,C,G,H,I,D,E),
    interface_0(A,B,C,H,I).

How can I make (even using another tool) a dependency graph of predicates?

I need to generate the graph to include dependencies within the programme (which is translated into horn clauses in the prolog language)

1

There are 1 best solutions below

2
Paulo Moura On

You can use Logtalk's diagrams tool to easily generate a dependency graph for the predicates. Assuming the plain Prolog code is saved in a code.pl file and that you're running Logtalk with GNU Prolog:

| ?- {diagrams(loader), hook_objects(loader)}.
...
% (0 warnings)

(477 ms) yes
| ?- logtalk_load(code, [hook(object_wrapper_hook)]), xref_diagram::entity(code).
...
% Generating cross-referencing diagram for object code ... done

(5 ms) yes
| ?- 

This will generated a Graphviz .dot file that you can then convert to e.g. SVG:

$ cd dot_dias/
$ lgt2svg

Converting .dot files to .svg files ...
  converting code_object_xref_diagram.dot . done
Conversion done

For your sample code (note that predicates are missing in your listing):

dependency diagram:

For more details, see https://logtalk.org/manuals/devtools/diagrams.html#creating-diagrams-for-plain-prolog-files