<commit_before>public typealias BindingMap = Dictionary<String, Term>

extension Dictionary where Key == String, Value == Term {

  func reified() -> [String: Term] {
    var result: [String: Term] = [:]
    for (name, term) in self {
      result[name] = deepWalk(term)
    }
    return result
  }

  func shallowWalk(_ term: Term) -> Term {
    switch term {
    case .var(let name):
      return self[name].map({
        shallowWalk($0)
      }) ?? term
    default:
      return term
    }
  }

  func deepWalk(_ term: Term) -> Term {
    let walked = shallowWalk(term)
    switch walked {
    case ._term(name: let name, arguments: let arguments):
      return ._term(name: name, arguments: arguments.map(deepWalk))
    case .conjunction(let lhs, let rhs):
      return .conjunction(deepWalk(lhs), deepWalk(rhs))
    case .disjunction(let lhs, let rhs):
      return .disjunction(deepWalk(lhs), deepWalk(rhs))
    default:
      return walked
    }
  }

  func binding(_ name: String, to term: Term) -> Dictionary {
    var result = self
    result[name] = term
    return result
  }

  func merged(with other: Dictionary) -> Dictionary {
    var result = self
    for (name, term) in other {
      result[name] = term
    }
    return result
  }

  public subscript(name: Term) -> Term? {
    guard case let .var(val) = name else { fatalError() }
    return self[val]
  }

}<commit_msg>Minor refactoring<commit_after>public typealias BindingMap = Dictionary<String, Term>

extension Dictionary where Key == String, Value == Term {

  func reified() -> [String: Term] {
    var result: [String: Term] = [:]
    for (name, term) in self {
      result[name] = deepWalk(term)
    }
    return result
  }

  func shallowWalk(_ term: Term) -> Term {
    switch term {
    case .var(let name):
      return self[name].map({
        shallowWalk($0)
      }) ?? term
    default:
      return term
    }
  }

  func deepWalk(_ term: Term) -> Term {
    let walked = shallowWalk(term)
    switch walked {
    case ._term(name: let name, arguments: let arguments):
      return ._term(name: name, arguments: arguments.map(deepWalk))
    case .conjunction(let lhs, let rhs):
      return .conjunction(deepWalk(lhs), deepWalk(rhs))
    case .disjunction(let lhs, let rhs):
      return .disjunction(deepWalk(lhs), deepWalk(rhs))
    default:
      return walked
    }
  }

  func binding(_ name: String, to term: Term) -> BindingMap {
    var result = self
    result[name] = term
    return result
  }

  func merged(with other: BindingMap) -> BindingMap {
    var result = self
    for (name, term) in other {
      result[name] = term
    }
    return result
  }

  public subscript(name: Term) -> Term? {
    guard case let .var(val) = name else { fatalError() }
    return self[val]
  }

}
{'fraction_non_alphanumeric': 0.1212338593974175, 'fraction_numerical': 0.0007173601147776184, 'mean_word_length': 2.650523560209424, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5695360', 'n_tokens_mistral': 891, 'n_tokens_neox': 868, 'n_words': 265}