Search in sources :

Example 1 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-lab by dkpro.

the class DefaultTaskContext method getFile.

@Override
public File getFile(String aKey, AccessMode aMode) {
    StorageKey key;
    StorageService storage = getStorageService();
    Map<String, String> imports = getMetadata().getImports();
    if (storage.containsKey(getId(), aKey)) {
        // If the context contains the key, we do nothing. Locally available data always
        // supersedes imported data.
        key = new StorageKey(getId(), aKey);
    } else if (imports.containsKey(aKey)) {
        URI uri;
        try {
            uri = new URI(imports.get(aKey));
        } catch (URISyntaxException e) {
            throw new DataAccessResourceFailureException("Imported key [" + aKey + "] resolves to illegal URL [" + imports.get(aKey) + "]", e);
        }
        if ("file".equals(uri.getScheme()) && new File(uri).isFile()) {
            if (aMode == AccessMode.READONLY) {
                return new File(uri);
            } else {
                // Here we should probably just copy the imported file into the context
                throw new DataAccessResourceFailureException("READWRITE access of imported " + "files is not implemented yet.");
            }
        } else {
            key = resolve(aKey, aMode, true);
        }
    } else {
        key = resolve(aKey, aMode, true);
    }
    File file = getStorageService().locateKey(key.contextId, key.key);
    if (file.exists() && !file.isFile()) {
        throw new DataAccessResourceFailureException("Key [" + aKey + "] resolves to [" + file + "] which is not a file.");
    }
    return file;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) StorageKey(org.dkpro.lab.storage.StorageService.StorageKey) StorageService(org.dkpro.lab.storage.StorageService)

Example 2 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-lab by dkpro.

the class DefaultTaskContext method getFolder.

@Override
public File getFolder(String aKey, AccessMode aMode) {
    StorageKey key;
    StorageService storage = getStorageService();
    Map<String, String> imports = getMetadata().getImports();
    if (storage.containsKey(getId(), aKey)) {
        // If the context contains the key, we do nothing. Locally available data always
        // supersedes imported data.
        key = new StorageKey(getId(), aKey);
    } else if (imports.containsKey(aKey)) {
        URI uri;
        try {
            uri = new URI(imports.get(aKey));
        } catch (URISyntaxException e) {
            throw new DataAccessResourceFailureException("Imported key [" + aKey + "] resolves to illegal URL [" + imports.get(aKey) + "]", e);
        }
        if ("file".equals(uri.getScheme()) && new File(uri).isDirectory()) {
            if (aMode == AccessMode.READONLY) {
                return new File(uri);
            } else {
                // Here we should probably just copy the imported folder into the context
                throw new DataAccessResourceFailureException("READWRITE access of imported " + "folders is not implemented yet.");
            }
        } else {
            key = resolve(aKey, aMode, true);
        }
    } else {
        key = resolve(aKey, aMode, true);
    }
    File folder = getStorageService().locateKey(key.contextId, key.key);
    if (!folder.exists()) {
        folder.mkdirs();
    }
    if (!folder.isDirectory()) {
        throw new DataAccessResourceFailureException("Key [" + aKey + "] resolves to [" + folder + "] which is not a folder.");
    }
    return folder;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) StorageKey(org.dkpro.lab.storage.StorageService.StorageKey) StorageService(org.dkpro.lab.storage.StorageService)

Example 3 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-lab by dkpro.

the class TaskBase method getResolvedDescriminators.

@Override
public Map<String, String> getResolvedDescriminators(TaskContext aContext) {
    StorageService storageService = aContext.getStorageService();
    Map<String, String> descs = new HashMap<String, String>();
    descs.putAll(getDescriminators());
    // defined in this task
    for (String rawUri : aContext.getMetadata().getImports().values()) {
        URI uri = URI.create(rawUri);
        if (isStaticImport(uri)) {
            continue;
        }
        final TaskContextMetadata meta = aContext.resolve(uri);
        Map<String, String> prerequisiteDiscriminators = storageService.retrieveBinary(meta.getId(), DISCRIMINATORS_KEY, new PropertiesAdapter()).getMap();
        for (Entry<String, String> e : prerequisiteDiscriminators.entrySet()) {
            if (descs.containsKey(e.getKey()) && !descs.get(e.getKey()).equals(e.getValue())) {
                throw new IllegalStateException("Discriminator [" + e.getKey() + "] in task [" + getType() + "] conflicts with dependency [" + meta.getType() + "]");
            }
            descs.put(e.getKey(), e.getValue());
        }
    }
    return descs;
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) HashMap(java.util.HashMap) URI(java.net.URI) StorageService(org.dkpro.lab.storage.StorageService)

Example 4 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.

the class ContextMemoryReport method execute.

@Override
public void execute() throws Exception {
    id2outcomeFiles = new ArrayList<>();
    crossValidationCombinedIdFiles = new ArrayList<>();
    allIds = new ArrayList<String>();
    StorageService storageService = getContext().getStorageService();
    Set<String> taskIds = getTaskIdsFromMetaData(getSubtasks());
    allIds.addAll(collectTasks(taskIds));
    for (String id : taskIds) {
        processFacadeId(storageService, id);
        processMachineLearningAdapterId(storageService, id);
        processCrossValidationId(storageService, id);
    }
}
Also used : StorageService(org.dkpro.lab.storage.StorageService)

Example 5 with StorageService

use of org.dkpro.lab.storage.StorageService 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

StorageService (org.dkpro.lab.storage.StorageService)19 File (java.io.File)14 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)4 StorageKey (org.dkpro.lab.storage.StorageService.StorageKey)4 PropertiesAdapter (org.dkpro.lab.storage.impl.PropertiesAdapter)4 TaskContextMetadata (org.dkpro.lab.task.TaskContextMetadata)4 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Properties (java.util.Properties)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 ConversionService (org.dkpro.lab.conversion.ConversionService)1 EmbeddingTask (org.dkpro.tc.core.task.deep.EmbeddingTask)1 PreparationTask (org.dkpro.tc.core.task.deep.PreparationTask)1 ID2OutcomeCombiner (org.dkpro.tc.ml.report.util.ID2OutcomeCombiner)1