Skip to content

Instantly share code, notes, and snippets.

@andrewclegg
Created July 4, 2016 11:39
Show Gist options
  • Save andrewclegg/5cac106a8352d49b7c69571db6973ebb to your computer and use it in GitHub Desktop.
Save andrewclegg/5cac106a8352d49b7c69571db6973ebb to your computer and use it in GitHub Desktop.
case class InputIterator(file: File) extends Iterable[LabelledDocument] {
val lines = Source.fromFile(file).getLines()
override def iterator: Iterator[LabelledDocument] = {
lines.map {
line =>
val fields = line.split("\t")
val label = fields(0)
val text = fields(2) // Ignore 1 as this is just the active/inactive flag
val doc = new LabelledDocument()
doc.setLabel(label)
doc.setContent(text)
doc
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment