Choose nlp mode in config file

This commit is contained in:
Eike Kettner
2021-01-14 00:55:19 +01:00
parent 54a09861c4
commit aa937797be
6 changed files with 95 additions and 19 deletions

View File

@ -0,0 +1,23 @@
package docspell.common
sealed trait NlpMode { self: Product =>
def name: String =
self.productPrefix
}
object NlpMode {
case object Full extends NlpMode
case object Basic extends NlpMode
case object Disabled extends NlpMode
def fromString(name: String): Either[String, NlpMode] =
name.toLowerCase match {
case "full" => Right(Full)
case "basic" => Right(Basic)
case "disabled" => Right(Disabled)
case _ => Left(s"Unknown nlp-mode: $name")
}
def unsafeFromString(name: String): NlpMode =
fromString(name).fold(sys.error, identity)
}

View File

@ -44,6 +44,9 @@ object Implicits {
implicit val priorityReader: ConfigReader[Priority] =
ConfigReader[String].emap(reason(Priority.fromString))
implicit val nlpModeReader: ConfigReader[NlpMode] =
ConfigReader[String].emap(reason(NlpMode.fromString))
def reason[A: ClassTag](
f: String => Either[String, A]
): String => Either[FailureReason, A] =