<commit_before>/*
    No, not that Node.js
*/

function visNode(props) {
    var node = props;
    //{ id, label, title, level, content }

    return node;
}
    
visNode.prototype.testFunc = function(something) {
    
};

// text, number, checkbox (string)
Node.Parameter = function(name, type, additionalData)
{
    var obj = {};
	obj.type = ( typeof(type) !== undefined ? type : '' );
    obj.name = ( typeof(name) !== undefined ? name : '' );
    obj.additionalData = ( typeof(additionalData) !== undefined ? additionalData : [] );
	return obj;
}

Node.Function = function(name, params, nodeProps)
{
    var obj = {};
	obj.name = ( typeof(name) !== undefined ? name : '' );
    obj.params = ( typeof(type) !== undefined ? params : [] );
    obj.nodeProps = ( typeof(nodeProps) !== undefined ? nodeProps : {} );
	return obj;
}

Node.Function.prototype._createFuncOptionsHTML = function()
{

}

Node._ShouldDeleteNode = function(node, useCode)
{
	var CODE = {
		NOPE: 0,
		GREATER_THAN_ONE_CHILD: 1,
		NO_PARENTS: 2,
		TOO_MANY_PARENTS: 3,
		NARRATIVE_NODE: 4,
		NO_CHILDREN: 5
	}
	var batman = false;

	if(node.children.length > 1)
	{
		batman = CODE.GREATER_THAN_ONE_CHILD;
	} 
	else if(node.children.length == 0)
	{
		batman = CODE.NO_CHILDREN;
	}
	else if(node.parents.length == 0)
	{
		batman = CODE.NO_PARENTS;
	} 
	else if(node.parents.length > 1) 
	{
		batman = CODE.TOO_MANY_PARENTS;
	}
	else if(node.nodeType.name == Node.NodeTypes.narrative.name)
	{
		batman = CODE.NARRATIVE_NODE;
	}

	if(useCode)
	{
		if(batman === false) return true;
		else return batman;	
	}
	else
	{
		if(batman === false) return true;
		else return false;	
	}

}

// DEPRECATED
Node.FindNextNarrativeNode = function(srcNode)
{
	for (var key in gl.nodesDataset._data) {
		if (gl.nodesDataset._data.hasOwnProperty(key)) {
			if(gl.nodesDataset._data[key].nodeType.name == Node.NodeTypes.narrative.name)
			{
				gl.nodesDataset._data[key];
				return 
			}
		}
	}
	return 0;
}

Node._GetPreviousNarrativeNode = function(parent)
{
	if(parent.nodeType.name == Node.NodeTypes.narrative.name)
	{
		return parent;	
	}
	else
	{
		if(parent.parents[0])
			return Node._GetPreviousNarrativeNode(gl.nodesDataset._data[parent.parents[0].from]);
		else
			return null;
	}
}

Node._LinkParentToChildren = function(node, queuedEdgesForDeletion)
{
	if(node.nodeType.name == Node.NodeTypes.narrative.name) return;

	for (var x = 0; x < node.parents.length; x++) {
		var p = node.parents[x];
		for (var y = 0; y < node.children.length; y++) {
			var c = node.children[y];
			var parentNode = gl.nodesDataset._data[p.from];
			var childNode = gl.nodesDataset._data[c.to];

			if(Node._ShouldDeleteNode(childNode) === false && Node._ShouldDeleteNode(childNode,true) != 4)
			{
				queuedEdgesForDeletion.push(c.id);
			}

			if(parentNode && parentNode.nodeType.name != Node.NodeTypes.narrative.name)
			{
				// backpropogate 
				parentNode = Node._GetPreviousNarrativeNode(parentNode);
				p.from = parentNode.id;
			}
			else if(parentNode)
			{
				p.to = c.to;
				Node._LinkParentToChildren(gl.nodesDataset._data[c.to], queuedEdgesForDeletion);
			}
		};
	};
	return node;
}

