Daniel@0: :- use_module(library(mlserver)). Daniel@0: :- use_module(library(semweb/rdf_label)). Daniel@0: :- use_module(components(matlab)). Daniel@0: :- use_module(components(audio)). Daniel@0: :- use_module(components(score)). Daniel@0: :- use_rendering(matlab,[size(12,8),cache(true)]). Daniel@0: :- use_rendering(html). Daniel@0: Daniel@0: %:- include(search). Daniel@0: Daniel@0: /** Daniel@0: ?- test_plot(X). Daniel@0: ?- test_html(X). Daniel@0: ?- X=html(\figure(??bar(rand(10,1)),5,3)), Y=fig(plot(1:10),5,3), hold. Daniel@0: ?- ml_fig(??bar(1:10),5,3), ml_fig(??plot(sin(0:0.05:12)),5,3). Daniel@0: ?- finder_player(title(brandenburg),Player). Daniel@0: ?- finder_player(title('prelude and fugue')/\composer(bach),Player). Daniel@0: ?- R::title(prelude)/\title(cello)/\humdrum, Daniel@0: X=html(\score(R,150)), Daniel@0: Y=html(\score_audio_player(R)). Daniel@0: Daniel@0: */ Daniel@0: Daniel@0: bar(Opts,X-Y,Fig) :- decorate(fig(bar(X,Y),15,5),Opts,Fig). Daniel@0: plot(Opts,X-Y,Fig) :- decorate(fig(plot(X,Y),15,5),Opts,Fig). Daniel@0: Daniel@0: ml_fig(Cmd,W,H) :- write_html(\figure(Cmd,W,H)). Daniel@0: Daniel@0: decorate(fig(Cmd,W,H),Opts,fig(Cmd2,W,H)) :- Daniel@0: ( option(labels(XL,YL),Opts) Daniel@0: -> Cmd1 = (Cmd;xlabel(q(XL));ylabel(q(YL))) Daniel@0: ; Cmd1 = Cmd Daniel@0: ), Daniel@0: ( option(title(T),Opts) Daniel@0: -> Cmd2 = (Cmd1;title(q(T))) Daniel@0: ; Cmd2 = Cmd1 Daniel@0: ). Daniel@0: Daniel@0: Daniel@0: /* Note that there is a subtle problem which affects Daniel@0: * the use of the figure//3 HTML component: the first argument Daniel@0: * is a module-qualified goal, and gets tagged with the name Daniel@0: * of the module created to run the current pengine query. Daniel@0: * The component results in an HTML IMAGE element whos Daniel@0: * URL encodes the goal and its module. If the pengine query Daniel@0: * has terminated by the time the image URL is dereferenced, Daniel@0: * the call fails. Thus, to make this work with write_html/1 Daniel@0: * you need either a delay (eg sleep(3)) after the call, to allow Daniel@0: * the image to render before the query terminates, or you need Daniel@0: * to introduce some nondeterminism so that the query remains Daniel@0: * active. To make it work with html term rendering, only the Daniel@0: * non-determinism method will work. To do this, you can add the Daniel@0: * following hold as a final goal - it succeeds but leaves a choice point. Daniel@0: */ Daniel@0: hold :- true; fail. Daniel@0: Daniel@0: test_plot(fig(plot(X,X.^2))) :- X= -1:0.01:1. Daniel@0: Daniel@0: test_html(html(span([b(hello),' ',i(world)]))). Daniel@0: test_html(html(\figure(??imagesc(magic(5)),3,3))). Daniel@0: test_html(_) :- fail. Daniel@0: