Search in sources :

Example 1 with PropertiesAdapter

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;
}
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 2 with PropertiesAdapter

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;
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PropertiesAdapter

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;
}
Also used : TaskContextMetadata(org.dkpro.lab.task.TaskContextMetadata) PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 4 with PropertiesAdapter

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());
}
Also used : PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ID2OutcomeCombiner(org.dkpro.tc.ml.report.util.ID2OutcomeCombiner) File(java.io.File) StorageService(org.dkpro.lab.storage.StorageService)

Example 5 with PropertiesAdapter

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);
}
Also used : PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

PropertiesAdapter (org.dkpro.lab.storage.impl.PropertiesAdapter)10 Properties (java.util.Properties)5 HashMap (java.util.HashMap)4 StorageService (org.dkpro.lab.storage.StorageService)4 TaskContextMetadata (org.dkpro.lab.task.TaskContextMetadata)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 File (java.io.File)2 Map (java.util.Map)2 TaskContext (org.dkpro.lab.engine.TaskContext)2 DefaultBatchTask (org.dkpro.lab.task.impl.DefaultBatchTask)2 ExecutableTaskBase (org.dkpro.lab.task.impl.ExecutableTaskBase)2 URI (java.net.URI)1 HashSet (java.util.HashSet)1 ConversionService (org.dkpro.lab.conversion.ConversionService)1 Task (org.dkpro.lab.task.Task)1 ID2OutcomeCombiner (org.dkpro.tc.ml.report.util.ID2OutcomeCombiner)1