amalgame/commit

make expand_node the only interface to expand_graph

authorJacco van Ossenbruggen
Mon Jan 23 11:29:46 2012 +0100
committerJacco van Ossenbruggen
Mon Jan 23 11:29:46 2012 +0100
commitb3f61da7b4235521b144d8d79402f8ee2d9122d6
tree75981f3a6da83bbbd749fe867167e156ce92e47a
parent56028f1f527ae357c9f3e95cba17499fd63990b5
Diff style: patch stat
diff --git a/applications/align_stats.pl b/applications/align_stats.pl
index 48d03b8..469d66e 100644
--- a/applications/align_stats.pl
+++ b/applications/align_stats.pl
@@ -147,7 +147,7 @@ http_materialize_graph(Request) :-
 	rdf_has(Graph, opmv:wasGeneratedBy, Process, RealProp),
 	rdf(Graph, RealProp, Process, Strategy),
 	\+ rdfs_individual_of(Strategy, amalgame:'AlignmentTrace'),
-	expand_mapping(Strategy, Graph, Mappings),
+	expand_node(Strategy, Graph, Mappings),
 	materialize_mapping_graph(Mappings, [graph(Target)]),
 	align_clear_stats(graph(Target)),
 	align_ensure_stats(all(Target)),
diff --git a/applications/equalizer/mapping.pl b/applications/equalizer/mapping.pl
index 1c49b7f..ed7c08e 100644
--- a/applications/equalizer/mapping.pl
+++ b/applications/equalizer/mapping.pl
@@ -69,11 +69,11 @@ http_data_mapping(Request) :-
 		       ]),
 
 	(   rdfs_individual_of(URL, amalgame:'EvaluatedMapping')
-	->  expand_mapping(Strategy, URL, PreviousEvaluation) 
+	->  expand_node(Strategy, URL, PreviousEvaluation)
 	;   evaluation_graph(Strategy, URL, Prev),
-	    expand_mapping(Strategy, Prev, PreviousEvaluation)
+	    expand_node(Strategy, Prev, PreviousEvaluation)
 	),
-	expand_mapping(Strategy, URL, Mapping0),
+	expand_node(Strategy, URL, Mapping0),
 	length(Mapping0, Count),
 	maplist(mapping_label, Mapping0, Mapping1),
 	select_relation(Mapping1, PreviousEvaluation, Mapping2),
@@ -201,7 +201,7 @@ http_correspondence(Request) :-
 				  description('Include all target')])
 			]),
 	findall(R-L, mapping_relation(L, R), Relations),
