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