Search in sources :

Example 6 with ITermSimilarity

use of edu.cmu.cs.hcii.cogtool.model.ITermSimilarity in project cogtool by cogtool.

the class ProjectController method createGenerateDictionaryAction.

protected IListenerAction createGenerateDictionaryAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            Design d = seln.getSelectedDesign();
            boolean hasDict = false;
            ITermSimilarity defaultAlg = ISimilarityDictionary.DEFAULT_ALG;
            if (d != null) {
                ISimilarityDictionary dict = (ISimilarityDictionary) d.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
                if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
                    hasDict = true;
                    defaultAlg = dict.getCurrentAlgorithm();
                }
            } else {
                // No design selected, so just show the compute options
                hasDict = true;
            }
            ProjectInteraction.GenerateEntriesData requestData = requestGenerateParms(generateEntriesMessage, defaultAlg, hasDict);
            if (requestData == null) {
                return false;
            }
            GenerateDictEntriesWorkThread workThread = new GenerateDictEntriesWorkThread(interaction, d, tasks, project, undoMgr, requestData);
            CogTool.logger.info(String.format("Generating dictionary for design %s in project %s.", d.getName(), getProject().getName()));
            ThreadManager.startNewThread(workThread);
            return true;
        }
    };
}
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) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) ProjectInteraction(edu.cmu.cs.hcii.cogtool.ui.ProjectInteraction)

Example 7 with ITermSimilarity

use of edu.cmu.cs.hcii.cogtool.model.ITermSimilarity in project cogtool by cogtool.

the class DictionaryEditorController method createAddNewEntryAction.

protected IListenerAction createAddNewEntryAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return DictionaryEditorUI.ComputeSimilarityParms.class;
        }

        public boolean performAction(Object actionParms) {
            final DictionaryEditorUI.ComputeSimilarityParms parms = (DictionaryEditorUI.ComputeSimilarityParms) actionParms;
            final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
            final double oldSimilarity = pendingEntry.getSimilarity();
            final double similarity;
            if (checkNewEntry(parms.goalString, parms.searchString, parms.algorithm)) {
                interaction.reportProblem(ERROR_TITLE, ENTRY_EXISTS);
                return false;
            }
            if (parms.algorithm == ITermSimilarity.MANUAL) {
                similarity = oldSimilarity;
            } else {
                similarity = computeSimilarity(parms.goalString, parms.searchString, parms.algorithm);
            }
            final String oldGoal = pendingEntry.getDictEntry().goalWord;
            final String oldSearch = pendingEntry.getDictEntry().searchWord;
            pendingEntry.clear();
            final DictValue value = new DictValue(similarity);
            dictionary.setSimilarity(parms.goalString, parms.searchString, parms.algorithm, value, parms.rowIndex);
            undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.CreateNewEntry) {

                @Override
                public String getPresentationName() {
                    return CREATE_ROW;
                }

                @Override
                public void redo() {
                    super.redo();
                    pendingEntry.clear();
                    dictionary.setSimilarity(parms.goalString, parms.searchString, parms.algorithm, value, parms.rowIndex);
                }

                @Override
                public void undo() {
                    super.undo();
                    dictionary.removeEntry(parms.rowIndex);
                    pendingEntry.setGoal(oldGoal);
                    pendingEntry.setSearch(oldSearch);
                    pendingEntry.setAlgorithm(oldAlg);
                    pendingEntry.setSimilarity(oldSimilarity);
                }
            });
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) DictValue(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 8 with ITermSimilarity

use of edu.cmu.cs.hcii.cogtool.model.ITermSimilarity in project cogtool by cogtool.

the class DictionaryEditorController method createSetSimilarityAction.

protected IListenerAction createSetSimilarityAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return DictionaryEditorUI.SetSimilarityParms.class;
        }

        public boolean performAction(Object actionParms) {
            DictionaryEditorUI.SetSimilarityParms parms = (DictionaryEditorUI.SetSimilarityParms) actionParms;
            DictEntry entry = dictionary.getEntry(parms.rowIndex);
            if (entry == null) {
                final double oldSimil = pendingEntry.getSimilarity();
                final double newSimil = parms.similarity;
                if (PrecisionUtilities.withinEpsilon(oldSimil, newSimil, 0.001)) {
                    interaction.setStatusMessage(SIMIL_UNCHANGED);
                    return true;
                }
                final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
                pendingEntry.setSimilarity(newSimil);
                pendingEntry.setAlgorithm(ITermSimilarity.MANUAL);
                undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.SetSimilarity) {

                    @Override
                    public String getPresentationName() {
                        return SET_SIMILARITY;
                    }

                    @Override
                    public void redo() {
                        super.redo();
                        pendingEntry.setSimilarity(newSimil);
                        pendingEntry.setAlgorithm(ITermSimilarity.MANUAL);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        pendingEntry.setSimilarity(oldSimil);
                        pendingEntry.setAlgorithm(oldAlg);
                    }
                });
                return true;
            }
            if (PrecisionUtilities.withinEpsilon(dictionary.getValue(entry).similarity, parms.similarity, 0.001)) {
                interaction.setStatusMessage(SIMIL_UNCHANGED);
                return true;
            }
            setSimilarity(parms.rowIndex, parms.similarity, ITermSimilarity.MANUAL, undoMgr);
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) DictEntry(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry) PendingDictEntry(edu.cmu.cs.hcii.cogtool.ui.PendingDictEntry) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Aggregations

ITermSimilarity (edu.cmu.cs.hcii.cogtool.model.ITermSimilarity)8 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)4 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 ISimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)3 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)3 DictionaryEditorUI (edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI)3 PendingDictEntry (edu.cmu.cs.hcii.cogtool.ui.PendingDictEntry)3 DictValue (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue)2 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 Design (edu.cmu.cs.hcii.cogtool.model.Design)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)1 SimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1 ProjectInteraction (edu.cmu.cs.hcii.cogtool.ui.ProjectInteraction)1 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)1 ComboWithEnableFix (edu.cmu.cs.hcii.cogtool.util.ComboWithEnableFix)1 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)1