comparison cpack/dml/examples/visuals.pl @ 0:718306e29690 tip

commiting public release
author Daniel Wolff
date Tue, 09 Feb 2016 21:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:718306e29690
1 :- use_module(library(mlserver)).
2 :- use_module(library(semweb/rdf_label)).
3 :- use_module(components(matlab)).
4 :- use_module(components(audio)).
5 :- use_module(components(score)).
6 :- use_rendering(matlab,[size(12,8),cache(true)]).
7 :- use_rendering(html).
8
9 %:- include(search).
10
11 /** <examples>
12 ?- test_plot(X).
13 ?- test_html(X).
14 ?- X=html(\figure(??bar(rand(10,1)),5,3)), Y=fig(plot(1:10),5,3), hold.
15 ?- ml_fig(??bar(1:10),5,3), ml_fig(??plot(sin(0:0.05:12)),5,3).
16 ?- finder_player(title(brandenburg),Player).
17 ?- finder_player(title('prelude and fugue')/\composer(bach),Player).
18 ?- R::title(prelude)/\title(cello)/\humdrum,
19 X=html(\score(R,150)),
20 Y=html(\score_audio_player(R)).
21
22 */
23
24 bar(Opts,X-Y,Fig) :- decorate(fig(bar(X,Y),15,5),Opts,Fig).
25 plot(Opts,X-Y,Fig) :- decorate(fig(plot(X,Y),15,5),Opts,Fig).
26
27 ml_fig(Cmd,W,H) :- write_html(\figure(Cmd,W,H)).
28
29 decorate(fig(Cmd,W,H),Opts,fig(Cmd2,W,H)) :-
30 ( option(labels(XL,YL),Opts)
31 -> Cmd1 = (Cmd;xlabel(q(XL));ylabel(q(YL)))
32 ; Cmd1 = Cmd
33 ),
34 ( option(title(T),Opts)
35 -> Cmd2 = (Cmd1;title(q(T)))
36 ; Cmd2 = Cmd1
37 ).
38
39
40 /* Note that there is a subtle problem which affects
41 * the use of the figure//3 HTML component: the first argument
42 * is a module-qualified goal, and gets tagged with the name
43 * of the module created to run the current pengine query.
44 * The component results in an HTML IMAGE element whos
45 * URL encodes the goal and its module. If the pengine query
46 * has terminated by the time the image URL is dereferenced,
47 * the call fails. Thus, to make this work with write_html/1
48 * you need either a delay (eg sleep(3)) after the call, to allow
49 * the image to render before the query terminates, or you need
50 * to introduce some nondeterminism so that the query remains
51 * active. To make it work with html term rendering, only the
52 * non-determinism method will work. To do this, you can add the
53 * following hold as a final goal - it succeeds but leaves a choice point.
54 */
55 hold :- true; fail.
56
57 test_plot(fig(plot(X,X.^2))) :- X= -1:0.01:1.
58
59 test_html(html(span([b(hello),' ',i(world)]))).
60 test_html(html(\figure(??imagesc(magic(5)),3,3))).
61 test_html(_) :- fail.
62