mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-25 16:45:05 +00:00
Fix potential index-out-of-bounds error in classifier
The stanford library expects a non-empty text.
This commit is contained in:
parent
709848244c
commit
cf6e63785d
@ -37,14 +37,19 @@ final class StanfordTextClassifier[F[_]: Sync: ContextShift](
|
||||
def classify(
|
||||
logger: Logger[F],
|
||||
model: ClassifierModel,
|
||||
text: String
|
||||
txt: String
|
||||
): F[Option[String]] =
|
||||
Sync[F].delay {
|
||||
val cls = ColumnDataClassifier.getClassifier(
|
||||
model.model.normalize().toAbsolutePath().toString()
|
||||
)
|
||||
val cat = cls.classOf(cls.makeDatumFromLine("\t\t" + normalisedText(text)))
|
||||
Option(cat)
|
||||
Option(txt).map(_.trim).filter(_.nonEmpty) match {
|
||||
case Some(text) =>
|
||||
Sync[F].delay {
|
||||
val cls = ColumnDataClassifier.getClassifier(
|
||||
model.model.normalize().toAbsolutePath().toString()
|
||||
)
|
||||
val cat = cls.classOf(cls.makeDatumFromLine("\t\t" + normalisedText(text)))
|
||||
Option(cat)
|
||||
}
|
||||
case None =>
|
||||
(None: Option[String]).pure[F]
|
||||
}
|
||||
|
||||
// --- helpers
|
||||
|
Loading…
x
Reference in New Issue
Block a user