mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-15 07:38:45 +02:00
ef4c5eb65e
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
37 lines
1.3 KiB
Scala
37 lines
1.3 KiB
Scala
package com.twitter.product_mixer.component_library.filter
|
|
import com.twitter.product_mixer.component_library.feature_hydrator.candidate.tweet_tweetypie.IsReplyFeature
|
|
import com.twitter.product_mixer.component_library.model.candidate.BaseTweetCandidate
|
|
import com.twitter.product_mixer.core.functional_component.filter.Filter
|
|
import com.twitter.product_mixer.core.functional_component.filter.FilterResult
|
|
import com.twitter.product_mixer.core.model.common.CandidateWithFeatures
|
|
import com.twitter.product_mixer.core.model.common.identifier.FilterIdentifier
|
|
import com.twitter.product_mixer.core.pipeline.PipelineQuery
|
|
import com.twitter.stitch.Stitch
|
|
|
|
/**
|
|
* Filters out tweets that is a reply to a tweet
|
|
*/
|
|
case class TweetIsNotReplyFilter[Candidate <: BaseTweetCandidate]()
|
|
extends Filter[PipelineQuery, Candidate] {
|
|
override val identifier: FilterIdentifier = FilterIdentifier("TweetIsNotReply")
|
|
|
|
override def apply(
|
|
query: PipelineQuery,
|
|
candidates: Seq[CandidateWithFeatures[Candidate]]
|
|
): Stitch[FilterResult[Candidate]] = {
|
|
|
|
val (kept, removed) = candidates
|
|
.partition { candidate =>
|
|
!candidate.features.get(IsReplyFeature)
|
|
}
|
|
|
|
val filterResult = FilterResult(
|
|
kept = kept.map(_.candidate),
|
|
removed = removed.map(_.candidate)
|
|
)
|
|
|
|
Stitch.value(filterResult)
|
|
}
|
|
|
|
}
|