amalgame/commit

make less modules depend on caching details

authorJacco van Ossenbruggen
Fri Aug 8 16:46:17 2014 +0200
committerJacco van Ossenbruggen
Fri Aug 8 16:46:17 2014 +0200
commit5cbe1ab21b939fefd88127fb929b70f4c60e6d9a
tree12024bd483c97ee13ca8ce6fb6c7d00913edb090
parent1b232b09d8060a02b79101333f5a224d33d821ef
Diff style: patch stat
diff --git a/api/hints.pl b/api/hints.pl
index 74791e9..9f15bbb 100644
--- a/api/hints.pl
+++ b/api/hints.pl
@@ -6,7 +6,7 @@
 :- use_module(library(semweb/rdf_db)).
 :- use_module(library(semweb/rdfs)).
 :- use_module(library(semweb/rdf_label)).
-:- use_module(library(amalgame/caching)).
+:- use_module(library(amalgame/ag_stats)).
 :- use_module(library(amalgame/voc_stats)).
 :- use_module(library(amalgame/map)).
 
@@ -325,4 +325,4 @@ is_result_of_process_type(Mapping, Type) :-
 % never expand/compute something.
 
 hints_mapping_counts(Id, Strategy, Stats) :-
-	stats_cache(Id-Strategy, Stats).
+	node_stats(Strategy, Id, Stats, [compute(false)]).
diff --git a/api/mapping.pl b/api/mapping.pl
index 883e007..71a5d65 100644
--- a/api/mapping.pl
+++ b/api/mapping.pl
@@ -64,7 +64,7 @@ http_data_mapping(Request) :-
 	list_offset(MSorted, Offset, MOffset),
 	list_limit(MOffset, Limit, MLimit, _),
 	mapping_json(MLimit, Mapping),
-	node_stats(Strategy, URL, Stats),
+	node_stats(Strategy, URL, Stats, []),
 	reply_json(jsondict{url:URL,
 			    limit:Limit,
 			    offset:Offset,
@@ -190,8 +190,8 @@ original_concepts_assessment(V, JSON, Options) :-
 	).
 
 new_concepts_assessment(V, O, JSON, Options, WithdrawOptions) :-
-	assert_relation(O, WithdrawOptions, JSONwith),
-	assert_relation(V, Options, JSONadd),
+	assert_relation(O, JSONwith, WithdrawOptions),
+	assert_relation(V, JSONadd, Options),
 	JSON = JSONwith.put(JSONadd).
 
 assert_relations(Mapping, JSON, Options) :-
diff --git a/api/node_info.pl b/api/node_info.pl
index 89e6a6f..4e1f1e4 100644
--- a/api/node_info.pl
+++ b/api/node_info.pl
@@ -59,8 +59,8 @@ http_deep_voc_stats(Request) :-
 				   [description('URL of the alignment strategy')])
 		       ]),
 	flush_dependent_caches(Voc, Strategy),
-	voc_property(Voc, depth(D), [compute(yes)]),
-	voc_property(Voc, branch(B), [compute(yes)]),
+	voc_property(Voc, depth(D), [compute(true)]),
+	voc_property(Voc, branch(B), [compute(true)]),
 	reply_json(json{url:Voc, depth:D, branch:B}).
 
 %%	html_prop_table(+Pairs)
@@ -126,7 +126,7 @@ html_form(Params, URI) -->
 amalgame_info(URL, Strategy, Stats) :-
 	rdfs_individual_of(URL, amalgame:'Mapping'),
 	!,
-	node_stats(Strategy, URL, MStats),
+	node_stats(Strategy, URL, MStats, []),
 	option(totalCount(MN), MStats),
 	(   option(inputPercentage(IP), MStats)
 	->  format(atom(TmA), '~d (~5f%)', [MN, IP]),
@@ -204,7 +204,7 @@ amalgame_info(Scheme, Strategy, Stats) :-
 	    label_stats(Scheme, Strategy, skos:altLabel,  AltLabelStats)
 	),
 
