Skip to content

Commit 29ed95b

Browse files
committed
TEST: Updated examples and tests to use the latest notation.
1 parent 0d17a8d commit 29ed95b

File tree

9 files changed

+140
-58
lines changed

9 files changed

+140
-58
lines changed

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```sh
44
$ swipl -s hello.pl -g view -t halt
5-
$ swipl -s loves.pl -g view -t halt
5+
$ swipl -s arc.pl -g view -t halt
66
$ swipl -s parse_tree.pl -g view -t halt
77
$ swipl -s proof_tree.pl -g view -t halt
88
```

example/arc.pl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** <application> Example of a simple arc
2+
3+
~~~sh
4+
$ swipl -s arc.pl -g export -t halt
5+
$ swipl -s arc.pl -g view -t halt
6+
~~~
7+
8+
*/
9+
10+
:- use_module(library(yall)).
11+
12+
:- use_module(library(gv)).
13+
14+
15+
16+
%! export is det.
17+
18+
export :-
19+
example_(String),
20+
gv_export('loves.svg', {String}/[Out]>>format(Out, String, [])).
21+
22+
23+
24+
%! view is det.
25+
26+
view :-
27+
example_(String),
28+
gv_view({String}/[Out]>>format(Out, String, [])).
29+
30+
31+
32+
% GENERICS %
33+
34+
example_("John -- Mary [label=loves];\n").

example/loves.svg renamed to example/arc.svg

Lines changed: 1 addition & 1 deletion
Loading

example/hello.pl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
:- module(hello, [export/0, view/0]).
1+
/** <application> “Hello, world!” GraphViz example
22
3-
/** <module> Hello, world! for GraphViz
3+
~~~sh
4+
$ swipl -s hello.pl -g export -t halt
5+
$ swipl -s hello.pl -g view -t halt
6+
~~~
47
58
*/
69

710
:- use_module(library(yall)).
811

912
:- use_module(library(gv)).
1013

11-
dot("x [label=<Hello,<BR/>world!>,shape=diamond];\n").
14+
15+
16+
%! export is det.
1217

1318
export :-
14-
dot(String),
19+
example_(String),
1520
gv_export('hello.svg', {String}/[Out]>>format(Out, String, [])).
1621

22+
23+
24+
%! view is det.
25+
1726
view :-
18-
dot(String),
27+
example_(String),
1928
gv_view({String}/[Out]>>format(Out, String, [])).
29+
30+
31+
32+
% GENERICS %
33+
34+
example_("x [label=<Hello,<BR/>world!>,shape=diamond];\n").

example/loves.pl

Lines changed: 0 additions & 19 deletions
This file was deleted.

example/parse_tree.pl

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
:- module(parse_tree, [export/0, export/1, view/0, view/1]).
1+
/** <application> Parse tree example
22
3-
/** <module> Parse tree example
3+
~~~sh
4+
$ swipl -s parse_tree.pl -g export -t halt
5+
$ swipl -s parse_tree.pl -g view -t halt
6+
~~~
47
58
*/
69

@@ -10,25 +13,41 @@
1013
:- use_module(library(gv)).
1114
:- use_module(library(term_ext)).
1215

16+
17+
18+
%! export is det.
19+
%! export(+Tree:tree) is det.
20+
1321
export :-
14-
tree(Tree),
22+
example_(Tree),
1523
export(Tree).
1624

25+
1726
export(Tree) :-
1827
gv_export('parse_tree.svg', {Tree}/[Out]>>export_tree_(Out, Tree, _)).
1928

20-
tree(s(np(det(the),n(cat)),vp(v(loves),np(det(the),n(dog))))).
29+
30+
31+
%! view is det.
32+
%! view(+Tree:tree) is det.
2133

2234
view :-
23-
tree(Tree),
35+
example_(Tree),
2436
view(Tree).
2537

38+
2639
view(Tree) :-
2740
gv_view({Tree}/[Out]>>export_tree_(Out, Tree, _)).
2841

