the-algorithm/timelineranker/common/src/main/scala/com/twitter/timelineranker/model/LanguageScope.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

47 lines
1.3 KiB
Scala

package com.twitter.timelineranker.model
import com.twitter.timelineranker.{thriftscala => thrift}
/**
* Represents what this language is associated with.
* For example, "user" is one of the scopes and "event"
* could be another scope.
*/
object LanguageScope extends Enumeration {
// User scope means that the language is the user's language.
val User: Value = Value(thrift.LanguageScope.User.value)
// Event scope means that the language is the event's language.
val Event: Value = Value(thrift.LanguageScope.Event.value)
// list of all LanguageScope values
val All: ValueSet = LanguageScope.ValueSet(User, Event)
def apply(scope: thrift.LanguageScope): LanguageScope.Value = {
scope match {
case thrift.LanguageScope.User =>
User
case thrift.LanguageScope.Event =>
Event
case _ =>
throw new IllegalArgumentException(s"Unsupported language scope: $scope")
}
}
def fromThrift(scope: thrift.LanguageScope): LanguageScope.Value = {
apply(scope)
}
def toThrift(scope: LanguageScope.Value): thrift.LanguageScope = {
scope match {
case LanguageScope.User =>
thrift.LanguageScope.User
case LanguageScope.Event =>
thrift.LanguageScope.Event
case _ =>
throw new IllegalArgumentException(s"Unsupported language scope: $scope")
}
}
}