in cassovary-core/src/main/scala/com/twitter/cassovary/util/io/LabelsReader.scala [30:62]
def readOneLabel[L : ClassTag: TypeTag](labelName: String, fileName: String,
isSparse: Option[Boolean] = None, maxId: Option[Int] = None): Label[Int, L] = {
val tag = implicitly[TypeTag[L]]
if (tag != intType && tag != stringType) {
throw new Exception("Only Int and String label values are supported right now!")
}
val label = (isSparse, maxId) match {
case (Some(false), Some(m)) => new ArrayBasedLabel[L](labelName, m)
case _ => new IntLabel[L](labelName, maxId)
}
var lastLineParsed = 0
val source = Source.fromFile(fileName)
source.getLines().foreach { line =>
lastLineParsed += 1
try {
val i = line.indexOf(separator)
val id = ParseString.toInt(line, 0, i - 1)
val labelValue = if (tag == intType) {
ParseString.toInt(line, i + 1, line.length - 1)
} else if (tag == stringType) {
line.substring(i + 1, line.length)
}
label.update(id, labelValue.asInstanceOf[L])
} catch {
case NonFatal(exc) =>
throw new IOException("Parsing failed near line: %d in %s"
.format(lastLineParsed, fileName), exc)
}
}
source.close()
label
}