use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.
the class TcBatchReportBase method getId2Outcome.
/**
* Retrieves the id2outcome file in a train test setup. The behavior of this method in cross
* validation tasks is undefined.
*
* @param id
* context id of machine learning adapter
*
* @return file to the id2 outcome file in the machine learning adapter or null if the folder of
* machine learning adapter was not found
* @throws Exception
* in case of errors
*/
protected File getId2Outcome(String id) throws Exception {
StorageService store = getContext().getStorageService();
File id2outcomeFile = store.locateKey(id, ID_OUTCOME_KEY);
return id2outcomeFile;
}
use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.
the class TcBatchReportBase method getBaselineMajorityClassId2Outcome.
/**
* Retrieves the id2outcome file in a train test setup. The behavior of this method in cross
* validation tasks is undefined.
*
* @param id
* context id of machine learning adapter
*
* @return file to the majority class id2 outcome file in the machine learning adapter or null
* if the folder of machine learning adapter was not found, i.e. majority class is not
* defined for regression tasks
* @throws Exception
* in case of errors
*/
protected File getBaselineMajorityClassId2Outcome(String id) throws Exception {
StorageService store = getContext().getStorageService();
File id2outcomeFile = store.locateKey(id, BASELINE_MAJORITIY_ID_OUTCOME_KEY);
return id2outcomeFile;
}
use of org.dkpro.lab.storage.StorageService in project dkpro-lab by dkpro.
the class BatchTaskEngine method getLatestExecution.
/**
* Locate the latest task execution compatible with the given task configuration.
*
* @param aContext
* the context of the current batch task.
* @param aType
* the type of the task context to find.
* @param aDiscriminators
* the discriminators of the task context to find.
* @param aConfig
* the current parameter configuration.
* @throws TaskContextNotFoundException
* if a matching task context could not be found.
* @see ImportUtil#matchConstraints(Map, Map, boolean)
*/
private TaskContextMetadata getLatestExecution(TaskContext aContext, String aType, Map<String, String> aDiscriminators, Map<String, Object> aConfig) {
// Convert parameter values to strings
Map<String, String> config = new HashMap<String, String>();
for (Entry<String, Object> e : aConfig.entrySet()) {
config.put(e.getKey(), Util.toString(e.getValue()));
// If the conversion service has a registered value override the constraint here
// accordingly
Object object = e.getValue();
ConversionService cs = aContext.getConversionService();
if (cs.isRegistered(object)) {
config.put(e.getKey(), cs.getDiscriminableValue(object));
}
}
StorageService storage = aContext.getStorageService();
List<TaskContextMetadata> metas = storage.getContexts(aType, aDiscriminators);
for (TaskContextMetadata meta : metas) {
Map<String, String> discriminators = storage.retrieveBinary(meta.getId(), Task.DISCRIMINATORS_KEY, new PropertiesAdapter()).getMap();
// interpret the discriminators as constraints on the current configuration.
if (ImportUtil.matchConstraints(discriminators, config, false)) {
return meta;
}
}
throw ImportUtil.createContextNotFoundException(aType, aDiscriminators);
}
use of org.dkpro.lab.storage.StorageService in project dkpro-lab by dkpro.
the class DefaultTaskContext method getStorageLocation.
@Deprecated
@Override
public File getStorageLocation(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);
}
return getStorageService().getStorageFolder(key.contextId, key.key);
}
use of org.dkpro.lab.storage.StorageService in project dkpro-lab by dkpro.
the class DefaultTaskContext method resolve.
public StorageKey resolve(String aKey, AccessMode aMode, boolean aAllowMissing) {
StorageService storage = getStorageService();
Map<String, String> imports = getMetadata().getImports();
if (storage.containsKey(getId(), aKey)) {
// supersedes imported data.
return 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);
}
// Try resolving by ID or by type/constraints
StorageKey key = null;
if (CONTEXT_ID_SCHEME.equals(uri.getScheme()) || LATEST_CONTEXT_SCHEME.equals(uri.getScheme())) {
TaskContextMetadata meta = resolve(uri);
key = new StorageKey(meta.getId(), uri.getPath());
}
// imported storage folders now but imported stream-access (files) keys later.
if (key != null) {
switch(aMode) {
case ADD_ONLY:
case READWRITE:
storage.copy(getId(), aKey, key, aMode);
return new StorageKey(getId(), aKey);
case READONLY:
return key;
}
}
// If this is an external URL, copy it to the current context and then return a location
// in the current context.
InputStream is = null;
try {
is = uri.toURL().openStream();
storage.storeBinary(getId(), aKey, is);
return new StorageKey(getId(), aKey);
} catch (MalformedURLException e) {
throw new DataAccessResourceFailureException("Imported external key [" + aKey + "] resolves to illegal URL [" + uri + "]", e);
} catch (IOException e) {
throw new DataAccessResourceFailureException("Unable to read data for external key [" + aKey + "] from [" + uri + "]", e);
} finally {
close(is);
}
} else if (aAllowMissing) {
return new StorageKey(getId(), aKey);
}
throw new DataAccessResourceFailureException("No resource bound to key [" + aKey + "]");
}
Aggregations