io.radicalbit.flink.pmml.scala.models.prediction.Target.scala Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2017 Radicalbit
*
* This file is part of flink-JPMML
*
* flink-JPMML is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* flink-JPMML is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with flink-JPMML. If not, see .
*/
package io.radicalbit.flink.pmml.scala.models.prediction
/** Represents the result output value; if the target is present has [[Score]] value,
* [[EmptyScore]] otherwise.
*/
object Target {
/** Factory method
*
* @param v
* @return
*/
def apply(v: Double): Target = Score(v)
/** Returns an empty instance of [[Target]]
*
* @return
*/
def empty = EmptyScore
}
/** ADT sealed trait providing getters for values.
*
*/
sealed trait Target extends Serializable {
/** Returns [[Score]]] if target has value, default value otherwise
*
* @param default the user defined default value
* @return
*/
final def getOrElse(default: => Double): Double =
this match {
case Score(v) => v
case EmptyScore => default
}
def get: Double
}
/** Represents the Target value if it is present
*
* @param value the prediction value as [[scala.Double]]
*/
final case class Score(value: Double) extends Target {
/** Returns the [[Score]] value
*
* @return
*/
def get: Double = value
}
/** Represents the Target value if it is not present
*
*/
case object EmptyScore extends Target {
/** Implements get method when the [[Score]] is empty
*
* @return
* @throws scala.NoSuchElementException for `EmptyScore` instance.
*/
def get: Double = throw new NoSuchElementException("EmptyScore.nan")
}