Index: /other-projects/hathitrust/wcsa/extracted-features-solr/trunk/web-portal/index.js
===================================================================
--- /other-projects/hathitrust/wcsa/extracted-features-solr/trunk/web-portal/index.js	(revision 31644)
+++ /other-projects/hathitrust/wcsa/extracted-features-solr/trunk/web-portal/index.js	(revision 31645)
@@ -32,4 +32,6 @@
 
 function add_titles(json_data) {
+    var itemURLs = [];
+    
     $.each( json_data, function( htid_with_prefix, htid_val ) {
 	var htid = htid_with_prefix.replace(/^htid:/,"");
@@ -40,6 +42,47 @@
 	    console.log(htid + ", title = " + metadata.titles[0]);
 	});
+
+	$.each(htid_val.items, function( item_index, item_val ) {
+	    if (item_val.htid == htid) {
+		var itemURL = item_val.itemURL;
+		itemURL = itemURL.replace(/^https:/,"http:");
+
+		var ws_span = '<span style="display: none;"><br>[Workset: <span name="'+itemURL+'"></span>]</span>';
+		$("[name='"+htid+"']").each(function() {$(this).append(ws_span)});
+		console.log("itemURL = " + itemURL);
+		itemURLs.push(itemURL);
+	    }
+	});
     });
-}
+    
+    workset_enrich_results(itemURLs);
+
+}
+
+function add_worksets(json_data) {
+	    
+    //console.log("****" + JSON.stringify(json_data));
+    $.each( json_data["@graph"], function( ws_index, ws_val ) {
+	var workset_title = ws_val["http://purl.org/dc/terms/title"][0]["@value"];
+	
+	var gathers = ws_val["http://www.europeana.eu/schemas/edm/gathers"]
+
+	$.each(gathers, function(gather_index,gather_val) {
+	    var item_url = gather_val["@id"];
+	    
+	    $("[name='"+item_url+"']").each(function() {
+		$(this).parent().show();
+//		if ($(this).find("span").length>1) {
+		if ($(this).children().size()>=1) {
+		    $(this).append("; ");
+		}
+		
+		$(this).append("<span>" + workset_title + "</span>")
+	    });
+	});
+    });
+    
+}
+
 
 function show_new_results(delta)
@@ -118,4 +161,81 @@
 
 
+function workset_enrich_results(itemURLs)
+{
+    // prefix dcterms: <http://purl.org/dc/terms/>
+    // prefix edm: <http://www.europeana.eu/schemas/edm/>
+    // prefix htrc: <http://wcsa.htrc.illinois.edu/>
+    // prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+    // prefix xsd: <http://www.w3.org/2001/XMLSchema#>
+
+    // CONSTRUCT {
+    // 	    ?wsid
+    // 	rdf:type htrc:Workset ;
+    // 	dcterms:title ?title ;
+    // 	dcterms:creator ?cre ;
+    // 	dcterms:created ?dat ;
+    // 	edm:gathers ?gar.}
+
+    // where {
+    // 	    ?wsid
+    // 	rdf:type htrc:Workset ;
+    // 	dcterms:title ?title ;
+    // 	dcterms:creator ?cre ;
+    // 	dcterms:created ?dat ;
+    // 	edm:gathers ?gar
+
+    // 	FILTER ( ?gar  = <http://hdl.handle.net/2027/uc2.ark:/13960/t4fn12212> || ?gar = <http://hdl.handle.net/2027/uva.x030825627> )
+    // 	       }
+
+    var prefixes = "";
+    prefixes += "prefix dcterms: <http://purl.org/dc/terms/>\n";
+    prefixes += "prefix edm: <http://www.europeana.eu/schemas/edm/>\n";
+    prefixes += "prefix htrc: <http://wcsa.htrc.illinois.edu/>\n";
+    prefixes += "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n";
+    prefixes += "prefix xsd: <http://www.w3.org/2001/XMLSchema#>\n";
+
+    var graph_body = "";
+    graph_body += " ?wsid\n";
+    graph_body += "   rdf:type htrc:Workset ;\n";
+    graph_body += "   dcterms:title ?title ;\n";
+    graph_body += "   dcterms:creator ?cre ;\n";
+    graph_body += "   dcterms:created ?dat ;\n";
+    graph_body += "   edm:gathers ?gar .\n";
+
+    var filter_array = [];
+    var item_urls_len = itemURLs.length;
+    for (var hi=0; hi<item_urls_len; hi++) {
+	var htid = itemURLs[hi];
+	filter_array.push("?gar = " + "<"+htid+">");
+    }
+    var filter = " FILTER ( " + filter_array.join(" || ") + " ) ";
+    
+    var construct = "CONSTRUCT {\n" + graph_body + "}\n";
+    var where = "WHERE {\n" + graph_body + filter + "}\n";
+
+    var sparql_query = prefixes + construct + where;
+    //console.log("*** sparql query = " + sparql_query);
+    
+    // http://acbres224.ischool.illinois.edu:8890/sparql?default-graph-uri=&query
+    // &format=application/x-json+ld&timeout=0&debug=on
+
+    var sparql_url = "http://acbres224.ischool.illinois.edu:8890/sparql";
+    var sparql_data = { "default-graph-uri": "",
+			"format": "application/x-json+ld",
+			"timeout": 0,
+			"debug": "on" };
+    sparql_data.query = sparql_query;
+    
+    $.ajax({
+	type: "POST",
+	url: sparql_url,
+	data: sparql_data,
+	dataType: 'jsonp',
+	jsonpCallback: "add_worksets"
+    });
+
+
+
+}
 
 function show_results(jsonData) {
@@ -202,9 +322,11 @@
     var htids_str = htids.join("|",htids);
     var cat_url = "http://catalog.hathitrust.org/api/volumes/brief/json/" + htids_str;
-    	$.ajax({
-	    url: cat_url,
-	    dataType: 'jsonp',
-	    jsonpCallback: "add_titles"
-	});
+    $.ajax({
+	url: cat_url,
+	dataType: 'jsonp',
+	jsonpCallback: "add_titles"
+    });
+
+    
 }
 
