Skip to content

Instantly share code, notes, and snippets.

@zeryx
Created May 2, 2018 21:00
Show Gist options
  • Save zeryx/3d511e54fa3b25c7b33d6182c406964f to your computer and use it in GitHub Desktop.
Save zeryx/3d511e54fa3b25c7b33d6182c406964f to your computer and use it in GitHub Desktop.
val result: Stream[Task, Prediction] = specimenStream.flatMap((spec: Document) =>{
modelStream.fold(ListBuffer.empty[TopN]) { case (topNVec, mod) =>
val res = calcDistance(spec, mod)
topNVec += TopN(res.modelElm.label.get, res.distance)
topNVec.sortBy(res => res.confidence).take(nearest)
}.map(topNVec => Prediction(spec.text, topNVec.toList) )
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment