<commit_before>module PropLogic
  class OrTerm < Term
    def initialize(*terms)
      @terms = terms.map{|t| t.is_a?(OrTerm) ? t.terms : t}.flatten
      @is_nnf = @terms.all?(&:nnf?) 
      @is_reduced = @terms.all? do |term|
        term.reduced? && ! term.is_a?(Constant)
      end
    end
    
    def to_s(in_term = false)
      str = @terms.map(&:to_s_in_term).join(' | ')
      in_term ? "( #{str} )" : str
    end
    
    def nnf?
      @is_nnf
    end
    
    def reduced?
      @is_reduced
    end
    
    def reduce
      return self if reduced?
      reduced_terms = @terms.map(&:reduce)
      reduced_terms.reject!{|term| term.equal?(False)}
      return False if reduced_terms.empty?
      if reduced_terms.any?{|term| term.equal?(True)}
        True
      elsif reduced_terms.length == 1
        reduced_terms[0]
      else
        Term.get self.class, *reduced_terms
      end
    end
    
    def to_cnf<commit_msg>obvious OrTerm can be reduced to True<commit_after>module PropLogic
  class OrTerm < Term
    def initialize(*terms)
      @terms = terms.map{|t| t.is_a?(OrTerm) ? t.terms : t}.flatten
      @is_nnf = @terms.all?(&:nnf?) 
      @is_reduced = @terms.all? do |term|
        term.reduced? && ! term.is_a?(Constant) && ! term.is_a?(NotTerm)
      end
    end
    
    def to_s(in_term = false)
      str = @terms.map(&:to_s_in_term).join(' | ')
      in_term ? "( #{str} )" : str
    end
    
    def nnf?
      @is_nnf
    end
    
    def reduced?
      @is_reduced
    end
    
    def reduce
      return self if reduced?
      reduced_terms = @terms.map(&:reduce)
      reduced_terms.reject!{|term| term.equal?(False)}
      return False if reduced_terms.empty?
      if reduced_terms.any?{|term| term.equal?(True)}
        True
      elsif reduced_terms.length == 1
        reduced_terms[0]
      else
        not_terms = reduced_terms.select{|term| term.is_a?(NotTerm)}
        negated_terms = not_terms.map{|term| term.terms[0]}
        return True unless (negated_terms & reduced_terms).empty?
        Term.get self.class, *reduced_terms
      end
    end
    
    def to_cnf
{'fraction_non_alphanumeric': 0.12429111531190926, 'fraction_numerical': 0.0023629489603024575, 'mean_word_length': 2.1882530120481927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '781907', 'n_tokens_mistral': 786, 'n_tokens_neox': 738, 'n_words': 155}