use of edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTParameters in project cogtool by cogtool.
the class ProjectController method computeSnifAct.
// assignActions
protected boolean computeSnifAct(Design design, AUndertaking task, IUndoableEditSequence editSequence, SNIFACTGroupParameters defaults) {
// TODO: L10N required for error titles and messages.
if (design == null) {
interaction.reportProblem("SNIF-ACT", "No design is selected.");
return false;
}
if (design.getFrames().size() == 0) {
interaction.reportProblem("SNIF-ACT", "Selected design is empty.");
return false;
}
if (task.isTaskGroup()) {
// We can only recompute with this algorithm if the
// group was generated by a previous SNIF-ACT
// computation (and thus has the execution
// context attribute)
Object contextAttr = task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
if (NullSafe.equals(contextAttr, WidgetAttributes.NO_CONTEXT)) {
interaction.reportProblem("SNIF-ACT", "Can't recompute with this algorithm from this cell.");
return false;
}
}
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (dict == null) {
interaction.reportProblem("Export Dictionary", "No dictionary exists for the selected design");
return false;
}
List<Frame> sortedFrames = NamedObjectUtil.getSortedList(design.getFrames());
SNIFACTParameters parms;
int addGroupMode;
boolean hasScript = false;
final SNIFACTExecContext prevContext;
if (task.isTaskGroup()) {
// Since we got this far, we know the group already has
// parameters associated with it, so use those values as
// defaults in the dialog box
prevContext = (SNIFACTExecContext) task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
parms = prevContext.getParameters();
addGroupMode = SNIFACTDialog.ENABLED;
} else {
// Otherwise, create a new set of default values for this
// execution
String defaultName = sortedFrames.get(0).getName();
List<String> targets = new ArrayList<String>();
targets.add(defaultName);
parms = new SNIFACTParameters(task.getName(), NUM_SNIF_ACT_TRIALS, SNIF_ACT_K_VALUE, defaultName, targets, ITermSimilarity.ALL);
addGroupMode = SNIFACTDialog.NONE;
prevContext = null;
TaskApplication ta = project.getTaskApplication(task, design);
hasScript = (ta != null) && ta.hasScript();
}
SNIFACTGroupParameters groupParms = null;
if (defaults == null) {
groupParms = interaction.requestSNIFACTParameters(hasScript, sortedFrames, parms, dict.getAlgorithmsInUse(), addGroupMode);
} else {
groupParms = new SNIFACTGroupParameters(defaults.taskName, defaults.numRuns, defaults.kValue, defaults.startFrame, defaults.targetFrames, defaults.algorithm, ((addGroupMode != SNIFACTDialog.NONE) && defaults.addToGroup));
}
if (groupParms == null) {
return false;
}
SNIFACTPredictionAlgo.ONLY.setParameters(groupParms);
TaskParent parent = task.getTaskGroup();
if (parent == null) {
parent = project;
}
final TaskGroup group;
if (groupParms.addToGroup) {
// user wants to add new trial tasks to the same group
group = (TaskGroup) task;
} else {
Collection<AUndertaking> siblings = parent.getUndertakings();
group = new TaskGroup(SNIFACTCmd.getGroupName(groupParms, siblings), GroupNature.MEAN);
}
final SNIFACTExecContext context = SNIFACTCmd.computeInBackground(project, design, interaction, group, groupParms);
if (context == null) {
return true;
}
group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context);
CompoundUndoableEdit snifActEditSeq = new CompoundUndoableEdit(SNIFACT_COMPUTATION, ProjectLID.RecomputeScript);
if (!task.isTaskGroup()) {
snifActEditSeq.addEdit(HCIPACmd.replaceTask(project, parent, task, group, SNIFACT_COMPUTATION));
} else {
if (groupParms.addToGroup) {
snifActEditSeq.addEdit(SNIFACTCmd.addTasksToGroup(project, group, context, SNIFACT_COMPUTATION));
} else {
snifActEditSeq.addEdit(SNIFACTCmd.addGroup(project, parent, group, SNIFACT_COMPUTATION));
}
}
snifActEditSeq.addEdit(new AUndoableEdit(ProjectLID.RecomputeScript) {
@Override
public String getPresentationName() {
return SNIFACT_COMPUTATION;
}
@Override
public void redo() {
super.redo();
group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context);
}
@Override
public void undo() {
super.undo();
group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, prevContext);
}
});
snifActEditSeq.end();
if (editSequence != null) {
editSequence.addEdit(snifActEditSeq);
}
return true;
}
Aggregations