<commit_before>package beast.shell;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

import beast.core.BEASTObject;
import beast.core.Description;
import beast.core.Function;
import beast.core.Input;
import beast.core.Loggable;
import bsh.EvalError;
import bsh.Interpreter;

@Description("Logger specified using BEASTScript "+
		"init(out), log(sample, out), close(out) must be specified. ")
public class BSHLogger extends BEASTObject implements Loggable {
	public Input<List<Function>> functionInputs = new Input<List<Function>>("x", "function values used by the distirbution", new ArrayList<Function>()); 
	public Input<String> valueInput = new Input<String>("value", "script specifying the various functions required for a distirbution"); 

	Interpreter interpreter;

	@Override
	public void initAndValidate() {
		interpreter = new Interpreter();
		NamedFunction.evalFunctionInputs(interpreter, functionInputs.get());
		String script = valueInput.get();
		try {
			interpreter.eval(script);
		} catch (EvalError e) {
			throw new RuntimeException(e);
		}
	}
	
	@Override
	public void init(PrintStream out) throws Exception {
		NamedFunction.evalVoidFunction(interpreter, functionInputs.get(), "init", out);

	}

	@Override
	public void log(int nSample, PrintStream out) {
		NamedFunction.evalVoidFunction(interpreter, functionInputs.get(), "log", nSample, out);
	}

	@Override
	public void close(PrintStream out) {
		NamedFunction.evalVoidFunction(interpreter, functionInputs.get(), "close", out);
	}

}<commit_msg>sync with beast2 exception overhaul<commit_after>package beast.shell;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

import beast.core.BEASTObject;
import beast.core.Description;
import beast.core.Function;
import beast.core.Input;
import beast.core.Loggable;
import bsh.EvalError;
import bsh.Interpreter;

@Description("Logger specified using BEASTScript "+
		"init(out), log(sample, out), close(out) must be specified. ")
public class BSHLogger extends BEASTObject implements Loggable {
	public Input<List<Function>> functionInputs = new Input<List<Function>>("x", "function values used by the distirbution", new ArrayList<Function>()); 
	public Input<String> valueInput = new Input<String>("value", "script specifying the various functions required for a distirbution"); 

	Interpreter interpreter;

	@Override
	public void initAndValidate() {
		interpreter = new Interpreter();
		NamedFunction.evalFunctionInputs(interpreter, functionInputs.get());
		String script = valueInput.get();
		try {
			interpreter.eval(script);
		} catch (EvalError e) {
			throw new RuntimeException(e);
		}
	}
	
	@Override
	public void init(PrintStream out) {
		NamedFunction.evalVoidFunction(interpreter, functionInputs.get(), "init", out);

	}

	@Override
	public void log(int nSample, PrintStream out) {
		NamedFunction.evalVoidFunction(interpreter, functionInputs.get(), "log", nSample, out);
	}

	@Override
	public void close(PrintStream out) {
		NamedFunction.evalVoidFunction(interpreter, functionInputs.get(), "close", out);
	}

}
{'fraction_non_alphanumeric': 0.11400966183574879, 'fraction_numerical': 0.00032206119162640903, 'mean_word_length': 5.886917960088692, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4308283', 'n_tokens_mistral': 944, 'n_tokens_neox': 930, 'n_words': 244}