<commit_before>var PropertySuggestDropdown = (function() {

	var instance = null;


	function PrivateConstructor() {
		var menuId = "propertySuggestDropdown";
		var worksheetId;
		var alignmentId;
		var propertyId;
		var propertyUri;
		var sourceNodeId, sourceLabel, sourceDomain, sourceId, sourceNodeType, sourceIsUri;
		var targetNodeId, targetLabel, targetDomain, targetId, targetNodeType, targetIsUri;
		var allPropertiesCache;

		function init() {
			allPropertiesCache = null;
			generateJS();
			window.setTimeout(function() {
				allPropertiesCache = getAllDataAndObjectProperties(worksheetId);
			}, 10);
		}

		function hide() {
			$("#" + menuId).hide();
			$(document).off('click', hide);
		}

		function changeLink(label, uri) {
			var info = generateInfoObject(worksheetId, "", "ChangeInternalNodeLinksCommand");
			// Prepare the input for command
			var newInfo = info['newInfo'];
			newInfo.push(getParamObject("alignmentId", alignmentId, "other"));

			// Put the old edge information
			var initialEdges = [];
			var oldEdgeObj = {};
			oldEdgeObj["edgeSourceId"] = sourceId;
			oldEdgeObj["edgeTargetId"] = targetId;
			oldEdgeObj["edgeId"] = propertyUri;
			initialEdges.push(oldEdgeObj);
			newInfo.push(getParamObject("initialEdges", initialEdges, "other"));
			info["initialEdges"] = initialEdges;

			// Put the new edge information
			var newEdges = [];
			var newEdgeObj = {};
			newEdgeObj["edgeSourceId"] = sourceId;
			newEdgeObj["edgeSourceUri"] = sourceDomain;
			newEdgeObj["edgeTargetId"] = targetId;
			newEdgeObj["edgeTargetUri"] = targetDomain;
			newEdgeObj["edgeId"] = uri;
			newEdges.push(newEdgeObj);
			newInfo.push(getParamObject("newEdges", newEdges, "other"));
			info["newEdges"] = newEdges;

			info["newInfo"] = JSON.stringify(newInfo);
			showLoading(worksheetId);
			var returned = sendRequest(info, worksheetId);
			hide();
		}

		function changeSemanticType(label, uri) {
			var info = generateInfoObject(worksheetId, targetId, "");
			var newInfo = info['newInfo']; 
			if(label == "uri") {
				info["command"] = "SetMetaPropertyCommand";
				info["metaPropertyName"] = "isUriOfClass";
				info["metaPropertyUri"] = sourceDomain;
				info["metaPropertyId"] = sourceId;
				newInfo.push(getParamObject("metaPropertyName", info["metaPropertyName"], "other"));
				newInfo.push(getParamObject("metaPropertyUri", info["metaPropertyUri"], "other"));
				newInfo.push(getParamObject("metaPropertyId", info["metaPropertyId"], "other"));
			} else {
				info["command"] = "SetSemanticTypeCommand";
				var semTypesArray = new Array();
				var newType = new Object();
				newType["FullType"] = uri;
				newType["DomainUri"] = sourceDomain;
				newType["DomainId"] = sourceId;
				newType["DomainLabel"] = sourceLabel;
				semTypesArray.push(newType);
				info["SemanticTypesArray"] = JSON.stringify(semTypesArray);
				newInfo.push(getParamObject("SemanticTypesArray", semTypesArray, "other"));
			}
			newInfo.push(getParamObject("trainAndShowUpdates", true, "other"));
			newInfo.push(getParamObject("rdfLiteralType", '', "other"));

			info["newInfo"] = JSON.stringify(newInfo);
			showLoading(info["worksheetId"]);
			var returned = sendRequest(info, worksheetId);
			hide();
		}

		function generateJS() {
			var ul = $("<ul>");
			ul.attr("role", "menu")
				.addClass("dropdown-menu")
				.css("display", "block")
				.css("position", "static")
				.css("margin-bottom", "5px");
		
			var box = $("<div>").addClass("input-group").addClass("dropdownInput");
			var search = $("<span>").addClass("input-group-addon").append($("<span>").addClass("glyphicon").addClass("glyphicon-search"));
			var input = $("<input>").attr("type", "text").addClass("form-control").attr("id", "input_" + menuId).addClass("typeahead").attr("autocomplete", "off").val('');
			box.append(search).append(input);

			var div = $("<div>")
				.attr("id", menuId)
				.addClass("dropdown")
				.addClass("clearfix")
				.addClass("contextMenu")
				.append(ul);

			var li = $("<li>");
			li.append(box);
			ul.append(li);

			var container = $("body div.container");
			container.append(div);

			$('.dropdownInput input').click(function(e){e.stopPropagation; return false;}); 
			$('.dropdownInput input')
			        .on('keyup', filterDropdown);
		}

	
		function selectPropertyFromMenu(e) {
			target = $(e.target);
			label = target.text();
			

			console.log("Selected property:" + label);
			if(label == 'More...') {
				populateAllProperties();
				e.stopPropagation();
			} else {
				uri = target.data('uri');
				if(targetNodeType == "ColumnNode") {
					changeSemanticType(label, uri);
				} else {
					changeLink(label, uri);	
				}
			}
		}

		function populateAllProperties() {
			if(allPropertiesCache == null) {
				window.setTimeout(populateAllProperties, 10);
				return;
			}

			var allTypes = [];
			

			if(targetNodeType == "ColumnNode") {
				allTypes.push({"label": "uri of " + sourceLabel, "uri": "http://isi.edu/integration/karma/dev#classLink"});
				allTypes.push({"label": "divider", "uri": "divider"});
			}

			$.each(allPropertiesCache, function(index, type) {
				allTypes.push({"label": type["label"], "uri": type["uri"]});
			});

			renderMenu(allTypes, true);
		}

		function filterDropdown(e) {
			query = $("#input_" + menuId).val();
			switch(e.keyCode) {
		        case 40: // down arrow
		        case 38: // up arrow
		        case 16: // shift
		        case 17: // ctrl
		        case 18: // alt
		          break;

		        case 9: // tab
		        case 13: // enter
		          if (!this.shown) return;
		          this.select();
		          break;

		        case 27: // escape
		          this.hide();
		          break;
		        default:
		          	items = displayMenuItems;
		          	items = $.grep(items, function (item) {
			        	return (item["label"].toLowerCase().indexOf(query.toLowerCase()) != -1);
			      	});
			      	renderMenu(items, false);
		      }
		}

		function populateMenu() {
			if(targetNodeType == "ColumnNode") {
				var semSuggestions = getSuggestedSemanticTypes(worksheetId, targetId, sourceDomain);
				var items = [];
				var uriFound = false;
				if(semSuggestions != null) {
					$.each(semSuggestions["Labels"], function(index, type) {
						if(type["DisplayLabel"] == "km-dev:columnSubClassOfLink" ||
								type["DisplayLabel"] == "km-dev:dataPropertyOfColumnLink" ||
								type["DisplayLabel"] == "km-dev:objectPropertySpecialization") {
							return;
						}
						if(type["DisplayLabel"] == "uri" || type["DisplayLabel"] == "km-dev:classLink") {
							uriFound = true;
							type["DisplayLabel"] = "uri of " + sourceLabel;
						}
						items.push({"label": type["DisplayLabel"], "uri": type["FullType"], "class": "propertyDropdown_suggestion"});
					});
				}

				var compatibleTypes = [];
				if(!uriFound)
					compatibleTypes.push({"label": "uri of " + sourceLabel, "uri": "http://isi.edu/integration/karma/dev#classLink"});

				compatibleTypes = compatibleTypes.concat(getAllPropertiesForClass(worksheetId, sourceDomain));
			
				if(compatibleTypes.length > 0 && items.length > 0)
					items.push({"label": "divider", "uri": "divider"});
				$.each(compatibleTypes, function(index, type) {
					items.push({"label": type["label"], "uri": type["uri"], "class": "propertyDropdown_compatible"});
				});	
				
				if(items.length > 0) {
					items.push({"label": "divider", "uri": "divider"});
					items.push({"label": "More...", "uri": "More..."});
					renderMenu(items, true);
				} else {
					populateAllProperties();
				}
			} else {<commit_msg>show suggestions on the top when user clicks More in properties dropdown<commit_after>var PropertySuggestDropdown = (function() {

	var instance = null;


	function PrivateConstructor() {
		var menuId = "propertySuggestDropdown";
		var worksheetId;
		var alignmentId;
		var propertyId;
		var propertyUri;
		var sourceNodeId, sourceLabel, sourceDomain, sourceId, sourceNodeType, sourceIsUri;
		var targetNodeId, targetLabel, targetDomain, targetId, targetNodeType, targetIsUri;
		var allPropertiesCache;
		var semanticSuggestions;

		function init() {
			allPropertiesCache = null;
			generateJS();
			window.setTimeout(function() {
				allPropertiesCache = getAllDataAndObjectProperties(worksheetId);
			}, 10);
		}

		function hide() {
			$("#" + menuId).hide();
			$(document).off('click', hide);
		}

		function changeLink(label, uri) {
			var info = generateInfoObject(worksheetId, "", "ChangeInternalNodeLinksCommand");
			// Prepare the input for command
			var newInfo = info['newInfo'];
			newInfo.push(getParamObject("alignmentId", alignmentId, "other"));

			// Put the old edge information
			var initialEdges = [];
			var oldEdgeObj = {};
			oldEdgeObj["edgeSourceId"] = sourceId;
			oldEdgeObj["edgeTargetId"] = targetId;
			oldEdgeObj["edgeId"] = propertyUri;
			initialEdges.push(oldEdgeObj);
			newInfo.push(getParamObject("initialEdges", initialEdges, "other"));
			info["initialEdges"] = initialEdges;

			// Put the new edge information
			var newEdges = [];
			var newEdgeObj = {};
			newEdgeObj["edgeSourceId"] = sourceId;
			newEdgeObj["edgeSourceUri"] = sourceDomain;
			newEdgeObj["edgeTargetId"] = targetId;
			newEdgeObj["edgeTargetUri"] = targetDomain;
			newEdgeObj["edgeId"] = uri;
			newEdges.push(newEdgeObj);
			newInfo.push(getParamObject("newEdges", newEdges, "other"));
			info["newEdges"] = newEdges;

			info["newInfo"] = JSON.stringify(newInfo);
			showLoading(worksheetId);
			var returned = sendRequest(info, worksheetId);
			hide();
		}

		function changeSemanticType(label, uri) {
			var info = generateInfoObject(worksheetId, targetId, "");
			var newInfo = info['newInfo']; 
			if(label == "uri") {
				info["command"] = "SetMetaPropertyCommand";
				info["metaPropertyName"] = "isUriOfClass";
				info["metaPropertyUri"] = sourceDomain;
				info["metaPropertyId"] = sourceId;
				newInfo.push(getParamObject("metaPropertyName", info["metaPropertyName"], "other"));
				newInfo.push(getParamObject("metaPropertyUri", info["metaPropertyUri"], "other"));
				newInfo.push(getParamObject("metaPropertyId", info["metaPropertyId"], "other"));
			} else {
				info["command"] = "SetSemanticTypeCommand";
				var semTypesArray = new Array();
				var newType = new Object();
				newType["FullType"] = uri;
				newType["DomainUri"] = sourceDomain;
				newType["DomainId"] = sourceId;
				newType["DomainLabel"] = sourceLabel;
				semTypesArray.push(newType);
				info["SemanticTypesArray"] = JSON.stringify(semTypesArray);
				newInfo.push(getParamObject("SemanticTypesArray", semTypesArray, "other"));
			}
			newInfo.push(getParamObject("trainAndShowUpdates", true, "other"));
			newInfo.push(getParamObject("rdfLiteralType", '', "other"));

			info["newInfo"] = JSON.stringify(newInfo);
			showLoading(info["worksheetId"]);
			var returned = sendRequest(info, worksheetId);
			hide();
		}

		function generateJS() {
			var ul = $("<ul>");
			ul.attr("role", "menu")
				.addClass("dropdown-menu")
				.css("display", "block")
				.css("position", "static")
				.css("margin-bottom", "5px");
		
			var box = $("<div>").addClass("input-group").addClass("dropdownInput");
			var search = $("<span>").addClass("input-group-addon").append($("<span>").addClass("glyphicon").addClass("glyphicon-search"));
			var input = $("<input>").attr("type", "text").addClass("form-control").attr("id", "input_" + menuId).addClass("typeahead").attr("autocomplete", "off").val('');
			box.append(search).append(input);

			var div = $("<div>")
				.attr("id", menuId)
				.addClass("dropdown")
				.addClass("clearfix")
				.addClass("contextMenu")
				.append(ul);

			var li = $("<li>");
			li.append(box);
			ul.append(li);

			var container = $("body div.container");
			container.append(div);

			$('.dropdownInput input').click(function(e){e.stopPropagation; return false;}); 
			$('.dropdownInput input')
			        .on('keyup', filterDropdown);
		}

	
		function selectPropertyFromMenu(e) {
			target = $(e.target);
			label = target.text();
			

			console.log("Selected property:" + label);
			if(label == 'More...') {
				populateAllProperties();
				e.stopPropagation();
			} else {
				uri = target.data('uri');
				if(targetNodeType == "ColumnNode") {
					changeSemanticType(label, uri);
				} else {
					changeLink(label, uri);	
				}
			}
		}

		function populateAllProperties() {
			if(allPropertiesCache == null) {
				window.setTimeout(populateAllProperties, 10);
				return;
			}

			var allTypes = [];
			var uriFound = false;
			$.each(semanticSuggestions, function(index, type) {
				allTypes.push({"label": type["label"], "uri": type["uri"], "class": type["class"]});
				if(type["uri"] == "http://isi.edu/integration/karma/dev#classLink")
					uriFound = true;
			});

			if(allTypes.length > 0) 
				allTypes.push({"label": "divider", "uri": "divider"});

			if(targetNodeType == "ColumnNode" && uriFound == false) {
				allTypes.push({"label": "uri of " + sourceLabel, "uri": "http://isi.edu/integration/karma/dev#classLink"});
				allTypes.push({"label": "divider", "uri": "divider"});
			}

			$.each(allPropertiesCache, function(index, type) {
				allTypes.push({"label": type["label"], "uri": type["uri"]});
			});

			renderMenu(allTypes, true);
		}

		function filterDropdown(e) {
			query = $("#input_" + menuId).val();
			switch(e.keyCode) {
		        case 40: // down arrow
		        case 38: // up arrow
		        case 16: // shift
		        case 17: // ctrl
		        case 18: // alt
		          break;

		        case 9: // tab
		        case 13: // enter
		          if (!this.shown) return;
		          this.select();
		          break;

		        case 27: // escape
		          this.hide();
		          break;
		        default:
		          	items = displayMenuItems;
		          	items = $.grep(items, function (item) {
			        	return (item["label"].toLowerCase().indexOf(query.toLowerCase()) != -1);
			      	});
			      	renderMenu(items, false);
		      }
		}

		function populateMenu() {
			semanticSuggestions = []
			if(targetNodeType == "ColumnNode") {
				var semSuggestions = getSuggestedSemanticTypes(worksheetId, targetId, sourceDomain);
				var items = [];
				var uriFound = false;
				if(semSuggestions != null) {
					$.each(semSuggestions["Labels"], function(index, type) {
						if(type["DisplayLabel"] == "km-dev:columnSubClassOfLink" ||
								type["DisplayLabel"] == "km-dev:dataPropertyOfColumnLink" ||
								type["DisplayLabel"] == "km-dev:objectPropertySpecialization") {
							return;
						}
						if(type["DisplayLabel"] == "uri" || type["DisplayLabel"] == "km-dev:classLink") {
							uriFound = true;
							type["DisplayLabel"] = "uri of " + sourceLabel;
						}
						items.push({"label": type["DisplayLabel"], "uri": type["FullType"], "class": "propertyDropdown_suggestion"});
					});
				}

				semanticSuggestions = semanticSuggestions.concat(items);

				if(!uriFound) {
					if(items.length > 0)
						items.push({"label": "divider", "uri": "divider"});
					items.push({"label": "uri of " + sourceLabel, "uri": "http://isi.edu/integration/karma/dev#classLink"});
				}

				var compatibleTypes = getAllPropertiesForClass(worksheetId, sourceDomain);
			
				if(compatibleTypes.length > 0 && items.length > 0)
					items.push({"label": "divider", "uri": "divider"});
				$.each(compatibleTypes, function(index, type) {
					items.push({"label": type["label"], "uri": type["uri"], "class": "propertyDropdown_compatible"});
				});	
				
				if(items.length > 0) {
					items.push({"label": "divider", "uri": "divider"});
					items.push({"label": "More...", "uri": "More..."});
					renderMenu(items, true);
				} else {
					populateAllProperties();
				}
			} else {
{'fraction_non_alphanumeric': 0.17263905625673875, 'fraction_numerical': 0.003171180313312615, 'mean_word_length': 3.6159250585480094, 'pattern_counts': {'":': 47, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3223358', 'n_tokens_mistral': 6017, 'n_tokens_neox': 4831, 'n_words': 913}