<commit_before>package xyz.javecs.tools.text2expr

import xyz.javecs.tools.expr.Calculator
import xyz.javecs.tools.text2expr.parsers.RuleBuilder
import xyz.javecs.tools.text2expr.utils.normalize
import xyz.javecs.tools.text2expr.utils.read
import xyz.javecs.tools.text2expr.utils.resources

class Text2Expr(rulePath: String = "rules") {
    private val rules = ArrayList<RuleBuilder>()
    private val calc = Calculator()

    init {
        resources(rulePath).forEach{ rules.add(RuleBuilder(read(it))) }
    }

    fun eval(text: String): String {
        for (rule in rules) {
            try {
                val evaluation = rule.eval(text)
                if (evaluation.value != Double.NaN) {
                    return evaluation.value.toString()
                }
            } catch (e: Exception) {
            }
        }
        return calc.eval(normalize(text)).value.toString()
    }
}<commit_msg>forEachに変えました。<commit_after>package xyz.javecs.tools.text2expr

import xyz.javecs.tools.expr.Calculator
import xyz.javecs.tools.text2expr.parsers.RuleBuilder
import xyz.javecs.tools.text2expr.utils.normalize
import xyz.javecs.tools.text2expr.utils.read
import xyz.javecs.tools.text2expr.utils.resources

class Text2Expr(rulePath: String = "rules") {
    private val rules = ArrayList<RuleBuilder>()
    private val calc = Calculator()

    init {
        resources(rulePath).forEach { rules.add(RuleBuilder(read(it))) }
    }

    fun eval(text: String): String {
        rules.forEach {
            try {
                val evaluation = it.eval(text)
                if (evaluation.value != Double.NaN) return evaluation.value.toString()
            } catch (e: Exception) {
            }
        }
        return calc.eval(normalize(text)).value.toString()
    }
}
{'fraction_non_alphanumeric': 0.11348314606741573, 'fraction_numerical': 0.006741573033707865, 'mean_word_length': 2.562, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7586270', 'n_tokens_mistral': 573, 'n_tokens_neox': 543, 'n_words': 95}