-	(   setting(amalgame:vocabulary_statistics, fast) ->  C = no; C = yes),
+	(   setting(amalgame:vocabulary_statistics, fast) ->  C = false; C = true),
 	(   voc_property(Scheme, depth(DepthStats0), [compute(C)])
 	->  option(median(DepthM), DepthStats0, 0),
 	    option(q1(Q1), DepthStats0, 0),
diff --git a/applications/startpage.pl b/applications/startpage.pl
index 01504a2..b16854a 100644
--- a/applications/startpage.pl
+++ b/applications/startpage.pl
@@ -268,7 +268,7 @@ html_vocab_head -->
 
 html_vocab_rows([]) --> !.
 html_vocab_rows([Scheme|Vs]) --> {
-    (   voc_property(Scheme, numberOfConcepts(ConceptCount), [compute(no)])
+    (   voc_property(Scheme, numberOfConcepts(ConceptCount), [compute(false)])
     ->  true
     ;   rdf_estimate_complexity(_, skos:inScheme, Scheme, ConceptCount)
     ),
diff --git a/applications/strategy_viz.pl b/applications/strategy_viz.pl
index db28462..02b307d 100644
--- a/applications/strategy_viz.pl
+++ b/applications/strategy_viz.pl
@@ -13,7 +13,6 @@
 :- use_module(library(semweb/rdf_label)).
 :- use_module(components(label)).
 :- use_module(components(graphviz)).
-:- use_module(library(amalgame/caching)).
 :- use_module(library(amalgame/voc_stats)).
 :- use_module(library(amalgame/ag_stats)).
 :- use_module(library(amalgame/ag_evaluation)).
@@ -55,7 +54,7 @@ http_strategy_viz(Request) :-
 			      ])
 			]),
 	% When a node has been selected, make sure we know the stats
