<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * This file consists of mehods that help us in generating XML from the blocks in the editor workspace
 */

var XMLDoc;
var nodes;
var nodeValues;

//initializes some globals.
function generateXML(){
	console.log(cleanRNG);
	XMLDoc = document.implementation.createDocument('http://relaxng.org/ns/structure/1.0', 'xml' , null );
	nodes = [];
	nodeValues = [];
	console.log(XMLDoc);
	var startBlock = Blockly.getMainWorkspace().getTopBlocks()[0];
	console.log(startBlock);
	handleBlock(startBlock);
	console.log(nodes);
	console.log(nodeValues);
	var RNGStartNode = cleanRNG.getElementsByTagName("start")[0];
	var XMLStartNode = XMLDoc.documentElement;
	createXML(RNGStartNode , XMLStartNode);
	console.log(XMLDoc);
	var XMLToString = new XMLSerializer().serializeToString(XMLDoc);
	document.getElementById("XMLOutput").value = XMLToString;
}

/* This function decides the order in which blocks should be traversed.
 * (We visit the block, and then call the block connected to its bottom notch, if any)
 */
function handleBlock(block){
	handleInputs(block.inputList, block);
	var next = block.getNextBlock();
	if(next){
		handleBlock(next);
	}
}

/* This function receives the inputList of a block.
 * It iterates through the list and takes actions depending on whether theere is a statementInput or not
*/
function handleInputs(inputList , block){
	for(var i=1;i<inputList.length;i++){
		if(inputList[i].type ==  Blockly.NEXT_STATEMENT){
			console.log(inputList[i]);
			var attachedBlock = block.getInputTargetBlock(inputList[i].name);
			if(attachedBlock){
				handleBlock(attachedBlock);
			}
		} else{
			handleRow(inputList[i].fieldRow);
		}
	}
}

/* This function goes through each row in the block and collects data from them.
 * It stores the data in arrays called nodes and nodeValues
 */
function handleRow(row){
	var foundTextArea = false;
	var nodeValue, nodeName;
	if(row[ row.length-1 ] instanceof Blockly.FieldTextInput){
		nodeValue = row[ row.length-1 ].text_;
		nodeValues.push(nodeValue);
		nodeName = row[ row.length-2 ].text_;
		nodes.push(nodeName);
	} else{
		var elementName = row[ row.length-1 ].text_;
		nodes.push(elementName);
		nodeValues.push("");
	}
}

/* This function parses RNG nodes and creates the corresponding XML for them.
 * The RNGNode and XMLParent parameters are at the same level in the RNG file and output XML respectively
 */
function createXML(RNGNode , XMLParent){
	var name = RNGNode.getAttribute("name");
	if(name != null){
		if(RNGNode.nodeName == "attribute"){
			var currentName = nodes.shift();
			var currentValue = nodeValues.shift();
			XMLParent.setAttribute(currentName , currentValue);
			return;	//as attribute won't have any children
		} else if(RNGNode.nodeName == "element"){
			var currentName = nodes.shift();
			var currentValue = nodeValues.shift();
			var ele = XMLDoc.createElement(currentName);
			if(currentValue != ""){
				var textNode = XMLDoc.createTextNode(currentValue);
				ele.appendChild(textNode);
				XMLParent.appendChild(ele);
				return;
			}
			XMLParent.appendChild(ele);
			var newParent = XMLDoc.getElementsByTagName(name);
			newParent = newParent[ newParent.length-1 ];
			var children = RNGNode.childNodes;
			for(var i=0;i<children.length;i++){
				createXML(children[i] , newParent);
			}
		} else{
			alert("Cannot handle "+RNGNode.nodeName+" yet");
		}
	} else{
		if(RNGNode.nodeName == "text"){
			var currentName = nodes.shift();
			var currentValue = nodeValues.shift();
			var textNode = XMLDoc.createTextNode(currentValue);
			XMLParent.appendChild(textNode);
			return;
		}
		var children = RNGNode.childNodes;
		for(var i=0;i<children.length;i++){
			createXML(children[i] , XMLParent);
		}
	}
}<commit_msg>Commented out methods used for XML generation in the earlier trial version<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * This file consists of mehods that help us in generating XML from the blocks in the editor workspace
 */








