comparison cpack/dml/lib/dml_misc.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_misc, [ periodically/2, current_periodical/3, remove_periodical/1 ]).
20 /** <module> Miscellaneous hooks and initialisations
21
22 This module implements some hooks for managing the context graphs
23 which appear at the bottom of individual resource pages.
24
25 It also loads some miscellanous RDF graphs.
26
27 */
28 :- use_module(library(semweb/rdf_db)).
29 :- use_module(library(semweb/rdfs)).
30 :- use_module(library(memo)).
31 :- use_module(cliopatria(hooks)).
32
33 :- rdf_meta context_graph_class(r).
34
35 :- meta_predicate periodically(+,0).
36 :- meta_predicate current_periodical(-,0,-).
37
38 cliopatria:context_graph(URI, Triples, _) :-
39 context_graphable(URI), !,
40 maplist(rdf_global_id,[rdf:type, prov:wasDerivedFrom],Excludes),
41 findall(T, context_triple(Excludes,URI,[],T), T1),
42 sort(T1,Triples).
43
44 context_triple(Excludes,URI,Visited,T) :-
45 edge(URI,Pred,URI1,Triple),
46 \+member(Pred,Excludes),
47 ( T=Triple
48 ; \+member(URI1,Visited),
49 %context_graphable(URI1), % this follows a lot of link
50 rdfs_individual_of(URI1,event:'Event'),
51 context_triple(Excludes,URI1,[URI|Visited],T)
52 ).
53
54 edge(URI,Pred,URI1,rdf(URI,Pred,URI1)) :- rdf(URI,Pred,URI1), URI1\=literal(_).
55 edge(URI,Pred,URI1,rdf(URI1,Pred,URI)) :- rdf(URI1,Pred,URI).
56
57 context_graphable(URI) :-
58 context_graph_class(Class),
59 rdfs_individual_of(URI,Class).
60
61 context_graph_class(event:'Event').
62 context_graph_class(mo:'Signal').
63 context_graph_class(mo:'MusicalWork').
64 context_graph_class(mo:'MusicGroup').
65
66 current_periodical(Interval,Goal,Id) :- current_alarm(_,periodically(Interval,Goal),Id,_).
67 remove_periodical(Id) :- remove_alarm(Id).
68
69 periodically(Interval,Goal) :-
70 memo:reify(Goal,Status),
71 (Status=ok -> true; debug(cron,'Periodic goal ~q failed with ~q',[Goal,Status])),
72 alarm(Interval,periodically(Interval,Goal),_,[remove(true)]).
73