Last active
August 13, 2020 08:41
-
-
Save mostafam/33d493362ea5b6c705ce5f8348f9f58a to your computer and use it in GitHub Desktop.
StringCheckerOp.scala (MLeap side)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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