Search in sources :

Example 6 with TaskContextMetadata

use of org.dkpro.lab.task.TaskContextMetadata in project dkpro-lab by dkpro.

the class CachedFileSystemStorageService method retrieveBinary.

@SuppressWarnings("unchecked")
@Override
public <T extends StreamReader> T retrieveBinary(String aContextId, String aKey, T aConsumer) {
    T consumer = null;
    // Get the consumer from cache if it is a TaskContextMetadata or PropertiesAdapter.
    if (aConsumer instanceof TaskContextMetadata && aKey.equals(METADATA_KEY)) {
        consumer = (T) contexts.get(aContextId);
    } else if (aConsumer instanceof PropertiesAdapter && aKey.equals(DISCRIMINATORS_KEY)) {
        Properties props = new Properties();
        Map<String, String> discs = discriminators.get(aContextId);
        if (discs != null) {
            props.putAll(discs);
            ((PropertiesAdapter) aConsumer).setProperties(props);
            consumer = aConsumer;
        }
    }
    // it from file and store it in the cache.
    if (consumer == null) {
        consumer = super.retrieveBinary(aContextId, aKey, aConsumer);
        storeInCache(aContextId, aKey, consumer);
    }
    return consumer;
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with TaskContextMetadata

use of org.dkpro.lab.task.TaskContextMetadata in project dkpro-lab by dkpro.

the class CachedFileSystemStorageService method getContexts.

@Override
public List<TaskContextMetadata> getContexts() {
    if (!scannedFiles) {
        // cache.
        for (TaskContextMetadata meta : super.getContexts()) {
            contexts.put(meta.getId(), meta);
        }
        scannedFiles = true;
    }
    List<TaskContextMetadata> contextList = new ArrayList<TaskContextMetadata>(contexts.values());
    Collections.sort(contextList, new Comparator<TaskContextMetadata>() {

        @Override
        public int compare(TaskContextMetadata aO1, TaskContextMetadata aO2) {
            return Long.signum(aO2.getEnd() - aO1.getEnd());
        }
    });
    return contextList;
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) ArrayList(java.util.ArrayList)

Example 8 with TaskContextMetadata

use of org.dkpro.lab.task.TaskContextMetadata in project dkpro-lab by dkpro.

the class FileSystemStorageService method getContexts.

@Override
public List<TaskContextMetadata> getContexts(String aTaskType, Map<String, String> aConstraints) {
    List<TaskContextMetadata> contexts = new ArrayList<TaskContextMetadata>();
    nextContext: for (TaskContextMetadata e : getContexts()) {
        // Ignore those that do not match the type
        if (!aTaskType.equals(e.getType())) {
            continue;
        }
        // Check the constraints if there are any
        if (aConstraints.size() > 0) {
            final Map<String, String> properties = retrieveBinary(e.getId(), Task.DISCRIMINATORS_KEY, new PropertiesAdapter()).getMap();
            if (!matchConstraints(properties, aConstraints, true)) {
                continue nextContext;
            }
        }
        contexts.add(e);
    }
    Collections.sort(contexts, new Comparator<TaskContextMetadata>() {

        @Override
        public int compare(TaskContextMetadata aO1, TaskContextMetadata aO2) {
            return Long.signum(aO2.getEnd() - aO1.getEnd());
        }
    });
    return contexts;
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 9 with TaskContextMetadata

use of org.dkpro.lab.task.TaskContextMetadata 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 10 with TaskContextMetadata

use of org.dkpro.lab.task.TaskContextMetadata in project dkpro-tc by dkpro.

the class LabFolderTrackerReport method execute.

@Override
public void execute() throws Exception {
    StorageService ss = getContext().getStorageService();
    for (TaskContextMetadata subcontext : getSubtasks()) {
        String type = subcontext.getType();
        if (type.contains(VectorizationTask.class.getName()) && type.contains("-Train-")) {
            vectorizationTaskTrain = ss.locateKey(subcontext.getId(), "").getAbsolutePath();
            System.err.println(vectorizationTaskTrain);
        }
        if (type.contains(VectorizationTask.class.getName()) && type.contains("-Test-")) {
            vectorizationTaskTest = ss.locateKey(subcontext.getId(), "").getAbsolutePath();
            System.err.println(vectorizationTaskTest);
        }
        if (type.contains(PreparationTask.class.getName())) {
            preparationTask = ss.locateKey(subcontext.getId(), "").getAbsolutePath();
            System.err.println(preparationTask);
        }
        if (type.contains(EmbeddingTask.class.getName())) {
            embeddingTask = ss.locateKey(subcontext.getId(), "").getAbsolutePath();
            System.err.println(embeddingTask);
        }
    }
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) PreparationTask(org.dkpro.tc.core.task.deep.PreparationTask) EmbeddingTask(org.dkpro.tc.core.task.deep.EmbeddingTask) StorageService(org.dkpro.lab.storage.StorageService)

Aggregations

TaskContextMetadata (org.dkpro.lab.task.TaskContextMetadata)15 File (java.io.File)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 StorageService (org.dkpro.lab.storage.StorageService)4 PropertiesAdapter (org.dkpro.lab.storage.impl.PropertiesAdapter)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URI (java.net.URI)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)2 TaskExecutionEngine (org.dkpro.lab.engine.TaskExecutionEngine)2 StreamReader (org.dkpro.lab.storage.StreamReader)2 UnresolvedImportException (org.dkpro.lab.storage.UnresolvedImportException)2 FileSystemStorageService (org.dkpro.lab.storage.filesystem.FileSystemStorageService)2 BatchTask (org.dkpro.lab.task.BatchTask)2