Mercurial > hg > NetworkVis
comparison query_builder/querybuild.html @ 34:4bbb832c53ac
Completed: Base functionality for simple examples. Minus button now removes all filters for simplicity. Still need to adjust how to go about restarting the querying process once a result has been selected from the display list (eg. the 'selected object is:' case). Also need to strip out a bunch of unneeded code.
author | arussell |
---|---|
date | Sat, 19 Dec 2015 23:25:23 -0500 |
parents | acc60a20582c |
children |
comparison
equal
deleted
inserted
replaced
33:758a5313baf4 | 34:4bbb832c53ac |
---|---|
53 <select class="selected-object form-control"> | 53 <select class="selected-object form-control"> |
54 <option selected>Object type : </option> | 54 <option selected>Object type : </option> |
55 </select> | 55 </select> |
56 </div> | 56 </div> |
57 <div class="col-sm-4 col-md-4" id="select-col2"> | 57 <div class="col-sm-4 col-md-4" id="select-col2"> |
58 <select class="select-object1 form-control"> | 58 <select class="select-object1 form-control" id="startselect"> |
59 <option selected>TEXT</option> | 59 <option disable selected></option> |
60 <option>TEXT</option> | |
60 <option>WITNESS</option> | 61 <option>WITNESS</option> |
61 <option>PERSON</option> | 62 <option>PERSON</option> |
62 <option>CODEX</option> | 63 <option>CODEX</option> |
63 <option>PLACE</option> | 64 <option>PLACE</option> |
64 <option>REPOSITORY</option> | 65 <option>REPOSITORY</option> |
107 <script type="text/javascript" class="js-code-data-array"> | 108 <script type="text/javascript" class="js-code-data-array"> |
108 //var queryData = []; | 109 //var queryData = []; |
109 | 110 |
110 // Defining initial variables and helper functions | 111 // Defining initial variables and helper functions |
111 var sourceType = "TEXT"; | 112 var sourceType = "TEXT"; |
113 var currentQueryData; | |
112 var targets = []; | 114 var targets = []; |
113 var targetTypes = []; | 115 var targetTypes = []; |
114 var targetObj = []; // The current objects on the display box | 116 var targetObj = [{}]; // The current objects on the display box |
115 var numFilters = 1; | 117 var numFilters = 1; |
116 var filters = [ | 118 var filters = [ |
117 { id: 0, text: 'has relation' }, | 119 { id: 0, text: 'has relation' }, |
118 { id: 1, text: 'attribute' } | 120 { id: 1, text: 'attribute' } |
119 ]; | 121 ]; |
181 $(".filter-box"+numFilters).select2({ | 183 $(".filter-box"+numFilters).select2({ |
182 data: filters, | 184 data: filters, |
183 minimumResultsForSearch: Infinity | 185 minimumResultsForSearch: Infinity |
184 }); | 186 }); |
185 }); | 187 }); |
188 // TODO: update minus button to alter the currRel currAttr arrays | |
186 $("#minus_filter_button").click(function() { | 189 $("#minus_filter_button").click(function() { |
187 console.log("minus filter"); | 190 console.log("minus filter"); |
188 $("#row"+numFilters).remove(); | 191 //$("#row"+numFilters).remove(); |
189 numFilters--; | 192 //numFilters--; |
193 | |
194 // NOTE: Temporary solution for removing filters, | |
195 while (numFilters > 0) { | |
196 $("#row"+numFilters).remove(); | |
197 numFilters--; | |
198 } | |
199 numFilters++; | |
200 $("#filters").append(filter_html(numFilters)); | |
201 $(".filter-box"+numFilters).select2({ | |
202 data: filters, | |
203 minimumResultsForSearch: Infinity | |
204 }); | |
205 currAttrs = []; | |
206 currRels = []; | |
207 currSource = sourceType; | |
208 | |
209 | |
190 }); | 210 }); |
191 $("#results-container").dblclick(function() { | 211 $("#results-container").dblclick(function() { |
192 var displayChoice = $("#results-container").find("option:selected").text(); | 212 var displayChoice = $("#results-container").find("option:selected").text(); |
193 console.log(displayChoice + "........."); | 213 console.log(targetObj); |
194 var selection; | 214 if (!targetObj[displayChoice]) { |
195 | 215 // increase tolerance |
196 _.map(targetObj, function(obj){ | 216 console.log("increase listTolerance"); |
197 | 217 listTolerance = 100000; |
198 if (_.values(_.values(targetObj))[1] === displayChoice) { | 218 process_display_results(currentQueryData); |
199 selection = (_.values(_.values(obj))[0])[1]; | 219 listTolerance = 100; |
200 } | 220 } |
201 else { | 221 else { |
202 selection = (_.values(_.values(obj))[0])[0]; | 222 console.log(displayChoice + "........."); |
203 } | 223 var displayType = targetObj[displayChoice]; |
204 }); | 224 /* |
205 numFilters++; | 225 _.map(targetObj, function(obj){ |
206 $("#filters").append(select_html(selection, numFilters)); | 226 |
207 // Generate inner relation list | 227 if (_.values(_.values(targetObj))[1] === displayChoice) { |
208 //genRelations(sourceType, ".constraint-box"+numFilters); | 228 selection = (_.values(_.values(obj))[0])[1]; |
209 sourceType = selection; | 229 } |
210 console.log("add filter"); | 230 else { |
231 selection = (_.values(_.values(obj))[0])[0]; | |
232 } | |
233 }); | |
234 */ | |
235 numFilters++; | |
236 $("#filters").append(select_html(displayChoice, numFilters)); | |
237 // Generate inner relation list | |
238 //genRelations(sourceType, ".constraint-box"+numFilters); | |
239 sourceType = displayChoice; | |
240 console.log("New Target"); | |
241 genResults("New Target", [displayType,displayChoice], "target") | |
242 } | |
211 }); | 243 }); |
212 $(function() { | 244 $(function() { |
213 $("input").submit(function(event, data) { | 245 $("input").submit(function(event, data) { |
214 console.log($('.form-control').find("option:selected").text()); | 246 console.log($('.form-control').find("option:selected").text()); |
215 console.log(event); | 247 console.log(event); |
298 var query = "match (source:"+sourceNodeType+")-[rel]-target return distinct rel.type"; | 330 var query = "match (source:"+sourceNodeType+")-[rel]-target return distinct rel.type"; |
299 console.log("QUERY TYPE IS RELATION NOW"); | 331 console.log("QUERY TYPE IS RELATION NOW"); |
300 currentQueryType = "relation"; | 332 currentQueryType = "relation"; |
301 ajax1(query, constraintBox); | 333 ajax1(query, constraintBox); |
302 } | 334 } |
335 | |
303 function genAttributes(sourceNodeType, constraintBox) { | 336 function genAttributes(sourceNodeType, constraintBox) { |
304 console.log("GENERATE ALL ATTRIBUTES"); | 337 console.log("GENERATE ALL ATTRIBUTES"); |
305 var query = "match (n:"+sourceNodeType+") with keys(n) as collection unwind collection as attributes return distinct attributes"; | 338 var query = "match (n:"+sourceNodeType+") with keys(n) as collection unwind collection as attributes return distinct attributes"; |
306 ajax1(query, constraintBox); | 339 ajax1(query, constraintBox); |
307 } | 340 } |
341 | |
308 function genResults(sourceNodeType, selected, constraintBox) { | 342 function genResults(sourceNodeType, selected, constraintBox) { |
309 // TODO: Return first the list of current values of the display box | 343 // TODO: Return first the list of current values of the display box |
310 | 344 |
311 if (selected === "New Source") { | 345 if (selected === "New Source") { |
312 console.log("NEW SOURCE - UPDATE RESULTS"); | 346 console.log("NEW SOURCE - UPDATE RESULTS"); |
313 var query = "match (source:"+sourceNodeType+") return source._n_label, source.type"; | 347 var query = "match (source:"+sourceNodeType+") return source._n_label, source.type"; |
348 set_current_query('source', sourceNodeType+")"); | |
349 } | |
350 else if (sourceNodeType === "New Target") { | |
351 newTarget = 1; | |
352 set_current_query('target', selected); | |
353 var query = get_current_query; | |
314 } | 354 } |
315 else if (currentQueryType === "attribute") { | 355 else if (currentQueryType === "attribute") { |
316 console.log("ATTR CHANGE - UPDATE RESULTS"); | 356 console.log("ATTR CHANGE - UPDATE RESULTS"); |
317 console.log("before update currentQueryAttr is " + currentQueryAttr); | 357 console.log("before update currentQueryAttr is " + currentQueryAttr); |
318 var qAttr = currentQueryAttr; | 358 var qAttr = currentQueryAttr; |
319 var query = "match (source:"+sourceNodeType+") where "+get_result_labels()+" AND source."+qAttr+"=~\"(?i).*"+selected+".*\" return distinct source._n_label, source.type limit 5"; | 359 set_current_query('attribute', "."+qAttr+"=~\"(?i).*"+selected+".*\""); |
360 // this might cause an issue | |
361 var query = get_current_query(); | |
362 } | |
363 /* | |
364 var query = "match (source:"+sourceNodeType+") where "; | |
365 if (get_result_labels()) query += get_result_labels() + " AND "; | |
366 query += "source."+qAttr+"=~\"(?i).*"+selected+".*\" return distinct source._n_label, source.type limit 5"; | |
367 // TODO: case where all attributes are searched | |
368 // if (selected === "ALL") set_current_query('attribute', "."+qAttr+"=~\"(?i).*"+selected+".*\""); | |
369 | |
320 console.log(query); | 370 console.log(query); |
321 } | 371 */ |
322 else if (currentQueryType === "relation") { | 372 else if (currentQueryType === "relation") { |
323 var query = "match (source:" + sourceNodeType + ")-[rel:" + selected + "]->(target) return distinct target._n_label, target.type"; | 373 var query = "match (source:" + sourceNodeType + ")-[rel:" + selected + "]->(target) return distinct target._n_label, target.type"; |
324 console.log("REL CHANGE - UPDATE RESULTS"); | 374 console.log("REL CHANGE - UPDATE RESULTS"); |
375 set_current_query('relation', selected+"]->("); | |
325 } | 376 } |
326 else { | 377 else { |
327 console.log("GENRESULTS IMPROPERLY CALLED"); | 378 console.log("GENRESULTS IMPROPERLY CALLED"); |
328 return; | 379 return; |
329 } | 380 } |
343 } | 394 } |
344 resultLabelString += ")" | 395 resultLabelString += ")" |
345 } | 396 } |
346 // to use contains | 397 // to use contains |
347 // TODO: start n = node(*) where n.Name =~ '.*SUBSTRING.*' return n.Name, n; | 398 // TODO: start n = node(*) where n.Name =~ '.*SUBSTRING.*' return n.Name, n; |
399 | |
400 var currSource = [sourceType]; | |
401 var currRels = []; | |
402 var currAttrs = []; | |
403 var currQ = ''; | |
404 | |
405 function set_current_query(type, q) { | |
406 if (type === 'source') { | |
407 currSource[0] = ("match (source:"+q); | |
408 } | |
409 else if (type === 'target') { | |
410 currSource.push("match (target:"+q[0]+")"); | |
411 currRels = []; | |
412 currAttrs = []; | |
413 currAttrs.push("target._n_label=\""+q[1]+"\""); | |
414 } | |
415 else if (type === 'relation') { | |
416 currRels.push("-[rel"+currRels.length+":"+q+"target"+currRels.length+")"); | |
417 } | |
418 else if (type === 'attribute') { | |
419 if (Boolean(currRels.length)) currAttrs.push("target"+(currRels.length-1)+q); | |
420 else currAttrs.push("source"+q); | |
421 } | |
422 else if (type === 'return') { | |
423 return currQ | |
424 } | |
425 else { | |
426 console.log("improper call to change current query"); | |
427 } | |
428 } | |
429 var newTarget = -1; | |
430 function get_current_query() { | |
431 var currQ = currSource[currSource.length-1]; | |
432 var i; | |
433 var n=currRels.length; | |
434 var m=currAttrs.length; | |
435 for (i=0; i<n; i++) { | |
436 currQ += currRels[i]; | |
437 } | |
438 currQ += " where "; | |
439 for (i=0; i<m; i++) { | |
440 if (Boolean(i)) { | |
441 currQ += "AND "; | |
442 } | |
443 currQ += currAttrs[i]+" "; | |
444 } | |
445 if (Boolean(currRels.length)) { | |
446 currQ += "return distinct target"+(currRels.length-1)+"._n_label, target"+(currRels.length-1)+".type"; | |
447 } | |
448 else if (newTarget > 0) { | |
449 currQ += "return distinct target._n_label, target.type"; | |
450 newTarget = -1; | |
451 } | |
452 else currQ += "return distinct source._n_label, source.type"; | |
453 console.log(currQ); | |
454 return currQ; | |
455 } | |
456 | |
457 | |
348 | 458 |
349 | 459 |
350 | 460 |
351 // Ajax request function | 461 // Ajax request function |
352 function ajax1(q, resBox) { | 462 function ajax1(q, resBox) { |
397 // On success, generate new data | 507 // On success, generate new data |
398 // TODO: might want to just always return nodes and then deal with the queryData different for each type of return | 508 // TODO: might want to just always return nodes and then deal with the queryData different for each type of return |
399 function dataGen(dataArr, resBox) { | 509 function dataGen(dataArr, resBox) { |
400 var d = dataArr; | 510 var d = dataArr; |
401 targets = []; | 511 targets = []; |
512 targetObj = []; | |
402 | 513 |
403 // Consider implementing localStorage to avoid reloading every time | 514 // Consider implementing localStorage to avoid reloading every time |
404 var queryData = []; | 515 var queryData = []; |
405 for (var i= 0; i<d.length; i++) { | 516 for (var i= 0; i<d.length; i++) { |
406 var j = d[i]; | 517 var j = d[i]; |
407 queryData.push({ id: j, text: j[0] }); | 518 queryData.push({ id: j, text: j[0] }); |
408 targets.push(j[1]); | 519 targets.push(j[1]); |
409 } | 520 targetObj[j[0]]=j[1]; |
521 } | |
522 console.log(queryData); | |
410 // Now that queryData array has been defined we will sort it by its label value and initialize the option. | 523 // Now that queryData array has been defined we will sort it by its label value and initialize the option. |
411 queryData.sort(function(a,b){ | 524 queryData.sort(function(a,b){ |
412 var c = a.text.replace(/<|>/g, ''); | 525 var c = a.text.replace(/<|>/g, ''); |
413 var d = b.text.replace(/<|>/g, ''); | 526 var d = b.text.replace(/<|>/g, ''); |
414 return c.localeCompare(d); | 527 return c.localeCompare(d); |
416 | 529 |
417 // Change the displayed results | 530 // Change the displayed results |
418 if (resBox === "results-container") { | 531 if (resBox === "results-container") { |
419 process_display_results(queryData); | 532 process_display_results(queryData); |
420 } | 533 } |
534 if (resBox === "target") { | |
535 sourceType = currSource[0]; | |
536 } | |
421 // Or fill any select boxes | 537 // Or fill any select boxes |
422 else { | 538 else { |
423 $(resBox).select2({ | 539 $(resBox).select2({ |
424 data: queryData | 540 data: queryData |
425 }); | 541 }); |
426 } | 542 } |
427 } | 543 } |
428 function process_display_results(queryData) { | 544 function process_display_results(queryData) { |
545 currentQueryData = queryData; | |
429 var weights = []; | 546 var weights = []; |
430 var resultLength = queryData.length; | 547 var resultLength = queryData.length; |
431 targetTypes = []; | 548 targetTypes = []; |
432 targetObj = queryData; | |
433 set_result_labels(queryData); | 549 set_result_labels(queryData); |
434 $('#results-container') | 550 $('#results-container') |
435 .find('option') | 551 .find('option') |
436 .remove() | 552 .remove() |
437 .end() | 553 .end() |