Daniel@0: /* Part of DML (Digital Music Laboratory) Daniel@0: Copyright 2014-2015 Samer Abdallah, University of London Daniel@0: Daniel@0: This program is free software; you can redistribute it and/or Daniel@0: modify it under the terms of the GNU General Public License Daniel@0: as published by the Free Software Foundation; either version 2 Daniel@0: of the License, or (at your option) any later version. Daniel@0: Daniel@0: This program is distributed in the hope that it will be useful, Daniel@0: but WITHOUT ANY WARRANTY; without even the implied warranty of Daniel@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Daniel@0: GNU General Public License for more details. Daniel@0: Daniel@0: You should have received a copy of the GNU General Public Daniel@0: License along with this library; if not, write to the Free Software Daniel@0: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Daniel@0: */ Daniel@0: Daniel@0: :- module(dml_misc, [ periodically/2, current_periodical/3, remove_periodical/1 ]). Daniel@0: /** Miscellaneous hooks and initialisations Daniel@0: Daniel@0: This module implements some hooks for managing the context graphs Daniel@0: which appear at the bottom of individual resource pages. Daniel@0: Daniel@0: It also loads some miscellanous RDF graphs. Daniel@0: Daniel@0: */ Daniel@0: :- use_module(library(semweb/rdf_db)). Daniel@0: :- use_module(library(semweb/rdfs)). Daniel@0: :- use_module(library(memo)). Daniel@0: :- use_module(cliopatria(hooks)). Daniel@0: Daniel@0: :- rdf_meta context_graph_class(r). Daniel@0: Daniel@0: :- meta_predicate periodically(+,0). Daniel@0: :- meta_predicate current_periodical(-,0,-). Daniel@0: Daniel@0: cliopatria:context_graph(URI, Triples, _) :- Daniel@0: context_graphable(URI), !, Daniel@0: maplist(rdf_global_id,[rdf:type, prov:wasDerivedFrom],Excludes), Daniel@0: findall(T, context_triple(Excludes,URI,[],T), T1), Daniel@0: sort(T1,Triples). Daniel@0: Daniel@0: context_triple(Excludes,URI,Visited,T) :- Daniel@0: edge(URI,Pred,URI1,Triple), Daniel@0: \+member(Pred,Excludes), Daniel@0: ( T=Triple Daniel@0: ; \+member(URI1,Visited), Daniel@0: %context_graphable(URI1), % this follows a lot of link Daniel@0: rdfs_individual_of(URI1,event:'Event'), Daniel@0: context_triple(Excludes,URI1,[URI|Visited],T) Daniel@0: ). Daniel@0: Daniel@0: edge(URI,Pred,URI1,rdf(URI,Pred,URI1)) :- rdf(URI,Pred,URI1), URI1\=literal(_). Daniel@0: edge(URI,Pred,URI1,rdf(URI1,Pred,URI)) :- rdf(URI1,Pred,URI). Daniel@0: Daniel@0: context_graphable(URI) :- Daniel@0: context_graph_class(Class), Daniel@0: rdfs_individual_of(URI,Class). Daniel@0: Daniel@0: context_graph_class(event:'Event'). Daniel@0: context_graph_class(mo:'Signal'). Daniel@0: context_graph_class(mo:'MusicalWork'). Daniel@0: context_graph_class(mo:'MusicGroup'). Daniel@0: Daniel@0: current_periodical(Interval,Goal,Id) :- current_alarm(_,periodically(Interval,Goal),Id,_). Daniel@0: remove_periodical(Id) :- remove_alarm(Id). Daniel@0: Daniel@0: periodically(Interval,Goal) :- Daniel@0: memo:reify(Goal,Status), Daniel@0: (Status=ok -> true; debug(cron,'Periodic goal ~q failed with ~q',[Goal,Status])), Daniel@0: alarm(Interval,periodically(Interval,Goal),_,[remove(true)]). Daniel@0: