直接附上我的示例代码:
package com.mobvoi.app.recommendation.data
import java.io.InputStream
import scala.io.Source.fromInputStream
trait AppNameData extends Serializable {
@transient private val stream: InputStream = getClass.getResourceAsStream("/app_name.txt")
private val appIdName = fromInputStream(stream).getLines.toArray
/** Param for app id and app name map. */
private[recommendation] val appIdNameMap = appIdName.map { x =>
val str = x.split(" ")
(str(0).trim, str(1).trim)
}.toMap
/** Param for app name and app id map. */
private[recommendation] val appNameIdMap = appIdName.map { x =>
val str = x.split(" ")
(str(1).trim, str(0).trim)
}.toMap
}
没有评论:
发表评论