the-algorithm/timelineranker/server/src/main/scala/com/twitter/timelineranker/common/FeatureHydrationDataTransform.scala
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
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.
2023-03-31 17:36:31 -05:00

34 lines
1.4 KiB
Scala

package com.twitter.timelineranker.common
import com.twitter.servo.util.FutureArrow
import com.twitter.timelineranker.core.CandidateEnvelope
import com.twitter.timelineranker.core.HydratedCandidatesAndFeaturesEnvelope
import com.twitter.timelineranker.model.RecapQuery
import com.twitter.util.Future
/**
* Fetches all data required for feature hydration and generates the HydratedCandidatesAndFeaturesEnvelope
* @param tweetHydrationAndFilteringPipeline Pipeline which fetches the candidate tweets, hydrates and filters them
* @param languagesService Fetch user languages, required for feature hydration
* @param userProfileInfoService Fetch user profile info, required for feature hydration
*/
class FeatureHydrationDataTransform(
tweetHydrationAndFilteringPipeline: FutureArrow[RecapQuery, CandidateEnvelope],
languagesService: UserLanguagesTransform,
userProfileInfoService: UserProfileInfoTransform)
extends FutureArrow[RecapQuery, HydratedCandidatesAndFeaturesEnvelope] {
override def apply(request: RecapQuery): Future[HydratedCandidatesAndFeaturesEnvelope] = {
Future
.join(
languagesService(request),
userProfileInfoService(request),
tweetHydrationAndFilteringPipeline(request)).map {
case (languages, userProfileInfo, transformedCandidateEnvelope) =>
HydratedCandidatesAndFeaturesEnvelope(
transformedCandidateEnvelope,
languages,
userProfileInfo)
}
}
}