use of org.dkpro.lab.storage.impl.PropertiesAdapter 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.impl.PropertiesAdapter 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;
}
use of org.dkpro.lab.storage.impl.PropertiesAdapter 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;
}
use of org.dkpro.lab.storage.impl.PropertiesAdapter in project dkpro-tc by dkpro.
the class DeepLearningInnerBatchReport method execute.
@Override
public void execute() throws Exception {
StorageService store = getContext().getStorageService();
Properties prop = new Properties();
List<File> id2outcomeFiles = new ArrayList<>();
Set<String> ids = getTaskIdsFromMetaData(getSubtasks());
for (String id : ids) {
if (!TcTaskTypeUtil.isMachineLearningAdapterTask(store, id)) {
continue;
}
Map<String, String> discriminatorsMap = store.retrieveBinary(id, Task.DISCRIMINATORS_KEY, new PropertiesAdapter()).getMap();
File id2outcomeFile = store.locateKey(id, Constants.ID_OUTCOME_KEY);
id2outcomeFiles.add(id2outcomeFile);
for (Entry<String, String> e : discriminatorsMap.entrySet()) {
String key = e.getKey();
String value = e.getValue();
prop.setProperty(key, value);
}
}
String learningMode = getDiscriminator(store, ids, DIM_LEARNING_MODE);
ID2OutcomeCombiner<String> aggregator = new ID2OutcomeCombiner<>(learningMode);
for (File id2o : id2outcomeFiles) {
aggregator.add(id2o, learningMode);
}
writeCombinedOutcomeReport(aggregator.generateId2OutcomeFile());
}
use of org.dkpro.lab.storage.impl.PropertiesAdapter in project dkpro-lab by dkpro.
the class StorageServiceTest method storeReadProperties.
@Test
public void storeReadProperties() {
Map<String, String> data = new HashMap<String, String>();
data.put("key1", "value1");
data.put("key2", "value2");
storageService.storeBinary("dummy", "data", new PropertiesAdapter(data));
Map<String, String> data2 = storageService.retrieveBinary("dummy", "data", new PropertiesAdapter(data)).getMap();
assertEquals(data, data2);
}
Aggregations