/*
var XMLDoc;
var nodes;
var nodeValues;

//initializes some globals.
function generateXML(){
	console.log(cleanRNG);
	XMLDoc = document.implementation.createDocument('http://relaxng.org/ns/structure/1.0', 'xml' , null );
	nodes = [];
	nodeValues = [];
	console.log(XMLDoc);
	var startBlock = Blockly.getMainWorkspace().getTopBlocks()[0];
	console.log(startBlock);
	handleBlock(startBlock);
	console.log(nodes);
	console.log(nodeValues);
	var RNGStartNode = cleanRNG.getElementsByTagName("start")[0];
	var XMLStartNode = XMLDoc.documentElement;
	createXML(RNGStartNode , XMLStartNode);
	console.log(XMLDoc);
	var XMLToString = new XMLSerializer().serializeToString(XMLDoc);
	document.getElementById("XMLOutput").value = XMLToString;
}*/

/* This function decides the order in which blocks should be traversed.
 * (We visit the block, and then call the block connected to its bottom notch, if any)
 */
/*function handleBlock(block){
	handleInputs(block.inputList, block);
	var next = block.getNextBlock();
	if(next){
		handleBlock(next);
	}
}*/

/* This function receives the inputList of a block.
 * It iterates through the list and takes actions depending on whether theere is a statementInput or not
*/
/*function handleInputs(inputList , block){
	for(var i=1;i<inputList.length;i++){
		if(inputList[i].type ==  Blockly.NEXT_STATEMENT){
			console.log(inputList[i]);
			var attachedBlock = block.getInputTargetBlock(inputList[i].name);
			if(attachedBlock){
				handleBlock(attachedBlock);
			}
		} else{
			handleRow(inputList[i].fieldRow);
		}
	}
}*/

/* This function goes through each row in the block and collects data from them.
 * It stores the data in arrays called nodes and nodeValues
 */
/*function handleRow(row){
	var foundTextArea = false;
	var nodeValue, nodeName;
	if(row[ row.length-1 ] instanceof Blockly.FieldTextInput){
		nodeValue = row[ row.length-1 ].text_;
		nodeValues.push(nodeValue);
		nodeName = row[ row.length-2 ].text_;
		nodes.push(nodeName);
	} else{
		var elementName = row[ row.length-1 ].text_;
		nodes.push(elementName);
		nodeValues.push("");
	}
}*/

/* This function parses RNG nodes and creates the corresponding XML for them.
 * The RNGNode and XMLParent parameters are at the same level in the RNG file and output XML respectively
 */
/*function createXML(RNGNode , XMLParent){
	var name = RNGNode.getAttribute("name");
	if(name != null){
		if(RNGNode.nodeName == "attribute"){
			var currentName = nodes.shift();
			var currentValue = nodeValues.shift();
			XMLParent.setAttribute(currentName , currentValue);
			return;	//as attribute won't have any children
		} else if(RNGNode.nodeName == "element"){
			var currentName = nodes.shift();
			var currentValue = nodeValues.shift();
			var ele = XMLDoc.createElement(currentName);
			if(currentValue != ""){
				var textNode = XMLDoc.createTextNode(currentValue);
				ele.appendChild(textNode);
				XMLParent.appendChild(ele);
				return;
			}
			XMLParent.appendChild(ele);
			var newParent = XMLDoc.getElementsByTagName(name);
			newParent = newParent[ newParent.length-1 ];
			var children = RNGNode.childNodes;
			for(var i=0;i<children.length;i++){
				createXML(children[i] , newParent);
			}
		} else{
			alert("Cannot handle "+RNGNode.nodeName+" yet");
		}
	} else{
		if(RNGNode.nodeName == "text"){
			var currentName = nodes.shift();
			var currentValue = nodeValues.shift();
			var textNode = XMLDoc.createTextNode(currentValue);
			XMLParent.appendChild(textNode);
			return;
		}
		var children = RNGNode.childNodes;
		for(var i=0;i<children.length;i++){
			createXML(children[i] , XMLParent);
		}
	}
}
*/
{'fraction_non_alphanumeric': 0.11874567673507032, 'fraction_numerical': 0.0036891860733225734, 'mean_word_length': 4.371517027863777, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1822644', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2627, 'n_words': 775}