Search in sources :

Example 1 with ISimilarityDictionary

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;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 2 with ISimilarityDictionary

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;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ArrayList(java.util.ArrayList) SNIFACTGroupParameters(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTGroupParameters) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SNIFACTParameters(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTParameters) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTExecContext(edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 3 with ISimilarityDictionary

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;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) SimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)

Example 4 with ISimilarityDictionary

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);
}
Also used : ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)

Example 5 with ISimilarityDictionary

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);
        }
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) SimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet)

Aggregations

ISimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)11 Design (edu.cmu.cs.hcii.cogtool.model.Design)5 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)4 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)3 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)3 ITermSimilarity (edu.cmu.cs.hcii.cogtool.model.ITermSimilarity)3 SimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary)3 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)3 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)2 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)2 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)1 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)1 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 SNIFACTExecContext (edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext)1 SNIFACTPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo)1