Search in sources :

Example 1 with DefaultBatchTask

use of org.dkpro.lab.task.impl.DefaultBatchTask in project dkpro-lab by dkpro.

the class BatchTaskTest method testNested.

@Test
public void testNested() throws Exception {
    Dimension innerDim = Dimension.create("inner", "1", "2", "3");
    ParameterSpace innerPSpace = new ParameterSpace(innerDim);
    DefaultBatchTask innerTask = new DefaultBatchTask() {

        @Override
        public void setConfiguration(Map<String, Object> aConfig) {
            super.setConfiguration(aConfig);
            System.out.printf("A %10d %s %s%n", this.hashCode(), getType(), aConfig);
        }
    };
    innerTask.setParameterSpace(innerPSpace);
    innerTask.addTask(new ConfigDumperTask1());
    Dimension outerDim = Dimension.create("outer", "1", "2", "3");
    ParameterSpace outerPSpace = new ParameterSpace(outerDim);
    DefaultBatchTask outerTask = new DefaultBatchTask() {

        @Override
        public void setConfiguration(Map<String, Object> aConfig) {
            super.setConfiguration(aConfig);
            System.out.printf("B %10d %s %s%n", this.hashCode(), getType(), aConfig);
        }
    };
    outerTask.setParameterSpace(outerPSpace);
    outerTask.addTask(innerTask);
    outerTask.addTask(new ConfigDumperTask2());
    Lab.getInstance().run(outerTask);
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace) Dimension(org.dkpro.lab.task.Dimension) Map(java.util.Map) DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) Test(org.junit.Test)

Example 2 with DefaultBatchTask

use of org.dkpro.lab.task.impl.DefaultBatchTask in project dkpro-lab by dkpro.

the class BatchTaskTest method testNested2.

@Test
public void testNested2() throws Exception {
    DefaultBatchTask innerTask = new DefaultBatchTask() {

        @Discriminator
        private Integer outer;

        @Override
        public ParameterSpace getParameterSpace() {
            // Dynamically configure parameter space of nested batch task
            Integer[] values = new Integer[outer];
            for (int i = 0; i < outer; i++) {
                values[i] = i;
            }
            Dimension<Integer> innerDim = Dimension.create("inner", values);
            ParameterSpace innerPSpace = new ParameterSpace(innerDim);
            return innerPSpace;
        }

        @Override
        public void setConfiguration(Map<String, Object> aConfig) {
            super.setConfiguration(aConfig);
            System.out.printf("A %10d %s %s%n", this.hashCode(), getType(), aConfig);
        }
    };
    innerTask.addTask(new ConfigDumperTask1());
    Dimension<Integer> outerDim = Dimension.create("outer", 1, 2, 3);
    ParameterSpace outerPSpace = new ParameterSpace(outerDim);
    DefaultBatchTask outerTask = new DefaultBatchTask() {

        @Override
        public void setConfiguration(Map<String, Object> aConfig) {
            super.setConfiguration(aConfig);
            System.out.printf("B %10d %s %s%n", this.hashCode(), getType(), aConfig);
        }
    };
    outerTask.setParameterSpace(outerPSpace);
    outerTask.addTask(innerTask);
    outerTask.addTask(new ConfigDumperTask2());
    Lab.getInstance().run(outerTask);
}
Also used : ParameterSpace(org.dkpro.lab.task.ParameterSpace) Map(java.util.Map) DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) Test(org.junit.Test)

Example 3 with DefaultBatchTask

use of org.dkpro.lab.task.impl.DefaultBatchTask in project dkpro-lab by dkpro.

the class FoldDimensionBundleTest method testFoldInjection.

@Test
public void testFoldInjection() throws Exception {
    File repo = new File("target/repository/" + getClass().getSimpleName() + "/" + name.getMethodName());
    FileUtils.deleteDirectory(repo);
    repo.mkdirs();
    ((FileSystemStorageService) Lab.getInstance().getStorageService()).setStorageRoot(repo);
    Dimension<String> baseData = Dimension.create("base", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
    FoldDimensionBundle<String> foldBundle = new FoldDimensionBundle<String>("fold", baseData, 3);
    String expected = "0 - [1, 4, 7, 10] [2, 5, 8, 3, 6, 9]\n" + "1 - [2, 5, 8] [1, 4, 7, 10, 3, 6, 9]\n" + "2 - [3, 6, 9] [1, 4, 7, 10, 2, 5, 8]\n";
    ParameterSpace pSpace = new ParameterSpace(foldBundle);
    final StringBuilder actual = new StringBuilder();
    Task testTask = new ExecutableTaskBase() {

        int n = 0;

        @Discriminator
        Collection<String> fold_validation;

        @Discriminator
        Collection<String> fold_training;

        @Override
        public void execute(TaskContext aContext) throws Exception {
            System.out.printf("%d training  : %s\n", n, fold_training);
            System.out.printf("%d validation: %s\n", n, fold_validation);
            actual.append(String.format("%d - %s %s\n", n, fold_validation, fold_training));
            n++;
        }
    };
    DefaultBatchTask batchTask = new DefaultBatchTask();
    batchTask.setParameterSpace(pSpace);
    batchTask.addTask(testTask);
    Lab.getInstance().run(batchTask);
    assertEquals(3, pSpace.getStepCount());
    assertEquals(expected, actual.toString());
}
Also used : Task(org.dkpro.lab.task.Task) DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) FoldDimensionBundle(org.dkpro.lab.task.impl.FoldDimensionBundle) TaskContext(org.dkpro.lab.engine.TaskContext) ExecutableTaskBase(org.dkpro.lab.task.impl.ExecutableTaskBase) ParameterSpace(org.dkpro.lab.task.ParameterSpace) Collection(java.util.Collection) File(java.io.File) FileSystemStorageService(org.dkpro.lab.storage.filesystem.FileSystemStorageService) DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) Test(org.junit.Test)

