Skip to content

Instantly share code, notes, and snippets.

@mostafam
Last active August 13, 2020 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafam/33d493362ea5b6c705ce5f8348f9f58a to your computer and use it in GitHub Desktop.
Save mostafam/33d493362ea5b6c705ce5f8348f9f58a to your computer and use it in GitHub Desktop.
StringCheckerOp.scala (MLeap side)
package ml.combust.mleap.bundle.ops.feature
import ml.combust.bundle.BundleContext
import ml.combust.bundle.dsl._
import ml.combust.bundle.op.OpModel
import ml.combust.mleap.bundle.ops.MleapOp
import ml.combust.mleap.core.feature.StringCheckerModel
import ml.combust.mleap.runtime.MleapContext
import ml.combust.mleap.runtime.transformer.feature.StringChecker
/**
* Created by mostafam on 6/19/20.
*/
class StringCheckerOp extends MleapOp[StringChecker, StringCheckerModel] {
override val Model: OpModel[MleapContext, StringCheckerModel] = new OpModel[MleapContext, StringCheckerModel] {
// the class of the model is needed for when we go to serialize JVM objects
override val klazz: Class[StringCheckerModel] = classOf[StringCheckerModel]
// a unique name for our op: "string_checker"
override def opName: String = Bundle.BuiltinOps.feature.string_checker
override def store(model: Model, obj: StringCheckerModel)
(implicit context: BundleContext[MleapContext]): Model = {
// add the caseSensitive parameter to the Bundle model that
// will be serialized to our MLeap bundle
model.withValue("caseSensitive", Value.boolean(obj.caseSensitive))
}
override def load(model: Model)
(implicit context: BundleContext[MleapContext]): StringCheckerModel = {
// retrieve our parameters
val caseSensitive = model.value("caseSensitive").getBoolean
// reconstruct the model using the parameters
StringCheckerModel(caseSensitive)
}
}
// the core model that is used by the transformer
override def model(node: StringChecker): StringCheckerModel = node.model
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment