amalgame/commit

EXPERIMENTAL: serve schemes as assocs

authorJacco van Ossenbruggen
Wed Sep 17 15:48:05 2014 +0200
committerJacco van Ossenbruggen
Wed Sep 17 15:48:05 2014 +0200
commit00a55b31bbc0eccde8bd66ffce4f838a9721e242
treedd4acf702d7fcc8c6a537878e1577a57d234d0e1
parent5bf3a5af759c5cda7597d6a849c74c2133727779
Diff style: patch stat
diff --git a/lib/ag_drivers/exec_amalgame_process.pl b/lib/ag_drivers/exec_amalgame_process.pl
index d9c7320..a74543f 100644
--- a/lib/ag_drivers/exec_amalgame_process.pl
+++ b/lib/ag_drivers/exec_amalgame_process.pl
@@ -6,6 +6,7 @@
 	  ]).
 
 :- use_module(library(apply)).
+:- use_module(library(assoc)).
 :- use_module(library(lists)).
 
 :- use_module(library(semweb/rdf_db)).
@@ -17,7 +18,8 @@
 :- multifile
 	exec_amalgame_process/7,
 	select_result_mapping/4,
-	select_result_scheme/4.
+	select_result_scheme/4,
+	specification/7.
 
 :- meta_predicate
 	timed_call(5, -).
@@ -120,10 +122,13 @@ exec_amalgame_process(Class, Process, Strategy, Module, VocSpec, Time, Options)
 	!,
 	once(rdf(Process, amalgame:input, Input, Strategy)),
 	findall(S, rdf_has(Process, amalgame:secondary_input, S), Ss),
-	VocSpec = vocspec(select(Selected, Discarded, Undecided)),
+	VocSpec = vocspec(select(SelectedA, DiscardedA, UndecidedA)),
 	vocab_spec(Strategy, Input, InputVocspec),
 	timed_call(Module:selecter(InputVocspec, Selected, Discarded, Undecided,
-				   [snd_input(Ss), strategy(Strategy)|Options]), Time).
+				   [snd_input(Ss), strategy(Strategy)|Options]), Time),
+	plain_ord_list_to_assoc(Selected, SelectedA),
+	plain_ord_list_to_assoc(Discarded, DiscardedA),
+	plain_ord_list_to_assoc(Undecided, UndecidedA).
 exec_amalgame_process(Class, Process, Strategy, Module, MapSpec, Time, Options) :-
 	rdfs_subclass_of(Class, amalgame:'MapMerger'),
 	!,
@@ -156,3 +161,9 @@ timed_call(Goal, Time) :-
 	call(Goal),
 	thread_statistics(Me, cputime, T1),
         Time is T1 - T0.
+
+dummy_value(K, K-null).
+
+plain_ord_list_to_assoc(List, Assoc) :-
+	maplist(dummy_value, List, Pairs),
+	ord_list_to_assoc(Pairs, Assoc).
diff --git a/lib/amalgame/expand_graph.pl b/lib/amalgame/expand_graph.pl
index 3a9b24d..efe79e7 100644
--- a/lib/amalgame/expand_graph.pl
+++ b/lib/amalgame/expand_graph.pl
@@ -3,7 +3,7 @@
 	    vocab_spec/3,
 	    precompute_process/2,
 	    precompute_node/2,
-	    all_mapped/4
+	    all_mapped/5
 	  ]).
 
 :- use_module(library(apply)).
@@ -69,24 +69,26 @@ precompute_node(Strategy, Mapping) :-
 %
 %	True if Concepts are all sources/targets in the correspondences
 %	of Mapping. Type is either source or target.
-all_mapped(Strategy, Type, Mapping, Concepts) :-
+all_mapped(Strategy, Type, Mapping, Concepts, Sorted) :-
 	atom(Mapping),
 	(   cache_mapped_concepts(Strategy, Type, Mapping, Concepts)
-	->  true
+	->  assoc_to_keys(Concepts, Sorted)
 	;   expand_node(Strategy, Mapping, Result),
-	    maplist(correspondence_element(Type), Result, Concepts),
-	    sort(Concepts, Sorted),
-	    cache_mapped_concepts(Strategy, Type, Mapping, Sorted)
+	    maplist(my_correspondence_element(Type), Result, Concepts0),
+	    sort(Concepts0, Sorted),
+	    ord_list_to_assoc(Sorted, Concepts),
+	    cache_mapped_concepts(Strategy, Type, Mapping, Concepts)
 	).
 
-all_mapped(Strategy, Type, Mappings, Concepts) :-
+all_mapped(Strategy, Type, Mappings, Concepts, Sorted) :-
 	is_list(Mappings),
 	(   cache_mapped_concepts(Strategy, Type, Mappings, Concepts)
-	->  true
+	->  assoc_to_keys(Concepts, Sorted)
 	;   maplist(expand_node(Strategy), Mappings, Results),
 	    append(Results, Result),
 	    maplist(my_correspondence_element(Type), Result, Concepts0),
-	    ord_list_to_assoc(Concepts0, Concepts),
+	    sort(Concepts0, Sorted),
+	    ord_list_to_assoc(Sorted, Concepts),
 	    cache_mapped_concepts(Strategy, Type, Mappings, Concepts)
 	).
 
diff --git a/lib/amalgame/vocabulary.pl b/lib/amalgame/vocabulary.pl
index 55e52c4..6b4dff7 100644
--- a/lib/amalgame/vocabulary.pl
+++ b/lib/amalgame/vocabulary.pl
@@ -85,7 +85,7 @@ vocab_member(E, is_mapped(Options)) :-
 	option(snd_input(Mappings), Options),
 	option(type(Type), Options),
 	option(strategy(Strategy), Options),
-	all_mapped(Strategy, Type, Mappings, Concepts),
+	all_mapped(Strategy, Type, Mappings, Concepts, _L),
 	!,
 	get_assoc(E, Concepts, _).
 
@@ -150,7 +150,7 @@ all_vocab_members(is_mapped(Options), Concepts) :-
 	option(snd_input(Mappings), Options),
 	option(type(Type), Options),
 	option(strategy(Strategy), Options),
-	maplist(all_mapped(Strategy, Type), Mappings, Mapped),
+	maplist(all_mapped(Strategy, Type), Mappings, _Assocs, Mapped),
 	append(Mapped, Concepts0),
 	sort(Concepts0, Concepts).