-	(   ground(Selected) -> node_stats(Strategy, Selected, _); true),
+	(   ground(Selected) -> node_stats(Strategy, Selected, _, [compute(true)]); true),
 
 	(   Format \== html
 	->  reply_strategy_graph(Strategy, Format)
@@ -136,7 +135,7 @@ is_amalgame_property(P) :-
 
 empty_result(Strategy, M) :-
 	rdfs_individual_of(M, amalgame:'Mapping'),
-	stats_cache(M-Strategy, Stats),
+	node_stats(Strategy, M, Stats, [compute(false)]),
 	option(totalCount(0), Stats),!.
 
 empty_result(_Strategy,M) :-
@@ -220,22 +219,21 @@ amalgame_label(Strategy, Resource, Lang, MaxLen, Label) :-
 
 stats_label_list(_Strategy, Resource, [Count]) :-
 	is_vocabulary(Resource),
-	voc_property(Resource, numberOfConcepts(Count), [compute(no)]),
+	voc_property(Resource, numberOfConcepts(Count), [compute(false)]),
 	!.
+stats_label_list(Strategy, Resource, [ConceptStats]) :-
+	node_stats(Strategy, Resource, Stats, [compute(false)]),
+	option(sourcePercentageInput(SPerc), Stats),
+	option(targetPercentageInput(TPerc), Stats),
+	format(atom(ConceptStats), '~0f% ~0f%', [SPerc, TPerc]),
+	!.
+
 stats_label_list(Strategy, Resource, [IPercA]) :-
-	stats_cache(Resource-Strategy, Stats),
+	node_stats(Strategy, Resource, Stats, [compute(false)]),
 	option(inputPercentage(IPerc), Stats, 0),
 	IPerc > 1,
 	format(atom(IPercA), '~0f%', [IPerc]),
 	!.
 
-stats_label_list(Strategy, Resource, [ConceptStats]) :-
-	stats_cache(Resource-Strategy, Stats),
-	option(sourcePercentageInput(SPerc), Stats, 0),
-	option(targetPercentageInput(TPerc), Stats, 0),
-	format(atom(ConceptStats), '~0f% ~0f%', [SPerc, TPerc]),
-	!.
-
-
 stats_label_list(_, _, []).
 
diff --git a/lib/amalgame/ag_provenance.pl b/lib/amalgame/ag_provenance.pl
index df3bdad..575765f 100644
--- a/lib/amalgame/ag_provenance.pl
+++ b/lib/amalgame/ag_provenance.pl
@@ -399,7 +399,7 @@ assert_count(VocUri, _Strategy, ProvGraph) :-
 
 assert_count(MapUri, Strategy, ProvGraph) :-
 	rdfs_individual_of(MapUri, amalgame:'Mapping'),!,
-	node_stats(Strategy, MapUri, MStats),
+	node_stats(Strategy, MapUri, MStats, []),
 	option(totalCount(Count), MStats),
 	option(mappedSourceConcepts(SN), MStats),
 	option(mappedTargetConcepts(TN), MStats),
diff --git a/lib/amalgame/ag_stats.pl b/lib/amalgame/ag_stats.pl
index 7a3976f..98d82e3 100644
--- a/lib/amalgame/ag_stats.pl
+++ b/lib/amalgame/ag_stats.pl
@@ -1,5 +1,5 @@
 :- module(ag_stats,[
-	      node_stats/3,
+	      node_stats/4,
 	      reference_counts/3,
 	      mapping_stats/4
 	  ]).
@@ -14,29 +14,33 @@
 :- use_module(library(amalgame/map)).
 :- use_module(library(amalgame/util)).
 
-node_stats(Strategy, Node, Stats) :-
+node_stats(Strategy, Node, Stats, Options) :-
 	(   rdfs_individual_of(Node, amalgame:'Mapping')
-	->  mapping_counts(Node, Strategy, Stats)
+	->  mapping_counts(Node, Strategy, Stats, Options)
 	;   is_vocabulary(Node)
-	->  voc_property(Node, numberOfConcepts(Stats))
+	->  voc_property(Node, numberOfConcepts(Stats), Options)
 	;   Stats = []
 	).
 
-%%	mapping_counts(+MappingURI,+Strategy, Stats)
+%%	mapping_counts(+MappingURI,+Strategy, Stats, +Options)
 %	is det.
 %
 %	Counts for the mappings in MappingURI.
 
-mapping_counts(URL, Strategy, Stats) :-
-	with_mutex(URL,	mapping_counts_(URL, Strategy, Stats)).
+mapping_counts(URL, Strategy, Stats, Options) :-
+	with_mutex(URL,	mapping_counts_(URL, Strategy, Stats, Options)).
 
-mapping_counts_(URL, Strategy, Stats) :-
+mapping_counts_(URL, Strategy, Stats, Options) :-
 	(   stats_cache(URL-Strategy, _)
 	->  true
-	;   expand_node(Strategy, URL, _Mapping)
+	;   option(compute(true), Options, true),
+	    expand_node(Strategy, URL, _Mapping)
 	),
-	stats_cache(URL-Strategy, Stats),
-	is_dict(Stats, mapping_stats_dict).
+	(   stats_cache(URL-Strategy, Stats),
+	    is_dict(Stats, mapping_stats_dict)
+	->  true
+	;   Stats = dict{error:'No stats computed'}
+	).
 
 
 reference_counts(Id, Strategy, Stats) :-
diff --git a/lib/amalgame/util.pl b/lib/amalgame/util.pl
index 9ce65d6..d0ec928 100644
--- a/lib/amalgame/util.pl
+++ b/lib/amalgame/util.pl
@@ -34,8 +34,8 @@
 :- use_module(user(user_db)).
 :- use_module(user(preferences)).
 :- use_module(cliopatria(components/label)).
-:- use_module(library(amalgame/caching)).
 :- use_module(library(amalgame/map)).
+:- use_module(library(amalgame/ag_stats)).
 :- use_module(library(amalgame/ag_reference)).
 :- use_module(library(amalgame/ag_evaluation)).
 
@@ -146,7 +146,7 @@ js_mappings_metadata(Strategy, Results, Options) :-
 
 mapping_metadata(Strategy, M, M-Dict) :-
 	Dict = mapping{uri:M, label:L, stats:Stats, agStatus:Status},
-	(   stats_cache(M-Strategy, Stats),
+	(   node_stats(Strategy, M, Stats, [compute(false)]),
 	    Stats.totalCount > 0
 	->  true
 	;   Stats = _{}
diff --git a/lib/amalgame/voc_stats.pl b/lib/amalgame/voc_stats.pl
index 3a982ca..3fc5c8b 100644
--- a/lib/amalgame/voc_stats.pl
+++ b/lib/amalgame/voc_stats.pl
@@ -53,7 +53,7 @@ voc_property(Voc, P, Options) :-
 	rdf_global_term(P, PG),
 	(   voc_stats_cache(Voc, PG)
 	->  true
-	;   (   option(compute(no), Options)
+	;   (   option(compute(false), Options)
 	    ->  fail
 	    ;   voc_ensure_stats(Voc, PG)
 	    )
@@ -353,7 +353,7 @@ compute_branch_stats(Voc, branch(Stats)) :-
 
 concept_list_depth_stats([], _Voc, depth([])) :-!.
 concept_list_depth_stats(CList, Voc, depth(Stats)) :-
-	voc_property(Voc, depth(_), [compute(no)]), % only if basic depth stats for voc already computed
+	voc_property(Voc, depth(_), [compute(false)]), % only if basic depth stats for voc already computed
 	maplist(concept_depth, CList, Depths),
 	sort(Depths, DepthsSorted),
 	list_five_number_summary_dict(DepthsSorted, Stats).