Search in sources :

Example 1 with CachedWorkItemHandlerConfig

use of io.automatiko.engine.workflow.CachedWorkItemHandlerConfig in project automatiko-engine by automatiko-io.

the class SmileRandomForestPredictionTest method configure.

@BeforeEach
public void configure() {
    final RandomForestConfiguration configuration = new RandomForestConfiguration();
    final Map<String, AttributeType> inputFeatures = new HashMap<>();
    inputFeatures.put("ActorId", AttributeType.NOMINAL);
    configuration.setInputFeatures(inputFeatures);
    configuration.setOutcomeName("output");
    configuration.setOutcomeType(AttributeType.NOMINAL);
    configuration.setConfidenceThreshold(0.7);
    configuration.setNumTrees(1);
    predictionService = new SmileRandomForest(configuration);
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
    config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
    for (int i = 0; i < 10; i++) {
        predictionService.train(null, Collections.singletonMap("ActorId", "john"), Collections.singletonMap("output", "predicted value"));
    }
    for (int i = 0; i < 8; i++) {
        predictionService.train(null, Collections.singletonMap("ActorId", "mary"), Collections.singletonMap("output", "value"));
    }
}
Also used : HumanTaskWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler) PredictionAwareHumanTaskLifeCycle(io.automatiko.engine.addons.predictions.api.PredictionAwareHumanTaskLifeCycle) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) HashMap(java.util.HashMap) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) CachedWorkItemHandlerConfig(io.automatiko.engine.workflow.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with CachedWorkItemHandlerConfig

use of io.automatiko.engine.workflow.CachedWorkItemHandlerConfig in project automatiko-engine by automatiko-io.

the class PredictionAwareHumanTaskLifeCycleTest method configure.

@BeforeEach
public void configure() {
    predictNow = new AtomicBoolean(false);
    trainedTasks = new ArrayList<>();
    predictionService = new PredictionService() {

        @Override
        public void train(io.automatiko.engine.api.runtime.process.WorkItem task, Map<String, Object> inputData, Map<String, Object> outputData) {
            trainedTasks.add(task.getId());
        }

        @Override
        public PredictionOutcome predict(io.automatiko.engine.api.runtime.process.WorkItem task, Map<String, Object> inputData) {
            if (predictNow.get()) {
                return new PredictionOutcome(95, 75, Collections.singletonMap("output", "predicted value"));
            }
            return new PredictionOutcome();
        }

        @Override
        public String getIdentifier() {
            return "test";
        }
    };
    CachedWorkItemHandlerConfig wiConfig = new CachedWorkItemHandlerConfig();
    wiConfig.register("Human Task", new HumanTaskWorkItemHandler(new PredictionAwareHumanTaskLifeCycle(predictionService)));
    config = new StaticProcessConfig(wiConfig, new DefaultProcessEventListenerConfig(), new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()), null, new DefaultVariableInitializer(), null);
}
Also used : HumanTaskWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler) StaticProcessConfig(io.automatiko.engine.workflow.StaticProcessConfig) DefaultVariableInitializer(io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CachedWorkItemHandlerConfig(io.automatiko.engine.workflow.CachedWorkItemHandlerConfig) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) DefaultProcessEventListenerConfig(io.automatiko.engine.workflow.DefaultProcessEventListenerConfig) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CollectingUnitOfWorkFactory (io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory)2 DefaultUnitOfWorkManager (io.automatiko.engine.services.uow.DefaultUnitOfWorkManager)2 CachedWorkItemHandlerConfig (io.automatiko.engine.workflow.CachedWorkItemHandlerConfig)2 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)2 StaticProcessConfig (io.automatiko.engine.workflow.StaticProcessConfig)2 DefaultVariableInitializer (io.automatiko.engine.workflow.base.instance.context.variable.DefaultVariableInitializer)2 HumanTaskWorkItemHandler (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemHandler)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 PredictionAwareHumanTaskLifeCycle (io.automatiko.engine.addons.predictions.api.PredictionAwareHumanTaskLifeCycle)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1