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