42+
43+
44+
% GENERICS %
45+
46+
example_(s(np(det(the),n(cat)),vp(v(loves),np(det(the),n(dog))))).
47+
2948
export_tree_(Out, Tree, Id) :-
3049
Tree =.. [Op|Trees],
3150
ascii_id(Id),
32-
dot_node_id(Out, Id, [label(Op)]),
51+
dot_node_id(Out, Id, options{label: Op}),
3352
maplist(export_tree_(Out), Trees, Ids),
3453
maplist(dot_edge_id(Out, Id), Ids).

example/proof_tree.pl

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
:- module(proof_tree, [export/0, export/1, view/0, view/1]).
1+
/** <application> Proof tree example
22
3-
/** <module> Proof tree example
3+
~~~sh
4+
$ swipl -s proof_tree.pl -g export -t halt
5+
$ swipl -s proof_tree.pl -g view -t halt
6+
~~~
47
58
*/
69

@@ -9,32 +12,57 @@
912

1013
:- use_module(library(gv)).
1114

15+
16+
17+
%! export is det.
18+
%! export(+Proof:tree) is det.
19+
1220
export :-
13-
proof(Proof),
21+
example_(Proof),
1422
export(Proof).
1523

24+
1625
export(Proof) :-
17-
gv_export('proof_tree.svg', {Proof}/[Out]>>export_proof_(Out, Proof), [directed(true)]).
26+
gv_export(
27+
'proof_tree.svg',
28+
{Proof}/[Out]>>export_proof_(Out, Proof),
29+
options{directed: true}
30+
).
31+
32+
1833

19-
proof(t(rdfs(3), ∈(class,class), [t(axiom(rdfs), range(range,class), []),
20-
t(axiom(rdfs), range(⊆,class), [])])).
34+
%! view is det.
35+
%! view(+Proof:tree) is det.
2136

2237
view :-
23-
proof(Proof),
38+
example_(Proof),
2439
view(Proof).
2540

41+
2642
view(Proof) :-
27-
gv_view({Proof}/[Out]>>export_proof_(Out, Proof), [directed(true)]).
43+
gv_view(
44+
{Proof}/[Out]>>export_proof_(Out, Proof),
45+
options{directed: true}
46+
).
47+
48+
49+
50+
% GENERICS %
2851

2952
export_proof_(Out, Proof) :-
30-
Proof = t(Rule,Concl,SubProofs),
53+
Proof = tree(Rule,Concl,SubProofs),
3154
dot_node(Out, Concl),
3255
dot_node(Out, Proof, [label(Rule)]),
3356
dot_arc(Out, Concl, Proof),
3457
maplist(export_subproof_(Out, Proof), SubProofs).
3558

3659
export_subproof_(Out, Proof, SubProof) :-
37-
SubProof = t(_,Prem,_),
60+
SubProof = tree(_,Prem,_),
3861
dot_node(Out, Prem),
3962
dot_arc(Out, Proof, Prem),
4063
export_proof_(Out, SubProof).
64+
65+
example_(tree(rdfs(3),
66+
∈(class,class),
67+
[tree(axiom(rdfs), range(range,class), []),
68+
tree(axiom(rdfs), range(⊆,class), [])])).

prolog/gv.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
write_to_file(
9393
File,
9494
gv_export_stream_(Goal_1, Format, Type, Method, Options),
95-
[type(Type)]
95+
options{type: Type}
9696
).
9797

9898
gv_export_default_format_(File, DefaultFormat) :-

test/test_graphviz.pl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
/** <test> Tests for the GraphViz library
2+
3+
*/
4+
15
:- use_module(library(apply)).
26
:- use_module(library(plunit)).
37
:- use_module(library(process)).
48
:- use_module(library(yall)).
59

610
:- use_module(library(gv)).
711
:- use_module(library(os_ext)).
12+
:- use_module(library(term_ext)).
13+
14+
:- begin_tests(gv).
815

