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