amalgame/commit
REFACTORING: move out backward compatibility fixes in builder to hook module
author | Jacco van Ossenbruggen |
---|---|
Mon Sep 1 18:05:22 2014 +0200 | |
committer | Jacco van Ossenbruggen |
Mon Sep 1 18:05:22 2014 +0200 | |
commit | 1cc22dddb5f9414831486fb43b0804f66e783e76 |
tree | c799103ed1aada2c447e9091b2968045440056b2 |
parent | dbe6246c990eec8d19c44111528c4a7684282b12 |
Diff style: patch stat
diff --git a/applications/builder.pl b/applications/builder.pl index a664c7f..5678aa8 100644 --- a/applications/builder.pl +++ b/applications/builder.pl @@ -68,12 +68,14 @@ ag:menu_item(900=Handler, Label) :- css('columnbrowser.css') ]) ]). +:- multifile + amalgame:prebuilder/1. -backward_compatibilty_fixes(Strategy) :- - fix_opmv_ns(Strategy), - fix_sec_inputs(Strategy), - fix_arity_params(Strategy), - fix_publish_ns(Strategy), +prebuilder_hook(Strategy) :- + amalgame:prebuilder(Strategy), fail. +prebuilder_hook(_Strategy). + +amalgame:prebuilder(Strategy) :- precalc_voc_stats(Strategy). precalc_voc_stats(Strategy) :- @@ -108,7 +110,7 @@ http_ag_build(Request) :- default(Strategy) ]) ]), - backward_compatibilty_fixes(Strategy), + prebuilder_hook(Strategy), html_page(Strategy, Focus). /******************************* @@ -272,53 +274,8 @@ js_module(columnbrowser, json([fullpath(Path), http_absolute_location(js('columnbrowser.js'), Path, []). -fix_publish_ns(S) :- -% backward compatibility - ( rdf(S, amalgame:publish_ns, _,S) - -> true - ; setting(amalgame:default_publish_namespace, NS), - rdf_assert(S, amalgame:publish_ns, NS, S) - ). -fix_sec_inputs(Strategy) :- -% backward compatibility - findall(rdf(S,RP,O), - ( rdf_has(S,amalgame:secondary_input, O, RP), - rdf(S, RP, O, Strategy) - ), Triples), - forall(member(rdf(S,P,O), Triples), - ( rdf_retractall(S,P,O,Strategy), - rdf_assert(S,amalgame:secondary_input, O, Strategy) - ) - ). -fix_opmv_ns(Strategy) :- % backward compatibility - OldProp = 'http://purl.org/net/opmv/ns#wasGeneratedBy', - findall(rdf(S,OldProp,O), - rdf(S, OldProp, O, Strategy), - Triples), - forall(member(rdf(S,P,O), Triples), - ( rdf_retractall(S,P,O,Strategy), - rdf_assert(S,amalgame:wasGeneratedBy, O, Strategy) - ) - ). -fix_arity_params(Strategy) :- -% backward compatibility - rdf_equal(amalgame:parameters, ParamProp), - findall(rdf(S,ParamProp,O), - ( rdf(S,ParamProp, literal(O), Strategy), - rdfs_individual_of(S, amalgame:'AritySelect') - ), ToBeFixed), - forall(member(rdf(S,P,O), ToBeFixed), - ( rdf_retractall(S,P,literal(O),Strategy), - arity_param_convert(O,NewO), - rdf_assert(S,P,literal(NewO), Strategy) - ) - ). -arity_param_convert('type=11', 'type=both'):- !. -arity_param_convert('type=1N', 'type=target'):- !. -arity_param_convert('type=N1', 'type=source'):- !. -arity_param_convert(X,X):- !. /******************************* diff --git a/config-available/025-amalgame.pl b/config-available/025-amalgame.pl index c86aa28..255cf24 100644 --- a/config-available/025-amalgame.pl +++ b/config-available/025-amalgame.pl @@ -39,6 +39,7 @@ http:location(img, root(img), [ priority(-100) ]). :- use_module(applications(builder)). :- use_module(applications(evaluater)). :- use_module(applications(publisher)). +:- use_module(library(amalgame/hooks/load)). % add local web directories from which static files are served. diff --git a/lib/amalgame/hooks/load.pl b/lib/amalgame/hooks/load.pl new file mode 100644 index 0000000..b0fbe50 --- /dev/null +++ b/lib/amalgame/hooks/load.pl @@ -0,0 +1,4 @@ +:- module(amalgame_hooks_loader, []). + + +:- use_module(strategy_backward_compatability). diff --git a/lib/amalgame/hooks/strategy_backward_compatability.pl b/lib/amalgame/hooks/strategy_backward_compatability.pl new file mode 100644 index 0000000..79ab1c7 --- /dev/null +++ b/lib/amalgame/hooks/strategy_backward_compatability.pl @@ -0,0 +1,68 @@ +:- module(strategy_backward_compatability, []). + +:- use_module(library(lists)). +:- use_module(library(settings)). + +:- use_module(library(semweb/rdf_db)). +:- use_module(library(semweb/rdfs)). + +:- multifile + amalgame:prebuilder/1. + +amalgame:prebuilder(Strategy) :- + backward_compatibilty_fixes(Strategy). + +backward_compatibilty_fixes(Strategy) :- + fix_opmv_ns(Strategy), + fix_sec_inputs(Strategy), + fix_arity_params(Strategy), + fix_publish_ns(Strategy). + +fix_publish_ns(S) :- +% backward compatibility + ( rdf(S, amalgame:publish_ns, _,S) + -> true + ; setting(amalgame:default_publish_namespace, NS), + rdf_assert(S, amalgame:publish_ns, NS, S) + ). + +fix_sec_inputs(Strategy) :- +% backward compatibility + findall(rdf(S,RP,O), + ( rdf_has(S,amalgame:secondary_input, O, RP), + rdf(S, RP, O, Strategy) + ), Triples), + forall(member(rdf(S,P,O), Triples), + ( rdf_retractall(S,P,O,Strategy), + rdf_assert(S,amalgame:secondary_input, O, Strategy) + ) + ). +fix_opmv_ns(Strategy) :- % backward compatibility + OldProp = 'http://purl.org/net/opmv/ns#wasGeneratedBy', + findall(rdf(S,OldProp,O), + rdf(S, OldProp, O, Strategy), + Triples), + forall(member(rdf(S,P,O), Triples), + ( rdf_retractall(S,P,O,Strategy), + rdf_assert(S,amalgame:wasGeneratedBy, O, Strategy) + ) + ). + +fix_arity_params(Strategy) :- +% backward compatibility + rdf_equal(amalgame:parameters, ParamProp), + findall(rdf(S,ParamProp,O), + ( rdf(S,ParamProp, literal(O), Strategy), + rdfs_individual_of(S, amalgame:'AritySelect') + ), ToBeFixed), + forall(member(rdf(S,P,O), ToBeFixed), + ( rdf_retractall(S,P,literal(O),Strategy), + arity_param_convert(O,NewO), + rdf_assert(S,P,literal(NewO), Strategy) + ) + ). + +arity_param_convert('type=11', 'type=both'):- !. +arity_param_convert('type=1N', 'type=target'):- !. +arity_param_convert('type=N1', 'type=source'):- !. +arity_param_convert(X,X):- !.