Example 4 with DefaultBatchTask

use of org.dkpro.lab.task.impl.DefaultBatchTask in project dkpro-lab by dkpro.

the class MultiThreadBatchTaskTest method testNested.

@Test
public void testNested() throws Exception {
    Dimension innerDim = Dimension.create("inner", "1", "2", "3");
    ParameterSpace innerPSpace = new ParameterSpace(innerDim);
    // BatchTask innerTask = new BatchTask()
    DefaultBatchTask innerTask = new DefaultBatchTask() {

        @Override
        public void setConfiguration(Map<String, Object> aConfig) {
            super.setConfiguration(aConfig);
            System.out.printf("A %10d %s %s%n", this.hashCode(), getType(), aConfig);
        }
    };
    innerTask.setParameterSpace(innerPSpace);
    innerTask.addTask(new ConfigDumperTask1());
    Dimension outerDim = Dimension.create("outer", "1", "2", "3");
    ParameterSpace outerPSpace = new ParameterSpace(outerDim);
    // BatchTask outerTask = new BatchTask()
    DefaultBatchTask outerTask = new DefaultBatchTask() {

        @Override
        public void setConfiguration(Map<String, Object> aConfig) {
            super.setConfiguration(aConfig);
            System.out.printf("B %10d %s %s%n", this.hashCode(), getType(), aConfig);
        }
    };
    outerTask.setParameterSpace(outerPSpace);
    outerTask.addTask(innerTask);
    outerTask.addTask(new ConfigDumperTask2());
    Lab.getInstance().run(outerTask);
}
Also used : Map(java.util.Map) DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) Test(org.junit.Test)

Example 5 with DefaultBatchTask

use of org.dkpro.lab.task.impl.DefaultBatchTask in project dkpro-lab by dkpro.

the class MultiThreadBatchTaskTest method testUnresolvable.

@Test(expected = UnresolvedImportException.class)
public void testUnresolvable() throws Exception {
    Dimension<String> dim = Dimension.create("param", "1", "2", "3");
    ParameterSpace pSpace = new ParameterSpace(dim);
    Task task1 = new ExecutableTaskBase() {

        @Discriminator
        private String param;

        @Override
        public void execute(TaskContext aContext) throws Exception {
        // Nothing to do
        }
    };
    Task task2 = new ExecutableTaskBase() {

        @Discriminator
        private String param;

        @Override
        public void execute(TaskContext aContext) throws Exception {
        // Nothing to do
        }
    };
    task2.addImport(task1, "DUMMY");
    task1.addImport(task2, "DUMMY");
    DefaultBatchTask batchTask = new DefaultBatchTask();
    batchTask.setParameterSpace(pSpace);
    batchTask.addTask(task1);
    batchTask.addTask(task2);
    Lab.getInstance().run(batchTask);
}
Also used : DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) TaskContext(org.dkpro.lab.engine.TaskContext) ExecutableTaskBase(org.dkpro.lab.task.impl.ExecutableTaskBase) DefaultBatchTask(org.dkpro.lab.task.impl.DefaultBatchTask) Test(org.junit.Test)

Aggregations

DefaultBatchTask (org.dkpro.lab.task.impl.DefaultBatchTask)20 Test (org.junit.Test)17 ParameterSpace (org.dkpro.lab.task.ParameterSpace)12 TaskContext (org.dkpro.lab.engine.TaskContext)11 ExecutableTaskBase (org.dkpro.lab.task.impl.ExecutableTaskBase)9 File (java.io.File)6 Map (java.util.Map)5 Task (org.dkpro.lab.task.Task)5 ImsCwbWriter (de.tudarmstadt.ukp.dkpro.core.io.imscwb.ImsCwbWriter)2 XmiWriter (de.tudarmstadt.ukp.dkpro.core.io.xmi.XmiWriter)2 SnowballStemmer (de.tudarmstadt.ukp.dkpro.core.snowball.SnowballStemmer)2 BreakIteratorSegmenter (de.tudarmstadt.ukp.dkpro.core.tokit.BreakIteratorSegmenter)2 Properties (java.util.Properties)2 Lab (org.dkpro.lab.Lab)2 ExamplePosAnnotator (org.dkpro.lab.ml.example.ExamplePosAnnotator)2 PropertiesAdapter (org.dkpro.lab.storage.impl.PropertiesAdapter)2 UimaTaskBase (org.dkpro.lab.uima.task.impl.UimaTaskBase)2 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1