mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-03-31 13:45:09 +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,8 +37,10 @@ final class StanfordTextClassifier[F[_]: Sync: ContextShift](
|
|||||||
def classify(
|
def classify(
|
||||||
logger: Logger[F],
|
logger: Logger[F],
|
||||||
model: ClassifierModel,
|
model: ClassifierModel,
|
||||||
text: String
|
txt: String
|
||||||
): F[Option[String]] =
|
): F[Option[String]] =
|
||||||
|
Option(txt).map(_.trim).filter(_.nonEmpty) match {
|
||||||
|
case Some(text) =>
|
||||||
Sync[F].delay {
|
Sync[F].delay {
|
||||||
val cls = ColumnDataClassifier.getClassifier(
|
val cls = ColumnDataClassifier.getClassifier(
|
||||||
model.model.normalize().toAbsolutePath().toString()
|
model.model.normalize().toAbsolutePath().toString()
|
||||||
@ -46,6 +48,9 @@ final class StanfordTextClassifier[F[_]: Sync: ContextShift](
|
|||||||
val cat = cls.classOf(cls.makeDatumFromLine("\t\t" + normalisedText(text)))
|
val cat = cls.classOf(cls.makeDatumFromLine("\t\t" + normalisedText(text)))
|
||||||
Option(cat)
|
Option(cat)
|
||||||
}
|
}
|
||||||
|
case None =>
|
||||||
|
(None: Option[String]).pure[F]
|
||||||
|
}
|
||||||
|
|
||||||
// --- helpers
|
// --- helpers
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user