mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Choose nlp mode in config file
This commit is contained in:
23
modules/common/src/main/scala/docspell/common/NlpMode.scala
Normal file
23
modules/common/src/main/scala/docspell/common/NlpMode.scala
Normal 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)
|
||||
}
|
@ -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] =
|
||||
|
Reference in New Issue
Block a user