-	expand_mapping(Strategy, Mapping, Ms),
+	expand_node(Strategy, Mapping, Ms),
 	(   AllSource
 	->  A = align(Source,_,_)
 	;   AllTarget
diff --git a/applications/equalizer/process.pl b/applications/equalizer/process.pl
index 567ed1f..518b3fc 100644
--- a/applications/equalizer/process.pl
+++ b/applications/equalizer/process.pl
@@ -111,7 +111,7 @@ new_process(Type, Alignment, Source, Target, Input, SecInputs, Params, Focus) :-
 	retractall(ag_alignment:nickname_cache(Alignment,_,_)),
 
 	rdf_bnode(URI),
-	rdf_transaction( % this transaction is to make it MT safe
+	rdf_transaction( % this rdf_transaction is to make it MT safe
 	    (	assert_process(URI, Type, Alignment, Params),
 		assert_user_provenance(URI, Alignment),
 		assert_input(URI, Type, Alignment, Source, Target, Input),
@@ -129,7 +129,7 @@ precompute(Process, Alignment) :-
 	rdf(Output, RP, Process, Alignment),
 	thread_create( % Write debug output to server console, cannot write to client:
 	    (	set_stream(user_output, alias(current_output)),
-		expand_mapping(Alignment, Output, _)
+		expand_node(Alignment, Output, _)
 	    ),
 	    _,[ detached(true) ]).
 
@@ -297,7 +297,7 @@ update_node_prop(status=Status, URI, Alignment) :-
 	(   rdf_equal(Status, amalgame:final)
 	->  thread_create(
 		(   set_stream(user_output, alias(current_output)),
-		    expand_mapping(Alignment, URI, _)
+		    expand_node(Alignment, URI, _)
 		), _, [ detached(true) ])
 	;   true
 	).
diff --git a/lib/ag_drivers/exec_amalgame_process.pl b/lib/ag_drivers/exec_amalgame_process.pl
index 2c90b7b..a265548 100644
--- a/lib/ag_drivers/exec_amalgame_process.pl
+++ b/lib/ag_drivers/exec_amalgame_process.pl
@@ -24,7 +24,7 @@ exec_amalgame_process(Type, Process, Strategy, Module, Mapping, Time, Options) :
 	rdfs_subclass_of(Type, amalgame:'Matcher'),
 	!,
 	findall(S, rdf(Process, amalgame:secondary_input, S), SecInputs),
-	maplist(expand_mapping(Strategy), SecInputs, SecInputNF),
+	maplist(expand_node(Strategy), SecInputs, SecInputNF),
 	flatten(SecInputNF, SecInput),
 	(   rdf(Process, amalgame:source, SourceId, Strategy),
 	    rdf(Process, amalgame:target, TargetId, Strategy)
@@ -32,7 +32,7 @@ exec_amalgame_process(Type, Process, Strategy, Module, Mapping, Time, Options) :
 	    expand_node(Strategy, TargetId, Target),
 	    timed_call(Module:matcher(Source, Target, Mapping0, [snd_input(SecInput)|Options]), Time)
 	;   rdf(Process, amalgame:input, InputId)
-	->  expand_mapping(Strategy, InputId, MappingIn),
+	->  expand_node(Strategy, InputId, MappingIn),
 	    timed_call(Module:filter(MappingIn, Mapping0, [snd_input(SecInput)|Options]), Time)
 	),
 	merge_provenance(Mapping0, Mapping).
@@ -45,7 +45,7 @@ exec_amalgame_process(Class, Process, Strategy, Module, Result, Time, Options) :
 	once(rdf(Process, amalgame:input, Input, Strategy)),
 	expand_node(Strategy, Input, Vocab),
 	findall(S, rdf_has(Process, amalgame:secondary_input, S), Ss),
-	maplist(expand_mapping(Strategy), Ss, Expanded),
+	maplist(expand_node(Strategy), Ss, Expanded),
 	append(Expanded, Mapping),
 	timed_call(Module:exclude(Vocab, Mapping, Result, [NewVocOption|Options]), Time).
 exec_amalgame_process(Class, Process, Strategy, Module, Result, Time, Options) :-
@@ -53,7 +53,7 @@ exec_amalgame_process(Class, Process, Strategy, Module, Result, Time, Options) :
 	!,
 	Result = select(Selected, Discarded, Undecided),
 	once(rdf(Process, amalgame:input, InputId, Strategy)),
-	expand_mapping(Strategy, InputId, MappingIn),
+	expand_node(Strategy, InputId, MappingIn),
 	timed_call(Module:selecter(MappingIn, Selected, Discarded, Undecided, Options), Time).
 exec_amalgame_process(Class, Process, Strategy, Module, Result, Time, Options) :-
 	rdfs_subclass_of(Class, amalgame:'VocabSelecter'),
@@ -65,7 +65,7 @@ exec_amalgame_process(Class, Process, Strategy, Module, Result, Time, Options) :
 	rdfs_subclass_of(Class, amalgame:'MapMerger'),
 	!,
 	findall(Input, rdf(Process, amalgame:input, Input, Strategy), Inputs),
-	maplist(expand_mapping(Strategy), Inputs, Expanded),
+	maplist(expand_node(Strategy), Inputs, Expanded),
 	timed_call(Module:merger(Expanded, Result, Options), Time).
 exec_amalgame_process(Class, Process, Strategy, Module, Result, Time, Options) :-
 	rdfs_subclass_of(Class, amalgame:'OverlapComponent'),
diff --git a/lib/ag_modules/ag_overlap.pl b/lib/ag_modules/ag_overlap.pl
index e036eef..e1526f4 100644
--- a/lib/ag_modules/ag_overlap.pl
+++ b/lib/ag_modules/ag_overlap.pl
@@ -22,7 +22,7 @@ analyzer(Inputs, Process, Strategy, overlap(Results), _Options) :-
 	maplist(output_expander(Results, Strategy), Overlaps).
 
 input_expander(Strategy, Id, Id:Expanded) :-
-	expand_mapping(Strategy, Id, Expanded).
+	expand_node(Strategy, Id, Expanded).
 
 output_expander(Results, Strategy, OverlapId-Mapping) :-
 	append(Mapping, MappingFlat),
diff --git a/lib/amalgame/ag_publish.pl b/lib/amalgame/ag_publish.pl
index 707744e..53cdbed 100644
--- a/lib/amalgame/ag_publish.pl
+++ b/lib/amalgame/ag_publish.pl
@@ -68,7 +68,7 @@ find_relation(Mapping, Cell, Default, Relation) :-
 
 save_mapping(Id, Strategy, ProvGraph, Options) :-
 	(   \+ rdf_graph(Id)
-	->  expand_mapping(Strategy, Id, Mapping),
+	->  expand_node(Strategy, Id, Mapping),
 	    materialize_mapping_graph(Mapping, [graph(Id)|Options])
 	;   add_relation_if_needed(Id, Options)
 	),
diff --git a/lib/amalgame/expand_graph.pl b/lib/amalgame/expand_graph.pl
index d7a924a..eec66e6 100644
--- a/lib/amalgame/expand_graph.pl
+++ b/lib/amalgame/expand_graph.pl
@@ -1,7 +1,6 @@
 :- module(expand_graph,
 	  [
-	    expand_node/3,
-	    expand_mapping/3
+	    expand_node/3
 	  ]).
 
 :- use_module(library(semweb/rdf_db)).
@@ -18,14 +17,23 @@
 :- use_module(library(skos/vocabularies)).
 :- use_module(library(ag_drivers/exec_amalgame_process)).
 
+%%	expand_node(+StrategyURL, +NodeURL, -Result) is det.
+%
+%	Compute result of expanding NodeURL as defined by StrategyURL.
+%	Result is a term defined by the type of output of the
+%	components.
+%
 expand_node(Strategy, Id, Result) :-
 	ground(Strategy),
 	ground(Id),
+	with_mutex(Id, expand_node_(Strategy, Id, Result)).
+
+expand_node_(Strategy, Id, Result) :-
 	(   rdfs_individual_of(Id, amalgame:'Mapping')
-	->  with_mutex(Id, expand_mapping(Strategy, Id, Result))
+	->  expand_mapping(Strategy, Id, Result)
 	;   rdfs_individual_of(Id, skos:'ConceptScheme')
-	->  with_mutex(Id, expand_vocab(Strategy, Id, Result))
-	;   true
+	->  expand_vocab(Strategy, Id, Result)
+	;   Result=error(Id)
 	).
 
 %%	expand_mapping(+Strategy, +Id, -Result) is det.
@@ -40,6 +48,7 @@ expand_node(Strategy, Id, Result) :-
 %          scheme(Scheme) or type(Class)
 
 expand_mapping(Strategy, Id, Mapping) :-
+	debug(ag_expand, 'Expanding mapping ~p', [Id]),
 	(   rdf_graph(Id)
 	;   rdfs_individual_of(Id, amalgame:'EvaluatedMapping')
 	;   rdfs_individual_of(Id, amalgame:'LoadedMapping')
diff --git a/lib/amalgame/irr.pl b/lib/amalgame/irr.pl
index 3982ddf..3bd8fb7 100644
--- a/lib/amalgame/irr.pl
+++ b/lib/amalgame/irr.pl
@@ -39,12 +39,12 @@ alpha(Strategy, Inputs, Out, Options) :-
 	length(Inputs, Ninputs), Ninputs > 1,
 	init_encoding_table(Options),
 	Inputs = [Head|Tail],
-	expand_mapping(Strategy, Head, Reference),
+	expand_node(Strategy, Head, Reference),
 	columnize(Reference, Reference, RefPrologColumn, RefRColumn, true),
 	debug(irr, 'ag_irr:alpha ref column: ~w', [RefRColumn]),
 	findall((Finding-Finding_as_an_R_column)-Same,
 		(member(Id, Tail),
-		 expand_mapping(Strategy, Id, Mapping),
+		 expand_node(Strategy, Id, Mapping),
 		 columnize(Mapping, Reference, Finding, Finding_as_an_R_column, Same),
 		 debug(irr, 'ag_irr:alpha column to check: ~p\n~w', [Id, Finding_as_an_R_column])
 		),