amalgame/commit
REFACTORING: move out skos browser hooks from builder to hook module
author | Jacco van Ossenbruggen |
---|---|
Mon Sep 1 18:13:09 2014 +0200 | |
committer | Jacco van Ossenbruggen |
Mon Sep 1 18:13:09 2014 +0200 | |
commit | fa20bb61eb1fcee32732b2c301449b1aaeb78db9 |
tree | 5931915d14de49c8ad683c027be9c962958c9ff2 |
parent | 1cc22dddb5f9414831486fb43b0804f66e783e76 |
Diff style: patch stat
diff --git a/applications/builder.pl b/applications/builder.pl index 5678aa8..49b3877 100644 --- a/applications/builder.pl +++ b/applications/builder.pl @@ -1,10 +1,8 @@ :- module(ag_builder, []). -:- use_module(library(option)). :- use_module(library(settings)). :- use_module(library(semweb/rdf_db)). -:- use_module(library(semweb/rdfs)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_parameters)). :- use_module(library(http/http_path)). @@ -13,8 +11,6 @@ :- use_module(library(yui3_beta)). :- use_module(user(user_db)). -:- use_module(library(skos/util)). - :- use_module(library(amalgame/voc_stats)). :- use_module(library(amalgame/util)). :- use_module(library(amalgame/json_util)). @@ -71,6 +67,7 @@ ag:menu_item(900=Handler, Label) :- :- multifile amalgame:prebuilder/1. + prebuilder_hook(Strategy) :- amalgame:prebuilder(Strategy), fail. prebuilder_hook(_Strategy). @@ -272,58 +269,3 @@ js_module(columnbrowser, json([fullpath(Path), requires([node,event,widget,resourcelist]) ])) :- http_absolute_location(js('columnbrowser.js'), Path, []). - - - - - - - /******************************* - * skos browser hooks * - *******************************/ - -cliopatria:concept_property(class, Concept, Graphs0, Class, Options) :- - graph_mappings(Graphs0, Graphs), - ( is_mapped(Concept, Graphs, Options) - -> Class = mapped - ; Class = unmapped - ). -cliopatria:concept_property(count, Concept, Graphs0, Count, Options) :- - graph_mappings(Graphs0, Graphs), - mapped_descendant_count(Concept, Graphs, Count, Options). - - -graph_mappings([Strategy], Graphs) :- - rdf(Strategy, rdf:type, amalgame:'AlignmentStrategy'), - !, - findall(Mapping, rdf(Mapping, rdf:type, amalgame:'Mapping', Strategy), Graphs). -graph_mappings(Graphs, Graphs). - - -mapped_descendant_count(Concept, Graphs, Count, Options) :- - findall(C, skos_descendant_of(Concept, C), Descendants0), - sort(Descendants0, Descendants), - ( Descendants = [] - -> Count = @null - ; mapped_chk(Descendants, Graphs, Mapped, Options), - length(Descendants, Descendant_Count), - length(Mapped, Mapped_Count), - atomic_list_concat([Mapped_Count, '/', Descendant_Count], Count) - ). - -mapped_chk([], _, [], _ ). -mapped_chk([C|T], Graphs, [C|Rest], Options) :- - is_mapped(C, Graphs, Options), - !, - mapped_chk(T, Graphs, Rest, Options). -mapped_chk([_|T], Graphs, Rest, Options) :- - mapped_chk(T, Graphs, Rest, Options). - -is_mapped(Concept, Mappings, Options) :- - option(strategy(Strategy), Options), - member(Mapping, Mappings), - ( is_mapped(Strategy, source, Concept, Mapping) - -> true - ; is_mapped(Strategy, target, Concept, Mapping) - ). - diff --git a/lib/amalgame/hooks/load.pl b/lib/amalgame/hooks/load.pl index b0fbe50..811c692 100644 --- a/lib/amalgame/hooks/load.pl +++ b/lib/amalgame/hooks/load.pl @@ -2,3 +2,4 @@ :- use_module(strategy_backward_compatability). +:- use_module(skos_browser). diff --git a/lib/amalgame/hooks/skos_browser.pl b/lib/amalgame/hooks/skos_browser.pl new file mode 100644 index 0000000..2c67502 --- /dev/null +++ b/lib/amalgame/hooks/skos_browser.pl @@ -0,0 +1,52 @@ +:- module(skos_broser_hooks, []). + +:- use_module(library(option)). +:- use_module(library(semweb/rdf_db)). +:- use_module(library(skos/util)). +:- use_module(library(amalgame/expand_graph)). + +cliopatria:concept_property(class, Concept, Graphs0, Class, Options) :- + graph_mappings(Graphs0, Graphs), + ( is_mapped(Concept, Graphs, Options) + -> Class = mapped + ; Class = unmapped + ). +cliopatria:concept_property(count, Concept, Graphs0, Count, Options) :- + graph_mappings(Graphs0, Graphs), + mapped_descendant_count(Concept, Graphs, Count, Options). + + +graph_mappings([Strategy], Graphs) :- + rdf(Strategy, rdf:type, amalgame:'AlignmentStrategy'), + !, + findall(Mapping, rdf(Mapping, rdf:type, amalgame:'Mapping', Strategy), Graphs). +graph_mappings(Graphs, Graphs). + + +mapped_descendant_count(Concept, Graphs, Count, Options) :- + findall(C, skos_descendant_of(Concept, C), Descendants0), + sort(Descendants0, Descendants), + ( Descendants = [] + -> Count = @null + ; mapped_chk(Descendants, Graphs, Mapped, Options), + length(Descendants, Descendant_Count), + length(Mapped, Mapped_Count), + atomic_list_concat([Mapped_Count, '/', Descendant_Count], Count) + ). + +mapped_chk([], _, [], _ ). +mapped_chk([C|T], Graphs, [C|Rest], Options) :- + is_mapped(C, Graphs, Options), + !, + mapped_chk(T, Graphs, Rest, Options). +mapped_chk([_|T], Graphs, Rest, Options) :- + mapped_chk(T, Graphs, Rest, Options). + +is_mapped(Concept, Mappings, Options) :- + option(strategy(Strategy), Options), + member(Mapping, Mappings), + ( is_mapped(Strategy, source, Concept, Mapping) + -> true + ; is_mapped(Strategy, target, Concept, Mapping) + ). +