<commit_before>package edu.rice.bayou.annotations;

import java.util.List;
import java.util.ArrayList;
import org.apache.commons.cli.*;

public class EvidenceObject {
    protected String type;

    protected List<String> elements;

    public EvidenceObject(String evidStr) {
	try {
            parseString(evidStr);
        } catch (ParseException e) {
            System.out.println("The bayou evidence should use such format: '" + "@key : value1, value2, ... '");
        }
    }

    protected void parseString(String input) throws ParseException {
	if (input.equals("")) {
	    throw new ParseException("Can not parse evidence");
	} 

	int start = input.indexOf("@");
	if (start > 0) {
	    checkBlank(input.substring(0, start));
	}

	// Get type name
	String content = parseType(input.substring(start + 1, input.length()));
	while (content != null) 
	    content = parseValue(content);
    }

    // Parse the type name
    protected String parseType(String input) throws ParseException {
	int stop = input.indexOf(":");
	int stop_ = input.indexOf(" ");
	if (stop == 0 || stop_ == 0)
	    throw new ParseException("Wrong type");

	if (stop > stop_) {
	    this.type = input.substring(0, stop_);
	} else 
	    this.type = input.substring(0, stop);

	return input.substring(stop + 1, input.length());
    }
    
    // Parse the values
    protected String parseValue(String input) throws ParseException {
	// Remove blank space
	if (input.length() == 0)
	    return null;

	while (input.indexOf(" ") == 0) {
	    if (input.length() == 1)
		return null;

	    input = input.substring(1, input.length());
	}

	int stop = input.indexOf(",");
	int stop_ = input.indexOf(" ");
	if (stop == 0)
	    throw new ParseException("Wrong value");

	if (stop > stop_) {
	    addValue(input.substring(0, stop_));
	    return input.substring(stop_, input.length());
	} else if (stop > 0) {
            addValue(this.type = input.substring(0, stop));
	    return input.substring(stop, input.length());
	}

	throw new ParseException("Wrong value");
    }

    protected void checkBlank(String blankString) throws ParseException {
	int idx = 0; 
	while (idx < blankString.length()) {
	    if (!blankString.substring(idx, idx + 1).equals(" "))
		throw new ParseException("Not blank space?");
	    idx += 1;
	}
    }

    protected void addValue(String value) {
	if (this.elements == null)
	    this.elements = new ArrayList<String>();
<commit_msg>minors fix<commit_after>package edu.rice.bayou.annotations;

import java.util.List;
import java.util.ArrayList;
import org.apache.commons.cli.*;

public class EvidenceObject {
    protected String type;

    protected List<String> elements;

    public EvidenceObject(String evidStr) {
	try {
            parseString(evidStr.substring(1, evidStr.length() - 1));
        } catch (ParseException e) {
            System.out.println("The bayou evidence should use such format: '" + "@key : value1, value2, ... '");
        }
    }

    protected void parseString(String input) throws ParseException {
	if (input.equals("")) {
	    throw new ParseException("Can not parse evidence");
	} 

	int start = input.indexOf("@");
	// System.out.println("start = " + start);
	if (start > 1) {
	    checkBlank(input.substring(0, start));
	}

	// Get type name
	String content = parseType(input.substring(start + 1, input.length()));
	while (content != null) 
	    content = parseValue(content);
    }

    // Parse the type name
    protected String parseType(String input) throws ParseException {
	// System.out.println("type: " + input);
	int stop = input.indexOf(":");
	int stop_ = input.indexOf(" ");
	// System.out.println("stop  = " + stop + " stop_ = " + stop_);
	if (stop == 0 || stop_ == 0)
	    throw new ParseException("Wrong type");

	if (stop > stop_) {
	    this.type = input.substring(0, stop_);
	} else 
	    this.type = input.substring(0, stop);

	return input.substring(stop + 1, input.length());
    }
    
    // Parse the values
    protected String parseValue(String input) throws ParseException {
	// Remove blank space
	if (input.length() == 0)
	    return null;

	while (input.indexOf(" ") == 0) {
	    if (input.length() == 1)
		return null;

	    input = input.substring(1, input.length());
	}

	int stop = input.indexOf(",");
	int stop_ = input.indexOf(" ");
	// System.out.println(input + " stop = " + stop + " stop_ = " + stop_); 
	if (stop < 0 && stop_ < 0) {
	    if (input.length() > 0) {
		addValue(input);
		return null;
	    } else
		throw new ParseException("Wrong value");
	}

	if (stop > stop_ && stop_ > 0) {
	    addValue(input.substring(0, stop_));
	    return input.substring(stop_ + 1, input.length());
	} else if (stop < 0 && stop_ > 0) {
            addValue(input.substring(0, stop_));
            return input.substring(stop_ + 1, input.length());
        } else if (stop > 0) {
            addValue(input.substring(0, stop));
	    return input.substring(stop + 1, input.length());
	}

	throw new ParseException("Wrong value");
    }

    protected void checkBlank(String blankString) throws ParseException {
	int idx = 0; 
	while (idx < blankString.length()) {
	    if (!blankString.substring(idx, idx + 1).equals(" "))
		throw new ParseException("Not blank space?");
	    idx += 1;
	}
    }

    protected void addValue(String value) {
	if (this.elements == null)
	    this.elements = new ArrayList<String>();

{'fraction_non_alphanumeric': 0.1479828964491541, 'fraction_numerical': 0.009853132552519055, 'mean_word_length': 3.0420736288504884, 'pattern_counts': {'":': 2, '<': 12, '<?xml version=': 0, '>': 18, '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': '3869112', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1630, 'n_words': 450}