the-algorithm/home-mixer/server/src/main/scala/com/twitter/home_mixer/model/ContentFeatures.scala

145 lines
4.5 KiB
Scala

package com.twitter.home_mixer.model
import com.twitter.escherbird.{thriftscala => esb}
import com.twitter.search.common.features.{thriftscala => sc}
import com.twitter.tweetypie.{thriftscala => tp}
object ContentFeatures {
val Empty: ContentFeatures = ContentFeatures(
0.toShort,
false,
0.toShort,
0.toShort,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None
)
def fromThrift(ebFeatures: sc.ThriftTweetFeatures): ContentFeatures =
ContentFeatures(
length = ebFeatures.tweetLength.getOrElse(0).toShort,
hasQuestion = ebFeatures.hasQuestion.getOrElse(false),
numCaps = ebFeatures.numCaps.getOrElse(0).toShort,
numWhiteSpaces = ebFeatures.numWhitespaces.getOrElse(0).toShort,
numNewlines = ebFeatures.numNewlines,
videoDurationMs = ebFeatures.videoDurationMs,
bitRate = ebFeatures.bitRate,
aspectRatioNum = ebFeatures.aspectRatioNum,
aspectRatioDen = ebFeatures.aspectRatioDen,
widths = ebFeatures.widths.map(_.map(_.toShort)),
heights = ebFeatures.heights.map(_.map(_.toShort)),
resizeMethods = ebFeatures.resizeMethods.map(_.map(_.toShort)),
numMediaTags = ebFeatures.numMediaTags.map(_.toShort),
mediaTagScreenNames = ebFeatures.mediaTagScreenNames,
emojiTokens = ebFeatures.emojiTokens.map(_.toSet),
emoticonTokens = ebFeatures.emoticonTokens.map(_.toSet),
faceAreas = ebFeatures.faceAreas,
dominantColorRed = ebFeatures.dominantColorRed,
dominantColorBlue = ebFeatures.dominantColorBlue,
dominantColorGreen = ebFeatures.dominantColorGreen,
numColors = ebFeatures.numColors.map(_.toShort),
stickerIds = ebFeatures.stickerIds,
mediaOriginProviders = ebFeatures.mediaOriginProviders,
isManaged = ebFeatures.isManaged,
is360 = ebFeatures.is360,
viewCount = ebFeatures.viewCount,
isMonetizable = ebFeatures.isMonetizable,
isEmbeddable = ebFeatures.isEmbeddable,
hasSelectedPreviewImage = ebFeatures.hasSelectedPreviewImage,
hasTitle = ebFeatures.hasTitle,
hasDescription = ebFeatures.hasDescription,
hasVisitSiteCallToAction = ebFeatures.hasVisitSiteCallToAction,
hasAppInstallCallToAction = ebFeatures.hasAppInstallCallToAction,
hasWatchNowCallToAction = ebFeatures.hasWatchNowCallToAction,
dominantColorPercentage = ebFeatures.dominantColorPercentage,
posUnigrams = ebFeatures.posUnigrams.map(_.toSet),
posBigrams = ebFeatures.posBigrams.map(_.toSet),
semanticCoreAnnotations = ebFeatures.semanticCoreAnnotations,
tokens = ebFeatures.textTokens.map(_.toSeq),
conversationControl = ebFeatures.conversationControl,
// media and selfThreadMetadata not carried by ThriftTweetFeatures
media = None,
selfThreadMetadata = None
)
}
case class ContentFeatures(
length: Short,
hasQuestion: Boolean,
numCaps: Short,
numWhiteSpaces: Short,
numNewlines: Option[Short],
videoDurationMs: Option[Int],
bitRate: Option[Int],
aspectRatioNum: Option[Short],
aspectRatioDen: Option[Short],
widths: Option[Seq[Short]],
heights: Option[Seq[Short]],
resizeMethods: Option[Seq[Short]],
numMediaTags: Option[Short],
mediaTagScreenNames: Option[Seq[String]],
emojiTokens: Option[Set[String]],
emoticonTokens: Option[Set[String]],
faceAreas: Option[Seq[Int]],
dominantColorRed: Option[Short],
dominantColorBlue: Option[Short],
dominantColorGreen: Option[Short],
numColors: Option[Short],
stickerIds: Option[Seq[Long]],
mediaOriginProviders: Option[Seq[String]],
isManaged: Option[Boolean],
is360: Option[Boolean],
viewCount: Option[Long],
isMonetizable: Option[Boolean],
isEmbeddable: Option[Boolean],
hasSelectedPreviewImage: Option[Boolean],
hasTitle: Option[Boolean],
hasDescription: Option[Boolean],
hasVisitSiteCallToAction: Option[Boolean],
hasAppInstallCallToAction: Option[Boolean],
hasWatchNowCallToAction: Option[Boolean],
media: Option[Seq[tp.MediaEntity]],
dominantColorPercentage: Option[Double],
posUnigrams: Option[Set[String]],
posBigrams: Option[Set[String]],
semanticCoreAnnotations: Option[Seq[esb.TweetEntityAnnotation]],
selfThreadMetadata: Option[tp.SelfThreadMetadata],
tokens: Option[Seq[String]],
conversationControl: Option[tp.ConversationControl],
)