Node.GetFirstNode = function()
{
	var level = GetLowestNodeLevel();<commit_msg>Fix critical bug in function node algorithm<commit_after>/*
    No, not that Node.js
*/

function visNode(props) {
    var node = props;
    //{ id, label, title, level, content }

    return node;
}
    
visNode.prototype.testFunc = function(something) {
    
};

// text, number, checkbox (string)
Node.Parameter = function(name, type, additionalData)
{
    var obj = {};
	obj.type = ( typeof(type) !== undefined ? type : '' );
    obj.name = ( typeof(name) !== undefined ? name : '' );
    obj.additionalData = ( typeof(additionalData) !== undefined ? additionalData : [] );
	return obj;
}

Node.Function = function(name, params, nodeProps)
{
    var obj = {};
	obj.name = ( typeof(name) !== undefined ? name : '' );
    obj.params = ( typeof(type) !== undefined ? params : [] );
    obj.nodeProps = ( typeof(nodeProps) !== undefined ? nodeProps : {} );
	return obj;
}

Node.Function.prototype._createFuncOptionsHTML = function()
{

}

Node._ShouldDeleteNode = function(node, useCode)
{
	var CODE = {
		NOPE: 0,
		GREATER_THAN_ONE_CHILD: 1,
		NO_PARENTS: 2,
		TOO_MANY_PARENTS: 3,
		NARRATIVE_NODE: 4,
		NO_CHILDREN: 5
	}
	var batman = false;

	if(node.children.length > 1)
	{
		batman = CODE.GREATER_THAN_ONE_CHILD;
	} 
	else if(node.children.length == 0)
	{
		batman = CODE.NO_CHILDREN;
	}
	else if(node.parents.length == 0)
	{
		batman = CODE.NO_PARENTS;
	} 
	else if(node.parents.length > 1) 
	{
		batman = CODE.TOO_MANY_PARENTS;
	}
	else if(node.nodeType.name == Node.NodeTypes.narrative.name)
	{
		batman = CODE.NARRATIVE_NODE;
	}

	if(useCode)
	{
		if(batman === false) return true;
		else return batman;	
	}
	else
	{
		if(batman === false) return true;
		else return false;	
	}

}

// DEPRECATED
Node.FindNextNarrativeNode = function(srcNode)
{
	for (var key in gl.nodesDataset._data) {
		if (gl.nodesDataset._data.hasOwnProperty(key)) {
			if(gl.nodesDataset._data[key].nodeType.name == Node.NodeTypes.narrative.name)
			{
				gl.nodesDataset._data[key];
				return 
			}
		}
	}
	return 0;
}

Node._GetPreviousNarrativeNode = function(parent)
{
	if(parent.nodeType.name == Node.NodeTypes.narrative.name)
	{
		return parent;	
	}
	else
	{
		if(parent.parents[0])
			return Node._GetPreviousNarrativeNode(gl.nodesDataset._data[parent.parents[0].from]);
		else
			return parent;
	}
}

Node._GetNextNarrativeNode = function(child)
{
	if(child.nodeType.name == Node.NodeTypes.narrative.name)
	{
		return child;	
	}
	else
	{
		if(child.children[0])
			return Node._GetNextNarrativeNode(gl.nodesDataset._data[child.children[0].to]);
		else
			return child;
	}
}

Node._LinkParentToChildren = function(node, queuedEdgesForDeletion)
{
	if(node.nodeType.name == Node.NodeTypes.narrative.name) return;

	for (var x = 0; x < node.parents.length; x++) {
		var p = node.parents[x];
		for (var y = 0; y < node.children.length; y++) {
			var c = node.children[y];
			var parentNode = gl.nodesDataset._data[p.from];
			var childNode = gl.nodesDataset._data[c.to];

			if(Node._ShouldDeleteNode(childNode) === false && Node._ShouldDeleteNode(childNode,true) != 4)
			{
				queuedEdgesForDeletion.push(c.id);
			}

			if(parentNode && parentNode.nodeType.name != Node.NodeTypes.narrative.name)
			{
				// backpropogate 
				parentNode = Node._GetPreviousNarrativeNode(parentNode);
				if(parentNode.nodeType.name == Node.NodeTypes.narrative.name)
					p.from = parentNode.id;
				else 
				{
					var nextNode = Node._GetNextNarrativeNode(node);
					p.to = nextNode.id;
				}
			}
			else if(parentNode)
			{
				p.to = c.to;
				Node._LinkParentToChildren(gl.nodesDataset._data[c.to], queuedEdgesForDeletion);
			}
		};
	};
	return node;
}

Node.GetFirstNode = function()
{
	var level = GetLowestNodeLevel();
{'fraction_non_alphanumeric': 0.1465666474321985, 'fraction_numerical': 0.0049047893825735715, 'mean_word_length': 3.5048732943469787, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1310739', 'n_tokens_mistral': 2852, 'n_tokens_neox': 2591, 'n_words': 450}