yaz/commit

first prototypes for tag gardening games

authorMichiel Hildebrand
Wed Feb 2 18:26:16 2011 +0100
committerMichiel Hildebrand
Wed Feb 2 18:26:16 2011 +0100
commitee80ba462ac4b7235ee0dc3215b5b096a717867d
tree6ac980eae5b8150f141d82e06ef03ae79581b2a9
parenta1d7c3bc176fa225c75e84ae1142776edf82361f
Diff style: patch stat
diff --git a/applications/yaz_mgarden.pl b/applications/yaz_mgarden.pl
index 5670cc9..60f4477 100644
--- a/applications/yaz_mgarden.pl
+++ b/applications/yaz_mgarden.pl
@@ -75,14 +75,12 @@ tag_matches([A0|As], User, Process, Interval, [A|Rest]) :-
 	tag_matches(As, User, Process, Interval, Rest).
 
 existing_match(Entries, Match) :-
-	findall(S, (member(E, Entries),
-		    rdf(i(E,_), pprime:score, S)
+	findall(S, (member(i(E,_), Entries),
+		    rdf(E, pprime:score, literal(S))
 		   ),
 		Ss),
-	(   max_list(Ss, Score)
-	->  Match = match(exact, score(Score))
-	;   Match = @false
-	).
+	max_list(Ss, Score),
+	Match = match(exact, Score).
 
 tag_match(literal(Tag), Time, User, Game, Interval, Match) :-
 	Match = match(Type, 0, E, literal(Tag1)),
@@ -196,7 +194,8 @@ js_support_functions(User) -->
 			  ]),
 	js_function_decl(handleResponse, [id, o],
 			 \[
-'    var data = Y.JSON.parse(o.responseText);\n'
+'    var r = Y.JSON.parse(o.responseText);
+     tagCarousel.updateMatch(r);\n'
 			  ]).
 
 js_tag_select -->
@@ -223,8 +222,8 @@ js_confirm(User) -->
 					     target:symbol(target),
 					     match:symbol(match)},
 				       on:{success:symbol('function(id, o)
-				             {var data = Y.JSON.parse(o.responseText);
-					      tagCarousel.scoreIndex(i,data.score,"confirm")
+				             {var r = Y.JSON.parse(o.responseText);
+					      tagCarousel.scoreIndex(i,r.score,"confirm",r.confirm)
 					     }')},
 				       context:symbol(tagCarousel)
 				      }))
@@ -250,25 +249,22 @@ http_yaz_api_confirm_match(Request) :-
  	debug(yaz(update), 'confirm ~w match between ~w and ~w',
 	      [Match, Source, Target]),
 
