Skip to content

Instantly share code, notes, and snippets.

@duanebester
Last active February 12, 2020 04:08
Show Gist options
  • Save duanebester/7c0b40fc3b412a157bcd9d5b10605f62 to your computer and use it in GitHub Desktop.
Save duanebester/7c0b40fc3b412a157bcd9d5b10605f62 to your computer and use it in GitHub Desktop.
Spell Check Method
def spellCheck = Flow[String].map(ocr => {
import scala.collection.JavaConverters._
val words: Set[String] = ocr.replaceAll("-\n", "")
.replaceAll("\n", " ")
.replaceAll("-"," ")
.split("\\s+")
.map(_.replaceAll(
"[^a-zA-Z'’\\d\\s]", "") // Remove most punctuation
.trim)
.filter(!_.isEmpty).toSet
println(words)
val misspelled = words.filter(word => !speller.isCorrect(word))
val suggestions: Set[Map[String, List[String]]] = misspelled.map(mis => {
Map(mis -> speller.suggest(mis).asScala.toList)
})
OcrSuggestions(ocr, suggestions)
})
// Update OCR Flow
val ocrFlow = imageOcr.via(spellCheck)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment