<commit_before>package it.bisi;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Utils {

	/**
	 * @param args
	 */
	//public static HashMap hmPercentages = new HashMap();
	public static ArrayList alPercentages = new ArrayList();
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(getResource("/it/bisi/resources/logo.png"));

	}
	public static String removeEol(String input){
		return input.replace("\r","").replace("\n","");
	}
	
	
	public static boolean isNum(String s) {
		try {
		Double.parseDouble(s);
		}
		catch (NumberFormatException nfe) {
		return false;
		}
		return true;
		}
	
	public static URL getResource(String path){
		return Utils.class.getResource(path);
	}
	/**
	 * @param xformLocation
	 * @param formName
	 * @param searchQuestion
	 * @param searchValue
	 * @return
	 */
	
	public static String getXformLabel(String xformLocation, String formName, String searchQuestion, String searchValue){

		//String xformLocation="/home/jaapandre/workspace/webenq4/java/src/webenqResources/org/webenq/resources/3-hva-oo-simpleQuest.xml";

		//read xform info and do something with it 
		// @TODO determine what to do with it
		//read file and put it in dom-object
		File fXmlFile = new File(xformLocation);
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = null;
		try {
			dBuilder = dbFactory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Document doc = null;
		try {
			doc = dBuilder.parse(fXmlFile);
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//search the label of the 'question'		
		XPathFactory factory = XPathFactory.newInstance();
		XPath xpath = factory.newXPath();
		//labels are descendants (children,grandchildren of /html/body
		//attribute (ref) contains the searchInput (needs to have the 'name' of the instance defined under model) 
		//String  searchString="/html/body/descendant::*[@ref='/"+searchQuestion+"']/item[value='1.0']/label";
		String searchString=null;
		if (searchValue != null && !searchValue.equals("")){
			searchString="/html/body/descendant::*[@ref='"+searchQuestion+"']/item[value='"+searchValue+"']/label";
			//System.out.println(searchString);
		} else {
			searchString="/html/body/descendant::*[@ref='"+searchQuestion+"']/label";
		}<commit_msg>escape xml so that eg quotes are treated correct<commit_after>package it.bisi;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.lang.StringEscapeUtils;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Utils {

	/**
	 * @param args
	 */
	//public static HashMap hmPercentages = new HashMap();
	public static ArrayList alPercentages = new ArrayList();
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(getResource("/it/bisi/resources/logo.png"));

	}
	public static String removeEol(String input){
		return input.replace("\r","").replace("\n","");
	}
	
	
	public static boolean isNum(String s) {
		try {
		Double.parseDouble(s);
		}
		catch (NumberFormatException nfe) {
		return false;
		}
		return true;
		}
	
	public static URL getResource(String path){
		return Utils.class.getResource(path);
	}
	/**
	 * @param xformLocation
	 * @param formName
	 * @param searchQuestion
	 * @param searchValue
	 * @return
	 */
	
	public static String getXformLabel(String xformLocation, String formName, String searchQuestion, String searchValue){

		//String xformLocation="/home/jaapandre/workspace/webenq4/java/src/webenqResources/org/webenq/resources/3-hva-oo-simpleQuest.xml";

		//read xform info and do something with it 
		// @TODO determine what to do with it
		//read file and put it in dom-object
		File fXmlFile = new File(xformLocation);
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = null;
		try {
			dBuilder = dbFactory.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Document doc = null;
		try {
			doc = dBuilder.parse(fXmlFile);
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//search the label of the 'question'		
		XPathFactory factory = XPathFactory.newInstance();
		XPath xpath = factory.newXPath();
		//labels are descendants (children,grandchildren of /html/body
		//attribute (ref) contains the searchInput (needs to have the 'name' of the instance defined under model) 
		//String  searchString="/html/body/descendant::*[@ref='/"+searchQuestion+"']/item[value='1.0']/label";
		String searchString=null;
		if (searchValue != null && !searchValue.equals("")){
			searchString="/html/body/descendant::*[@ref='"+StringEscapeUtils.escapeXml(searchQuestion)+"']/item[value='"+StringEscapeUtils.escapeXml(searchValue)+"']/label";
			//System.out.println(searchString);
		} else {
			searchString="/html/body/descendant::*[@ref='"+StringEscapeUtils.escapeXml(searchQuestion)+"']/label";
		}
{'fraction_non_alphanumeric': 0.12893982808022922, 'fraction_numerical': 0.001591849729385546, 'mean_word_length': 4.435121107266436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 21}, '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': '1205371', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1901, 'n_words': 454}