Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Forked from zeryx/input_trait.scala
Last active January 5, 2017 22:28
Show Gist options
  • Save Jacoby6000/c6a87477237fdd37ee3dc5acf7778031 to your computer and use it in GitHub Desktop.
Save Jacoby6000/c6a87477237fdd37ee3dc5acf7778031 to your computer and use it in GitHub Desktop.
package algorithmia.TechSupport
import algorithmia.TechSupport.Classes.DataPoint
import argonaut.Argonaut._
import argonaut.CodecJson
/**
* Created by james on 05/01/17.
*/
sealed trait Input
object Input {
implicit def inputCodec =
CodecJson[Input](
encoder = {
case train: Train => Train.trainCodec.encode(train)
case predict: Predict => Predict.predictCodec.encode(predict)
},
decoder = json => Predict.predictCodec.decode(json) ||| Train.trainCodec.decode(json)
)
}
case class Train(labelData: Option[List[DataPoint]], labelFile: Option[String], namespace: Option[String]) extends Input
case class Predict(text: String, namespace: Option[String]) extends Input
object Train {
implicit def trainCodec: CodecJson[Train] =
casecodec3(Train.apply, Train.unapply)(
"labelData",
"labelFile",
"namespace"
)
}
object Predict{
implicit def predictCodec: CodecJson[Predict] =
casecodec2(Predict.apply, Predict.unapply)(
"text",
"namespace"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment