Created
September 5, 2016 13:38
-
-
Save chobeat/f07221357a2e3f9efa377e4cb0479f92 to your computer and use it in GitHub Desktop.
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
class JPMMLEvaluationMapOperator(pmmlSource: String, | |
inputPreparationErrorHandlingStrategy: InputPreparationErrorHandlingStrategy, | |
missingValueStrategy: MissingValueStrategy, | |
resultExtractionStrategy: ResultExtractionStrategy) | |
extends RichMapFunction[Map[String, Any], Map[String, Serializable]] { | |
//The evaluator is transient and built in the open() function to allow proper serializability of the operator. | |
@transient | |
private var evaluator: Evaluator = null | |
override def open(params: Configuration) = { | |
super.open(params) | |
evaluator = ModelEvaluatorFactory.newInstance() | |
.newModelManager( | |
JAXBUtil.unmarshalPMML( | |
new StreamSource( | |
new StringReader(pmmlSource)))) | |
} | |
override def map(input: Map[String, Any]) = { | |
val preparedInput = prepareInput(input, evaluator, missingValueStrategy, inputPreparationErrorHandlingStrategy) | |
val evaluationResult = evaluate(preparedInput, evaluator) | |
val result = resultExtractionStrategy(evaluationResult, evaluator) | |
result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment