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;
}
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;
}
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;
}
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);
}
}
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);
}
}
}
Aggregations