Search in sources :

Example 16 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.

the class ReportUtils method writeExcelAndCSV.

public static void writeExcelAndCSV(TaskContext context, String contextLabel, TcFlexTable<String> table, String evalFileName, String suffixExcel, String suffixCsv) throws IOException {
    StorageService store = context.getStorageService();
    // Excel cannot cope with more than 255 columns
    if (table.getColumnIds().length <= 255) {
        context.storeBinary(evalFileName + "_compact" + suffixExcel, table.getExcelWriter());
    }
    context.storeBinary(evalFileName + "_compact" + suffixCsv, table.getCsvWriter());
    table.setCompact(false);
    // Excel cannot cope with more than 255 columns
    if (table.getColumnIds().length <= 255) {
        context.storeBinary(evalFileName + suffixExcel, table.getExcelWriter());
    }
    context.storeBinary(evalFileName + suffixCsv, table.getCsvWriter());
    // output the location of the batch evaluation folder
    // otherwise it might be hard for novice users to locate this
    File dummyFolder = store.locateKey(context.getId(), "dummy");
    // TODO can we also do this without creating and deleting the dummy folder?
    context.getLoggingService().message(contextLabel, "Storing detailed results in:\n" + dummyFolder.getParent() + "\n");
    FileUtils.deleteDirectory(dummyFolder);
}
Also used : File(java.io.File) StorageService(org.dkpro.lab.storage.StorageService)

Example 17 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.

the class InnerBatchReport method execute.

@Override
public void execute() throws Exception {
    StorageService store = getContext().getStorageService();
    Properties prop = new Properties();
    List<File> id2outcomeFiles = new ArrayList<>();
    List<File> baselineMajorityClass2outcomeFiles = new ArrayList<>();
    List<File> baselineRandom2outcomeFiles = new ArrayList<>();
    Set<String> ids = getTaskIdsFromMetaData(getSubtasks());
    for (String id : ids) {
        if (!TcTaskTypeUtil.isFacadeTask(store, id)) {
            continue;
        }
        Set<String> wrap = new HashSet<>();
        wrap.add(id);
        Set<String> subTaskId = collectTasks(wrap);
        subTaskId.remove(id);
        // Should be only one anyway?
        for (String subId : subTaskId) {
            if (!TcTaskTypeUtil.isMachineLearningAdapterTask(store, subId)) {
                continue;
            }
            Map<String, String> discriminatorsMap = store.retrieveBinary(id, Task.DISCRIMINATORS_KEY, new PropertiesAdapter()).getMap();
            File id2outcomeFile = store.locateKey(subId, ID_OUTCOME_KEY);
            id2outcomeFiles.add(id2outcomeFile);
            File baselineMajority2outcomeFile = store.locateKey(subId, BASELINE_MAJORITIY_ID_OUTCOME_KEY);
            if (isAvailable(baselineMajority2outcomeFile)) {
                baselineMajorityClass2outcomeFiles.add(baselineMajority2outcomeFile);
            }
            File baselineRandom2outcomeFile = store.locateKey(subId, BASELINE_RANDOM_ID_OUTCOME_KEY);
            if (isAvailable(baselineRandom2outcomeFile)) {
                baselineRandom2outcomeFiles.add(baselineRandom2outcomeFile);
            }
            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);
    writeCombinedOutcomeReport(FILE_COMBINED_ID_OUTCOME_KEY, aggregate(learningMode, id2outcomeFiles));
    writeCombinedOutcomeReport(FILE_COMBINED_BASELINE_MAJORITY_OUTCOME_KEY, aggregate(learningMode, baselineMajorityClass2outcomeFiles));
    writeCombinedOutcomeReport(FILE_COMBINED_BASELINE_RANDOM_OUTCOME_KEY, aggregate(learningMode, baselineRandom2outcomeFiles));
}
Also used : PropertiesAdapter(org.dkpro.lab.storage.impl.PropertiesAdapter) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) StorageService(org.dkpro.lab.storage.StorageService) HashSet(java.util.HashSet)

Example 18 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.

the class TcBatchReportBase method collectSubtasks.

/**
 * Collects recursively all <b>subtasks</b> stored in the <i>attributes.txt</i>. of a task and
 * the tasks located in a lower level in the hierarchy.
 *
 * @param contextId
 *            the current context id
 * @return set of all task ids including the one passed as parameter
 * @throws Exception
 *             in case of errors
 */
public Set<String> collectSubtasks(String contextId) throws Exception {
    Set<String> ids = new HashSet<>();
    StorageService store = getContext().getStorageService();
    File attributes = store.locateKey(contextId, Task.ATTRIBUTES_KEY);
    Set<String> taskIds = readSubTasks(attributes);
    ids.add(contextId);
    ids.addAll(taskIds);
    return ids;
}
Also used : File(java.io.File) HashSet(java.util.HashSet) StorageService(org.dkpro.lab.storage.StorageService)

Example 19 with StorageService

use of org.dkpro.lab.storage.StorageService in project dkpro-tc by dkpro.

the class TcBatchReportBase method getBaselineRandomId2Outcome.

/**
 * 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. random baseline is
 *         available for regression tasks
 * @throws Exception
 *             in case of errors
 */
protected File getBaselineRandomId2Outcome(String id) throws Exception {
    StorageService store = getContext().getStorageService();
    File id2outcomeFile = store.locateKey(id, BASELINE_RANDOM_ID_OUTCOME_KEY);
    return id2outcomeFile;
}
Also used : File(java.io.File) StorageService(org.dkpro.lab.storage.StorageService)

Aggregations

StorageService (org.dkpro.lab.storage.StorageService)19 File (java.io.File)14 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)4 StorageKey (org.dkpro.lab.storage.StorageService.StorageKey)4 PropertiesAdapter (org.dkpro.lab.storage.impl.PropertiesAdapter)4 TaskContextMetadata (org.dkpro.lab.task.TaskContextMetadata)4 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Properties (java.util.Properties)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 ConversionService (org.dkpro.lab.conversion.ConversionService)1 EmbeddingTask (org.dkpro.tc.core.task.deep.EmbeddingTask)1 PreparationTask (org.dkpro.tc.core.task.deep.PreparationTask)1 ID2OutcomeCombiner (org.dkpro.tc.ml.report.util.ID2OutcomeCombiner)1