Integrate learn-classifier task into the app

This commit is contained in:
Eike Kettner
2020-09-01 00:21:19 +02:00
parent 0c97b4ef76
commit 68bb65572b
5 changed files with 53 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import docspell.ftssolr.SolrFtsClient
import docspell.joex.analysis.RegexNerFile
import docspell.joex.fts.{MigrationTask, ReIndexTask}
import docspell.joex.hk._
import docspell.joex.learn.LearnClassifierTask
import docspell.joex.notify._
import docspell.joex.pdfconv.ConvertAllPdfTask
import docspell.joex.pdfconv.PdfConvTask
@ -159,6 +160,13 @@ object JoexAppImpl {
ConvertAllPdfTask.onCancel[F]
)
)
.withTask(
JobTask.json(
LearnClassifierArgs.taskName,
LearnClassifierTask[F](cfg.textAnalysis, blocker, analyser),
LearnClassifierTask.onCancel[F]
)
)
.resource
psch <- PeriodicScheduler.create(
cfg.periodicScheduler,

View File

@ -12,11 +12,15 @@ import docspell.backend.ops.OCollective
import docspell.common._
import docspell.joex.Config
import docspell.joex.scheduler._
import docspell.store.records.RClassifierSetting
object LearnClassifierTask {
type Args = LearnClassifierArgs
def onCancel[F[_]: Sync]: Task[F, Args, Unit] =
Task.log(_.warn("Cancelling learn-classifier task"))
def apply[F[_]: Sync: ContextShift](
cfg: Config.TextAnalysis,
blocker: Blocker,
@ -24,7 +28,7 @@ object LearnClassifierTask {
): Task[F, Args, Unit] =
Task { ctx =>
(for {
sett <- findActiveSettings[F](ctx.args.collective, cfg)
sett <- findActiveSettings[F](ctx, cfg)
data = selectItems(
ctx,
math.min(cfg.classification.itemCount, sett.itemCount),
@ -52,10 +56,16 @@ object LearnClassifierTask {
???
private def findActiveSettings[F[_]: Sync](
coll: Ident,
ctx: Context[F, Args],
cfg: Config.TextAnalysis
): OptionT[F, OCollective.Classifier] =
???
if (cfg.classification.enabled)
OptionT(ctx.store.transact(RClassifierSetting.findById(ctx.args.collective)))
.filter(_.enabled)
.filter(_.category.nonEmpty)
.map(OCollective.Classifier.fromRecord)
else
OptionT.none
private def logInactiveWarning[F[_]: Sync](logger: Logger[F]): F[Unit] =
logger.warn(