916
:- meta_predicate
1017
test_gv_export(+, 1),
1118
test_gv_export(+, 1, +).
1219

13-
:- begin_tests(gv).
14-
1520
test(hello, [cleanup(delete_file(File))]) :-
1621
File = 'hello.pdf',
1722
test_gv_export(
@@ -25,50 +30,50 @@
2530
File = 'hello2.pdf',
2631
test_gv_export(
2732
File,
28-
[Out]>>dot_node(Out, hello, [label(["Hello,","world!"]),shape(diamond)])
33+
[Out]>>dot_node(Out, hello, options{label: ["Hello,","world!"], shape: diamond})
2934
).
3035

3136

3237

33-
test(loves, [cleanup(delete_file(File))]) :-
34-
File = 'loves.svg',
35-
test_gv_export(File, [Out]>>format(Out, "John -- Mary [label=loves]", [])).
38+
test(arc, [cleanup(delete_file(File))]) :-
39+
File = 'arc.svg',
40+
test_gv_export(File, [Out]>>format(Out, "John -- Mary [label=arc]", [])).
3641

3742

3843

3944
test(parse_tree, [cleanup(delete_file(File))]) :-
4045
File = 'parse_tree.svg',
41-
Tree = s(np(det(the),n(cat)),vp(v(loves),np(det(the),n(dog)))),
46+
Tree = s(np(det(the),n(cat)),vp(v(knows),np(det(the),n(dog)))),
4247
test_gv_export(File, {Tree}/[Out]>>export_tree_(Out, Tree, _)).
4348

4449
export_tree_(Out, Tree, Id) :-
4550
Tree =.. [Op|Trees],
4651
ascii_id(Id),
47-
dot_node_id(Out, Id, [label(Op)]),
52+
dot_node_id(Out, Id, options{label: Op}),
4853
maplist(export_tree_(Out), Trees, Ids),
4954
maplist(dot_edge_id(Out, Id), Ids).
5055

5156

5257

5358
test(proof_tree, [cleanup(delete_file(File))]) :-
5459
File = 'proof_tree.svg',
55-
Proof = t(rdfs(3),≡(class,class),[t(axiom(rdfs),range(range,class),[]),
56-
t(axiom(rdfs),range(⊆,class),[])]),
60+
Proof = tree(rdfs(3),≡(class,class),[tree(axiom(rdfs),range(range,class),[]),
61+
tree(axiom(rdfs),range(⊆,class),[])]),
5762
test_gv_export(
5863
File,
5964
{Proof}/[Out]>>export_proof_(Out, Proof),
60-
[directed(true)]
65+
options{directed: true}
6166
).
6267

6368
export_proof_(Out, Tree) :-
64-
Tree = t(Rule,Concl,SubTrees),
69+
Tree = tree(Rule,Concl,SubTrees),
6570
dot_node(Out, Concl),
66-
dot_node(Out, Tree, [color(green),label(Rule)]),
71+
dot_node(Out, Tree, options{color: green, label: Rule}),
6772
dot_arc(Out, Concl, Tree),
6873
maplist(export_subproof_(Out, Tree), SubTrees).
6974

7075
export_subproof_(Out, Tree, SubTree) :-
71-
SubTree = t(_,Prem,_),
76+
SubTree = tree(_,Prem,_),
7277
dot_node(Out, Prem),
7378
dot_arc(Out, Tree, Prem),
7479
export_proof_(Out, SubTree).
@@ -83,7 +88,7 @@
8388
%! test_gv_export(+File:atom, :Goal_1, +Options:list(compound)) is det.
8489

8590
test_gv_export(File, Goal_1) :-
86-
test_gv_export(File, Goal_1, []).
91+
test_gv_export(File, Goal_1, options{}).
8792

8893

8994
test_gv_export(File, Goal_1, Options) :-

0 commit comments

Comments
 (0)