Search in sources :

Example 1 with SimilarityDictionary

use of edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary 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 2 with SimilarityDictionary

use of edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary 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)

Example 3 with SimilarityDictionary

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

the class ProjectController method openDictionaryEditor.

protected void openDictionaryEditor(Design design) {
    ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
    if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
        dict = new SimilarityDictionary();
        design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
    }
    DictionaryEditorController.openController(dict, design, project);
}
Also used : ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) SimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)

Aggregations

ISimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)3 SimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary)3 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 ITermSimilarity (edu.cmu.cs.hcii.cogtool.model.ITermSimilarity)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)1 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)1 HashSet (java.util.HashSet)1