-	(   confirmed(Match, Source, Target, User)
+	(   confirmed(Match, Source, Target, User, Confirm)
 	->  match_score(Match, Score)
-	;   Score = 0
+	;   Score = 0,
+	    rdf_bnode(Confirm),
+	    rdfh_transaction((rdfh_assert(Confirm, pprime:match, literal(Match)),
+			      rdfh_assert(Confirm, pprime:creator, User),
+			      rdfh_assert(Confirm, pprime:matchSource, Source),
+			      rdfh_assert(Confirm, pprime:matchTarget, Target)))
 	),
 
-	rdf_bnode(Confirm),
-	rdfh_transaction((rdfh_assert(Confirm, pprime:match, literal(Match)),
-			  rdfh_assert(Confirm, pprime:creator, User),
-			  rdfh_assert(Confirm, pprime:matchSource, Source),
-			  rdfh_assert(Confirm, pprime:matchTarget, Target))),
-
-  	reply_json(json([source=Source,
-			 target=Target,
-			 match=Match,
+  	reply_json(json([confirm=Confirm,
 			 score=Score
  			])).
 
 
-confirmed(specific, Source, Target, User) :-
+confirmed(specific, Source, Target, User, Confirm) :-
 	rdf(Confirm, pprime:match, literal(Match)),
 	\+ rdf(Confirm, pprime:creator, User),
 	(   Match = specific
@@ -276,7 +272,7 @@ confirmed(specific, Source, Target, User) :-
 	;   Match = generic
 	->  confirmed_(Confirm, Target, Source)
 	).
-confirmed(generic, Source, Target, User) :-
+confirmed(generic, Source, Target, User, Confirm) :-
 	rdf(Confirm, pprime:match, literal(Match)),
 	\+ rdf(Confirm, pprime:creator, User),
 	(   Match = generic
@@ -284,7 +280,7 @@ confirmed(generic, Source, Target, User) :-
 	;   Match = specific
 	->  confirmed_(Confirm, Target, Source)
 	).
-confirmed(Match, Source, Target, User) :-
+confirmed(Match, Source, Target, User, Confirm) :-
 	rdf(Confirm, pprime:match, literal(Match)),
 	\+ rdf(Confirm, pprime:creator, User),
 	(   confirmed_(Confirm, Source, Target)
@@ -295,10 +291,10 @@ confirmed_(Confirm, Source, Target) :-
 	rdf(Confirm, pprime:matchSource, Source),
 	rdf(Confirm, pprime:matchTarget, Target).
 
-match_score(stem, 10).
-match_score(synonym, 15).
-match_score(specific, 20).
-match_score(generic, 20).
+match_score(stem, 75).
+match_score(synonym, 100).
+match_score(specific, 150).
+match_score(generic, 125).
 
 
 %%	http_yaz_api_mgarden_data(+Request)
@@ -311,8 +307,8 @@ http_yaz_api_mgarden_data(Request) :-
 			       [description('URL of the user')])
 			]),
 	current_user_process(Process),
-	Obj = json([match=Match, score=Score]),
-	findall(Obj, user_confirmed(User, Process, Match, Score), Confirmed),
+	Obj = json([confirm=Confirm, score=Score]),
+	findall(Obj, user_confirmed(User, Process, Confirm, Score), Confirmed),
   	reply_json(Confirmed).
 
 user_confirmed(User, Process, Confirm, Score) :-
@@ -320,7 +316,7 @@ user_confirmed(User, Process, Confirm, Score) :-
 	rdf(Confirm, pprime:match, literal(Match)),
 	rdf(Confirm, pprime:matchSource, Source),
 	rdf(Confirm, pprime:matchTarget, Target),
-	(   confirmed(Match, Source, Target, User)
+	(   confirmed(Match, Source, Target, User, _)
 	->  match_score(Match, Score)
 	;   Score = 0
 	).
diff --git a/applications/yaz_sgarden.pl b/applications/yaz_sgarden.pl
index 6c1d77b..eb92c7b 100644
--- a/applications/yaz_sgarden.pl
+++ b/applications/yaz_sgarden.pl
@@ -61,11 +61,11 @@ tag_matches([A0|As], [A|Rest]) :-
 	A0 = annotation(Value,Start,End,Entries),
 	A =  annotation(Value,Start,End,Entries,Match),
 	findall(S, (member(i(E,_),Entries),
-		    rdf(E, pprime:score, S)
+		    rdf(E, pprime:score, literal(S))
 		   ),
 		Ss),
 	(   max_list(Ss, Score)
-	->  Match = match(exact, score(Score))
+	->  Match = match(exact, Score)
 	;   Match = @false
 	),
  	tag_matches(As,	Rest).
diff --git a/web/js/tagcarousel/tagcarousel.js b/web/js/tagcarousel/tagcarousel.js
index 9d2cb8b..b9457a8 100644
--- a/web/js/tagcarousel/tagcarousel.js
+++ b/web/js/tagcarousel/tagcarousel.js
@@ -66,6 +66,7 @@ YUI.add('tag-carousel', function(Y) {
 
 		initializer: function() {
 			this._nDelayID = -1;
+			this.scores = {};
 		},
 
 		destructor : function() {
@@ -127,16 +128,12 @@ YUI.add('tag-carousel', function(Y) {
 			var tag = item.tag,
 				label = tag.label ? tag.label : tag.value,
 				match = item.match,
+				score = (match&&match.score) ? match.score : '',
 				html = "";
-				
+
 			if(this.get("confirm")&&(match&&!match.score)) {
-				var sep = match.type=='specific' ? '<' : (match.type=='generic' ? '>' : '=')
-				html += '<div class="label match">'
-					+label
-					+" "+sep+" "
-					+match.value.value;
-					+'</div>';
-				}
+				var sep = match.type=='specific' ? '&lt;' : (match.type=='generic' ? '&gt;' : '=');
+				html += '<div class="label match">'+label+" "+sep+" "+match.value.value+'</div>';
 				html += '<div class="confirm"><a href="javascript:{}">?</a></div>';
 			}
 			else {
@@ -152,10 +149,11 @@ YUI.add('tag-carousel', function(Y) {
 			if(this.get("remove")) {
 				html += '<div class="remove"><a href="javascript:{}">x</a></div>';
 			}
-			if(match&&match.score) {
-				html += '<div class="score">'+match.score+'</div>';
+			if(score) {
+				html += '<div class="score">'+score+'</div>';
+			} else {
+				html += '<div class="score hidden"></div>';
 			}
-			
 			if(item.uri) {
 				return '<a href="javascript:{}">'+html+'</a>';
 			} else {
@@ -269,16 +267,25 @@ YUI.add('tag-carousel', function(Y) {
 			}
 		},
 		
-		scoreIndex : function(index, score, type) {
-			var item = this.listNode.all("li").item(index);
+		scoreIndex : function(index, score, type, id) {
+			var item = this.listNode.all("li").item(index),
+				el;
+			if(id) {
+				this.scores[id] = item;
+			}	
 			if(type=='edit'&&score>0) {
-				item.addClass('scored');
-				item.one('.score').setContent(score);
-				item.one('.edit').addClass("hidden");
+				el = '.edit';
 			} else if(type=='confirm') {
+				el = '.confirm';
+			}
+			if(el) {
 				item.addClass('scored');
-				item.one('.score').setContent(score);
-				item.one('.confirm').addClass("hidden");
+				item.one(el).addClass("hidden");
+				if(score>0) {
+					item.one('.score')
+						.setContent(score)
+						.removeClass("hidden");
+				}
 			}
 		},
 		
@@ -326,6 +333,18 @@ YUI.add('tag-carousel', function(Y) {
 			}
 		},
 		
+		updateMatch : function(matches) {
+			for(var i=0; i < matches.length; i++) {
+				var match = matches[i];
+				if(match.score) {
+					var node = this.scores[match.confirm];
+					if(node) {
+						node.one('.score').setContent(match.score);
+					}
+				}
+			}
+		},
+		
 		_search : function(e) {
 			var delay = this.get("queryDelay"),
 				query = e.currentTarget.get("value").toLowerCase(),