我正在尝试在我的 Scala NLP(自然语言处理)应用程序中挑选一些结构相对简单但创建速度较慢的类。因为有很多数据,所以需要pickle和esp。快速解开,不会膨胀。Java 序列化在这方面显然很糟糕。我知道 Kryo,但我从未使用过它。我也遇到过 Apache Avro,它看起来很相似,但我不太确定为什么它通常不被称为合适的解决方案。也不是 Scala 特定的,我看到有一个名为 Scala Pickling 的特定于 Scala 的包。不幸的是,它几乎没有所有文档,我不确定如何创建自定义pickler。
我在这里看到一个问题:
Scala Pickling:为嵌套结构编写自定义pickler / unpickler
这个问题仍然缺少一些上下文,而且与为 Kryo 或 Avro 给出的示例相比,创建自定义pickler 的样板文件看起来非常多。
这是我需要序列化的一些类:
trait ToIntMemoizer[T] {
protected val minimum_raw_index: Int = 1
protected var next_raw_index: Int = minimum_raw_index
// For replacing items with ints. This is a wrapper around
// gnu.trove.map.TObjectIntMap to make it look like mutable.Map[T, Int].
// It behaves the same way.
protected val value_id_map = trovescala.ObjectIntMap[T]()
// Map in the opposite direction. This is a wrapper around
// gnu.trove.map.TIntObjectMap to make it look like mutable.Map[Int, T].
// It behaves the same way.
protected val id_value_map = trovescala.IntObjectMap[T]()
...
}
class FeatureMapper extends ToIntMemoizer[String] {
val features_to_standardize = mutable.BitSet()
...
}
class LabelMapper extends ToIntMemoizer[String] {
}
case class FeatureLabelMapper(
feature_mapper: FeatureMapper = new FeatureMapper,
label_mapper: LabelMapper = new LabelMapper
)
class DoubleCompressedSparseFeatureVector(
var keys: Array[Int], var values: Array[Double],
val mappers: FeatureLabelMapper
) { ... }
我将如何以使用尽可能少的样板的方式创建自定义选择器/取消选择器(因为我有许多其他需要类似处理的类)?
谢谢!