use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class ProjectController method createDuplicateDesignAction.
protected IListenerAction createDuplicateDesignAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
}
public boolean performAction(Object prms) {
DesignSelectionState seln = (DesignSelectionState) prms;
Design design = seln.getSelectedDesign();
// Can only duplicate if a design is currently selected.
if (design == null) {
interaction.protestNoSelection();
return false;
}
// Determine new name
String copyName = NamedObjectUtil.makeNameUnique(design.getName(), project.getDesigns());
Design designCopy = design.duplicate(copyName);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
designCopy.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict.duplicate());
}
ProjectCmd.addNewDesign(project, designCopy, seln.getSelectedDesign(), DUPLICATE_DESIGN, undoMgr);
Map<ITaskDesign, TaskApplication> associatedTAs = project.taskApplicationsForDesign(design);
duplicateTaskApplications(designCopy, associatedTAs);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary 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;
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class ProjectController method createImportDictionaryAction.
protected IListenerAction createImportDictionaryAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectSelectionState.class;
}
public boolean performAction(Object actionParms) {
ProjectSelectionState seln = (ProjectSelectionState) actionParms;
Design design = seln.getSelectedDesign();
if (design == null) {
interaction.reportProblem("Import Dictionary", "No design is selected");
return false;
}
ISimilarityDictionary prevDict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
// Leonghwee says he wants the imported dictionary to replace
// the old one
ISimilarityDictionary dict = new SimilarityDictionary();
design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
boolean success = DictionaryEditorCmd.importDictionary(design, dict, prevDict, interaction, undoMgr, null);
if (success) {
DictionaryEditorController.openController(dict, design, project);
}
return success;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class GenerateDictEntriesWorkThread method openDictionaryEditor.
protected void openDictionaryEditor(Design d) {
ISimilarityDictionary dict = (ISimilarityDictionary) d.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
return;
}
ITermSimilarity oldAlg = dict.getCurrentAlgorithm();
dict.setCurrentAlgorithm(requestData.algorithm);
DictionaryEditorController dec = DictionaryEditorController.openController(dict, d, project);
DictEntryGenerator generator = generatorMap.get(d);
generator.insertEntries(dec, requestData.computeAll, oldAlg, requestData.algorithm, project, editSequence);
}
use of edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary in project cogtool by cogtool.
the class DictEntryGenerator method generateEntries.
// TODO This whole mishmash of different flavors of progress bars, and
// Cancelables/Stoppables/Pausables is a mess. We shouldn't be using
// the type hierarchy to fiddle this stuff. Instead we should have a
// single interface for control of a background operation, subsuming
// all of Cancelable, Stoppable and Pausable, and a single ProgressBar
// type that takes a bunch of flags indicating what buttons it should
// display.
public void generateEntries(String goal, ITermSimilarity alg, Cancelable cancelable, Stoppable stoppable, boolean computeAll, List<String> computeErrors, ProgressCallback progressCallback) {
// TODO figure out how to deal with this for real, long term
// goal = clean(goal);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
dict = new SimilarityDictionary();
design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
}
int initialSize = dict.size();
ITermSimilarity.Continuable cont = new ITermSimilarity.Continuable(cancelable, stoppable);
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext() && cont.isContinuing()) {
Frame f = frames.next();
generateOneEntry(f.getSpeakerText(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
Set<SimpleWidgetGroup> swGrps = new HashSet<SimpleWidgetGroup>();
Iterator<IWidget> widgets = f.getWidgets().iterator();
while (widgets.hasNext() && cont.isContinuing()) {
IWidget w = widgets.next();
generateOneEntry(w.getTitle(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
if (!cont.isContinuing()) {
break;
}
generateOneEntry(w.getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
SimpleWidgetGroup swg = w.getParentGroup();
if (swg != null) {
swGrps.add(swg);
}
}
Iterator<FrameElementGroup> groups = f.getEltGroups().iterator();
while (groups.hasNext() && cont.isContinuing()) {
generateOneEntry(groups.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
Iterator<SimpleWidgetGroup> swgIter = swGrps.iterator();
while (swgIter.hasNext() && cont.isContinuing()) {
generateOneEntry(swgIter.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
}
if (stoppable.isStopped()) {
// Clean out the last entry if we were stopped, as it may not be
// correct. But only if we've added something.
int n = dict.size();
if (n > initialSize) {
dict.removeEntry(n - 1);
}
}
}
Aggregations