Search in sources :

Example 1 with FileSystemStorageService

use of org.dkpro.lab.storage.filesystem.FileSystemStorageService 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 2 with FileSystemStorageService

use of org.dkpro.lab.storage.filesystem.FileSystemStorageService in project dkpro-lab by dkpro.

the class PosExampleCrf method clean.

/**
 * This is a hack to change the repository to a path inside this project.Normally you should
 * set the environment variable DKPRO_HOME before using the Lab.
 */
public void clean() throws Exception {
    System.setProperty("DKPRO_HOME", new File("target").getAbsolutePath());
    File repo = new File("target/repository");
    FileUtils.deleteDirectory(repo);
    repo.mkdirs();
    ((FileSystemStorageService) Lab.getInstance().getStorageService()).setStorageRoot(repo);
}
Also used : File(java.io.File) FileSystemStorageService(org.dkpro.lab.storage.filesystem.FileSystemStorageService)

Example 3 with FileSystemStorageService

use of org.dkpro.lab.storage.filesystem.FileSystemStorageService in project dkpro-lab by dkpro.

the class PosExampleMaxEnt method clean.

/**
 * This is a hack to change the repository to a path inside this project.Normally you should
 * set the environment variable DKPRO_HOME before using the Lab.
 */
public void clean() throws Exception {
    System.setProperty("DKPRO_HOME", new File("target").getAbsolutePath());
    File repo = new File("target/repository");
    FileUtils.deleteDirectory(repo);
    repo.mkdirs();
    ((FileSystemStorageService) Lab.getInstance().getStorageService()).setStorageRoot(repo);
}
Also used : File(java.io.File) FileSystemStorageService(org.dkpro.lab.storage.filesystem.FileSystemStorageService)

Example 4 with FileSystemStorageService

use of org.dkpro.lab.storage.filesystem.FileSystemStorageService in project dkpro-lab by dkpro.

the class SimpleExecutionEngineTest method testInit.

@Test
public void testInit() throws Exception {
    File repo = new File("target/repository");
    FileUtils.deleteDirectory(repo);
    ((FileSystemStorageService) storageService).setStorageRoot(repo);
    assertNotNull(executionService);
    assertNotNull(contextFactory);
    TypeSystemDescription tsd = createTypeSystemDescription(new String[0]);
    AnalysisEngineDescription desc = createEngineDescription(DummyAE.class, tsd);
    DefaultUimaTask cfg = new DefaultUimaTask();
    cfg.setReaderDescription(createReaderDescription(TestReader.class, tsd));
    cfg.setAnalysisEngineDescription(desc);
    TaskExecutionEngine runner = executionService.createEngine(cfg);
    String uuid = runner.run(cfg);
    System.out.println("=== Experiments in repository ===");
    List<TaskContextMetadata> experiments = storageService.getContexts();
    for (TaskContextMetadata e : experiments) {
        System.out.println(e);
    }
    final StringBuilder sb = new StringBuilder();
    storageService.retrieveBinary(uuid, "test", new StreamReader() {

        @Override
        public void read(InputStream aInputStream) throws IOException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Util.shoveAndClose(aInputStream, bos);
            sb.append(new String(bos.toByteArray(), "UTF-8"));
        }
    });
    assertEquals("works", sb.toString());
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) TypeSystemDescriptionFactory.createTypeSystemDescription(org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TaskExecutionEngine(org.dkpro.lab.engine.TaskExecutionEngine) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultUimaTask(org.dkpro.lab.uima.task.impl.DefaultUimaTask) TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) StreamReader(org.dkpro.lab.storage.StreamReader) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) FileSystemStorageService(org.dkpro.lab.storage.filesystem.FileSystemStorageService) Test(org.junit.Test)

Example 5 with FileSystemStorageService

use of org.dkpro.lab.storage.filesystem.FileSystemStorageService in project dkpro-lab by dkpro.

the class UimaAsExecutionEngineTest method testInit.

@Test
public void testInit() throws Exception {
    File repo = new File("target/repository");
    FileUtils.deleteQuietly(repo);
    ((FileSystemStorageService) storageService).setStorageRoot(repo);
    assertNotNull(executionService);
    assertNotNull(contextFactory);
    AnalysisEngineDescription desc = createEngineDescription(DummyAE.class);
    DefaultUimaTask cfg = new DefaultUimaTask();
    cfg.setReaderDescription(createReaderDescription(TestReader.class));
    cfg.setAnalysisEngineDescription(desc);
    TaskExecutionEngine runner = executionService.createEngine(cfg);
    String uuid = runner.run(cfg);
    System.out.println("=== Experiments in repository ===");
    List<TaskContextMetadata> experiments = storageService.getContexts();
    for (TaskContextMetadata e : experiments) {
        System.out.println(e);
    }
    final StringBuilder sb = new StringBuilder();
    storageService.retrieveBinary(uuid, "test", new StreamReader() {

        @Override
        public void read(InputStream aInputStream) throws IOException {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Util.shoveAndClose(aInputStream, bos);
            sb.append(new String(bos.toByteArray(), "UTF-8"));
        }
    });
    assertEquals("works", sb.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TaskExecutionEngine(org.dkpro.lab.engine.TaskExecutionEngine) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultUimaTask(org.dkpro.lab.uima.task.impl.DefaultUimaTask) TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) StreamReader(org.dkpro.lab.storage.StreamReader) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) File(java.io.File) FileSystemStorageService(org.dkpro.lab.storage.filesystem.FileSystemStorageService) Test(org.junit.Test)

Aggregations

File (java.io.File)5 FileSystemStorageService (org.dkpro.lab.storage.filesystem.FileSystemStorageService)5 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)2 TaskExecutionEngine (org.dkpro.lab.engine.TaskExecutionEngine)2 StreamReader (org.dkpro.lab.storage.StreamReader)2 TaskContextMetadata (org.dkpro.lab.task.TaskContextMetadata)2 DefaultUimaTask (org.dkpro.lab.uima.task.impl.DefaultUimaTask)2 Collection (java.util.Collection)1 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)1 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)1 TaskContext (org.dkpro.lab.engine.TaskContext)1 ParameterSpace (org.dkpro.lab.task.ParameterSpace)1 Task (org.dkpro.lab.task.Task)1 DefaultBatchTask (org.dkpro.lab.task.impl.DefaultBatchTask)1 ExecutableTaskBase (org.dkpro.lab.task.impl.ExecutableTaskBase)1