Mercurial > hg > dml-open-cliopatria
comparison cpack/dml/config-available/dml.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 /* Part of DML (Digital Music Laboratory) | |
2 Copyright 2014-2015 Samer Abdallah, University of London | |
3 | |
4 This program is free software; you can redistribute it and/or | |
5 modify it under the terms of the GNU General Public License | |
6 as published by the Free Software Foundation; either version 2 | |
7 of the License, or (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public | |
15 License along with this library; if not, write to the Free Software | |
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 */ | |
18 | |
19 :- module(dml, | |
20 [ call_debugging/2 | |
21 , call_nodebug/1 | |
22 , view_computations/0 | |
23 , start_matlab/0 | |
24 , stop_matlab/0 | |
25 , start_r_server/0 | |
26 , update/1 ]). | |
27 | |
28 /** <module> DML main loader | |
29 */ | |
30 | |
31 :- set_prolog_flag(double_quotes, string). | |
32 :- debug_message_context(+time('%FT%T')). | |
33 | |
34 user:file_search_path(memo, cp_application(memo_db)). | |
35 | |
36 :- use_module(cp_application('config-enabled/dml_permission')). | |
37 | |
38 :- use_module(library(rcutils)). | |
39 :- use_module(library(http/http_dispatch)). | |
40 :- use_module(skin(minimal)). | |
41 :- use_module(library(dml_data)). | |
42 :- use_module(applications(callgraph_ui)). | |
43 :- use_module(applications(audio_ui)). | |
44 :- use_module(applications(score_ui)). | |
45 :- use_module(applications(csv_ui)). | |
46 :- use_module(applications(memo_ui)). | |
47 :- use_module(applications(transcription_ui)). | |
48 :- use_module(applications(dml_overview)). | |
49 | |
50 :- use_module(library(code_cache)). | |
51 :- use_module(library(dml_crawler)). | |
52 :- use_module(library(dml_spotify)). | |
53 :- use_module(library(dml_musicbrainz)). | |
54 :- use_module(library(dml_swish)). | |
55 :- use_module(library(dml_misc)). | |
56 :- use_module(library(musiclab)). | |
57 :- use_module(library(rdfutils)). | |
58 :- use_module(library(dlogic)). | |
59 :- use_module(library(dataset)). | |
60 :- use_module(library(mlserver), except([start_matlab/0,start_matlab/1])). | |
61 :- use_module(library(real)). | |
62 :- use_module(library(backend_json)). | |
63 :- use_module(library(dovamp)). | |
64 :- use_module(api(matlab)). | |
65 :- use_module(api(r_plot)). | |
66 :- use_module(api(archive)). | |
67 :- use_module(api(dmlvis)). | |
68 :- use_module(api(perspectives)). | |
69 :- use_module(api(transcription)). | |
70 :- use_module(components(audio)). | |
71 :- use_module(cliopatria(hooks)). | |
72 | |
73 cliopatria_openid:insecure_host('mirg.city.ac.uk'). | |
74 | |
75 | |
76 % Hooks for audio related services | |
77 cp_audio:audio_file(URI,File,Fmt) :- beets_p2r:audio_file(URI,File,Fmt). | |
78 cp_audio:audio_file(URI,File,Fmt) :- charm_p2r:audio_file(URI,File,Fmt). | |
79 cp_audio:audio_file(URI,File,Fmt) :- bl_p2r:audio_file(URI,File,Fmt). | |
80 cp_audio:audio_file(URI,File,Fmt) :- mazurka_p2r:audio_file(URI,File,Fmt). | |
81 | |
82 cp_audio:audio_link(URI,Link,just(mp3)) :- bl_p2r:audio_link(URI,Link). | |
83 cp_audio:audio_link(URI,URL,just(Fmt)) :- | |
84 bl_p2r:audio_file(URI,File,just(Fmt)), | |
85 file_permission(File,public), | |
86 http_link_to_id(audio_get,[uri(URI),format(Fmt)],URL). | |
87 cp_audio:audio_link(URI,Link,just(mp3)) :- charm_p2r:audio_link(mp3,URI,Link). | |
88 cp_audio:audio_link(URI,URL,just(Fmt)) :- | |
89 Formats=[ogg,mp3], % in order of preference | |
90 ( beets_p2r:audio_file(URI,File,just(Orig)) | |
91 ; mazurka_p2r:audio_file(URI,File,just(Orig)) | |
92 ), | |
93 file_permission(File,public), | |
94 (member(Orig,Formats) -> member(Fmt,Formats); member(Fmt,[Orig|Formats])), | |
95 http_link_to_id(audio_get,[uri(URI),format(Fmt)],URL). | |
96 | |
97 %:- rdf_set_cache_options([enabled(true),global_directory(cache)]). | |
98 | |
99 % ------------------ string portrayal ------------- | |
100 % user:portray(String) :- | |
101 % string(String), !, | |
102 % truncate(50,String,Short), | |
103 % writeq(Short). | |
104 | |
105 % truncate(Max,S,S) :- string_length(S,L), L<Max, !. | |
106 % truncate(Max,S1,S3) :- | |
107 % L is Max-3, | |
108 % sub_string(S1,0,L,_,S2), | |
109 % string_concat(S2,"...",S3). | |
110 | |
111 % Adjust menus | |
112 cliopatria:menu_item(900=query/isearch, 'Interactive faceted search'). | |
113 cliopatria:menu_item(900=places/http_skos_browser, 'SKOS Concept browser'). | |
114 cliopatria:menu_item(800=help/dml_overview, 'DML overview'). | |
115 cliopatria:menu_item(800=admin/job_view, 'Current jobs'). | |
116 | |
117 warm_indices :- | |
118 ignore(rdf(s, _, _)), | |
119 ignore(rdf(_, p, _)), | |
120 ignore(rdf(_, _, o)), | |
121 ignore(rdf(s, p, _)), | |
122 ignore(rdf(_, p, o)), | |
123 ignore(rdf(s, p, o)), | |
124 ignore(rdf(_, _, _, g)), | |
125 ignore(rdf(s, _, _, g)), | |
126 ignore(rdf(_, p, _, g)). | |
127 | |
128 % :- rdf_register_prefix(dmlcla,'http://dml.org/cla#'). | |
129 % :- initialization rdf_load(dml('cla/ontologies/dmlclaOntology.n3')). | |
130 :- initialization open_log, maplist(debug,[dmlvis(perspective),dmlvis(error),dmlvis(response)]). | |
131 :- initialization persistent_history('.dml.history',[interval(300)]), confirm_on_halt. | |
132 :- initialization p2r_import(memo_p2r). | |
133 :- initialization | |
134 ( current_periodical(_,clean_code_cache(_),Id) | |
135 -> remove_periodical(Id) | |
136 ; true | |
137 ), | |
138 periodically(3600,clean_code_cache(3600)). | |
139 | |
140 :- dynamic log_stream/1. | |
141 open_log :- | |
142 (log_stream(S) -> close(S), retractall(log_stream(_)); true), | |
143 expand_file_name('~/var/log/dml.log',[LogFile]), | |
144 open(LogFile,append,LogStream,[buffer(line)]), nl(LogStream), | |
145 assert(log_stream(LogStream)), | |
146 debug(log), debug(log,'Started logging.',[]). | |
147 | |
148 | |
149 :- meta_predicate call_debugging(?,0), call_nodebug(0). | |
150 call_debugging(Topic,Goal) :- setup_call_cleanup(debug(Topic), Goal, nodebug(Topic)). | |
151 call_nodebug(Goal) :- | |
152 setup_call_cleanup( (setof(T,debugging(T),Topics),maplist(nodebug,Topics)), Goal, maplist(debug,Topics)). | |
153 | |
154 view_computations :- | |
155 call_debugging(computations(item),termutils:with_status_line(get_single_char(_))). | |
156 | |
157 logging(dmlvis(method)). | |
158 logging(dmlvis(perspective)). | |
159 logging(log). | |
160 | |
161 prolog:debug_print_hook(computations(item),Fmt,Args) :- | |
162 termutils:status(Fmt,Args). | |
163 | |
164 prolog:debug_print_hook(Topic,Fmt,Args) :- | |
165 logging(Topic), log_stream(S), | |
166 get_time(T), | |
167 format(S,'~@ ~w | ~@\n',[format_time(current_output,'%FT%T',T), Topic, format(Fmt,Args)]), | |
168 fail. | |
169 | |
170 update(dml) :- | |
171 debug(log,'Updating dml-cliopatria repository.',[]), | |
172 shell('cd cpack/dml && hg pull && hg update'), | |
173 make. | |
174 | |
175 start_matlab :- start_matlab([]). | |
176 start_matlab(Opts) :- mlserver:start_matlab([path([dml(matlab)])|Opts]). | |
177 start_r_server :- real:r_start_server. | |
178 | |
179 :- multifile sandbox:safe_primitive/1. | |
180 :- multifile sandbox:safe_directive/1. | |
181 sandbox:safe_primitive(dml_permissions:file_permission(_,_)). | |
182 sandbox:safe_primitive(cp_audio:audio_link(_,_,_)). | |
183 | |
184 initiate_bl_scraping(Status) :- | |
185 format('% Initiating BL audio link scraping...\n',[]), | |
186 async:async_memo(vis_cla, bl_p2r:scrape_all([],_), Status, [recompute(failed),status_var(time-progress(summary))]). | |
187 | |
188 after_load :- | |
189 warm_indices, | |
190 initiate_bl_scraping(_), | |
191 start_r_server, | |
192 start_matlab. |