<commit_before>package org.talkingpuffin.filter

import org.talkingpuffin.util.Loggable
import org.talkingpuffin.filter.RetweetDetector._
import twitter4j.Status

/**
 * Used to match a tweet against a set of TextFilters and retweet options.
 */
case class CompoundFilter(val textFilters: List[TextFilter], 
    val retweet: Option[Boolean], val commentedRetweet: Option[Boolean]) 
    extends Loggable {

  /**
   * Whether the specified tweet matches all the elements of this CompoundFilter.
   */
  def matches(status: Status): Boolean = {

    def allTextFiltersMatch = textFilters.forall(tf => {
      val text = tf.text
      val compareWith = tf.getCompareWith(status)
      
      if (tf.isRegEx)
        text.r.findFirstIn(compareWith).isDefined
      else
        compareWith.toUpperCase.contains(text.toUpperCase)
    })

    def retweetFilterMatches = booleanFilterMatches(retweet, status.isRetweet)

    def commentedRetweetFilterMatches = booleanFilterMatches(
        commentedRetweet, false) // todo status.isCommentedRetweet)

    def booleanFilterMatches(filter: Option[Boolean], value: Boolean) = filter match {
      case Some(f) => f == value
      case _ => true
    }

    allTextFiltersMatch && retweetFilterMatches && commentedRetweetFilterMatches
  }
  
  override def toString = List(textFilters.map(_.toString).mkString("⇅"), 
    retweet.toString, commentedRetweet.toString).mkString("↕")
}

object CompoundFilter {
  def muteRtSender(sender: String) = 
      CompoundFilter(List(FromTextFilter(sender, false)), Some(true), None)

  def muteCRtSender(sender: String) = 
      CompoundFilter(List(FromTextFilter(sender, false)), None, Some(true))
  
  def muteApp(app: String) = CompoundFilter(List(SourceTextFilter(app, false)), None, None)
  
  def muteSender(sender: String) = CompoundFilter(List(FromTextFilter(sender, false)), None, None)
}

<commit_msg>Uncomment call to status.isCommentedRetweet<commit_after>package org.talkingpuffin.filter

import org.talkingpuffin.util.Loggable
import org.talkingpuffin.filter.RetweetDetector._
import twitter4j.Status

/**
 * Used to match a tweet against a set of TextFilters and retweet options.
 */
case class CompoundFilter(textFilters: List[TextFilter],
    retweet: Option[Boolean], commentedRetweet: Option[Boolean])
    extends Loggable {

  /**
   * Whether the specified tweet matches all the elements of this CompoundFilter.
   */
  def matches(status: Status): Boolean = {

    def allTextFiltersMatch = textFilters.forall(tf => {
      val text = tf.text
      val compareWith = tf.getCompareWith(status)
      
      if (tf.isRegEx)
        text.r.findFirstIn(compareWith).isDefined
      else
        compareWith.toUpperCase.contains(text.toUpperCase)
    })

    def retweetFilterMatches = booleanFilterMatches(retweet, status.isRetweet)

    def commentedRetweetFilterMatches = booleanFilterMatches(
        commentedRetweet, status.isCommentedRetweet)

    def booleanFilterMatches(filter: Option[Boolean], value: Boolean) = filter match {
      case Some(f) => f == value
      case _ => true
    }

    allTextFiltersMatch && retweetFilterMatches && commentedRetweetFilterMatches
  }
  
  override def toString = List(textFilters.map(_.toString).mkString("⇅"), 
    retweet.toString, commentedRetweet.toString).mkString("↕")
}

object CompoundFilter {
  def muteRtSender(sender: String) = 
      CompoundFilter(List(FromTextFilter(sender, false)), Some(true), None)

  def muteCRtSender(sender: String) = 
      CompoundFilter(List(FromTextFilter(sender, false)), None, Some(true))
  
  def muteApp(app: String) = CompoundFilter(List(SourceTextFilter(app, false)), None, None)
  
  def muteSender(sender: String) = CompoundFilter(List(FromTextFilter(sender, false)), None, None)
}


{'fraction_non_alphanumeric': 0.10119205298013245, 'fraction_numerical': 0.0005298013245033113, 'mean_word_length': 4.193947730398899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1464060', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1122, 'n_words': 250}