<commit_before>package concrete.generator.cspompatterns

import cspom.CSPOMConstraint
import cspom.compiler.VariableCompiler
import cspom.variable.CSPOMConstant
import cspom.variable.CSPOMExpression
import cspom.variable.CSPOMSeq
import cspom.variable.SimpleExpression
import cspom.util.IntInterval
import cspom.variable.IntExpression


/**
 * @author vion
 */
object OccurrenceDomains extends VariableCompiler('occurrence) {
  def compiler(c: CSPOMConstraint[_]): Map[CSPOMExpression[_], CSPOMExpression[_]] = {
    val CSPOMConstraint(r, _, Seq(const @ CSPOMConstant(value), CSPOMSeq(args)), _) = c
    val ir = IntExpression.coerce(r)
    val lb = args.count(_ == const)
    val ub = args.count {
      case s: SimpleExpression[_] => s.contains(value)
      case _ => throw new IllegalArgumentException("Occurrence constraint only supports SimpleExpressions")
    }

    Map(r -> reduceDomain(ir, IntInterval(lb, ub)))
  }<commit_msg>OccurrenceDomains simplified<commit_after>package concrete.generator.cspompatterns

import cspom.CSPOMConstraint
import cspom.compiler.VariableCompiler
import cspom.variable.CSPOMConstant
import cspom.variable.CSPOMExpression
import cspom.variable.CSPOMSeq
import cspom.variable.SimpleExpression
import cspom.util.IntInterval
import cspom.variable.IntExpression

/**
 * @author vion
 */
object OccurrenceDomains extends VariableCompiler('occurrence) {
  def compiler(c: CSPOMConstraint[_]): Map[CSPOMExpression[_], CSPOMExpression[_]] = {
    val CSPOMConstraint(r, _, Seq(_, CSPOMSeq(args)), _) = c
    val ir = IntExpression.coerce(r)

    Map(r -> reduceDomain(ir, IntInterval(0, args.size)))
  }
{'fraction_non_alphanumeric': 0.10513447432762836, 'fraction_numerical': 0.0006112469437652812, 'mean_word_length': 5.600806451612903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3317536', 'n_tokens_mistral': 528, 'n_tokens_neox': 514, 'n_words': 103}