Search in sources :

Example 1 with ITermSimilarity

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

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

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

the class DictionaryEditorController method setSimilarity.

protected void setSimilarity(final int rowIndex, final double similarity, final ITermSimilarity algorithm, IUndoableEditSequence editSeq) {
    DictEntry entry = dictionary.getEntry(rowIndex);
    final String goal = entry.goalWord;
    final String search = entry.searchWord;
    DictValue oldV = dictionary.getValue(entry);
    final DictValue oldValue = new DictValue(oldV.similarity, oldV.editedDate);
    final DictValue newValue = new DictValue(similarity);
    if (PrecisionUtilities.withinEpsilon(oldValue.similarity, similarity, 0.001)) {
        interaction.setStatusMessage(SIMIL_UNCHANGED);
        return;
    }
    final ITermSimilarity oldAlg = entry.algorithm;
    dictionary.setSimilarity(goal, search, algorithm, newValue, rowIndex);
    editSeq.addEdit(new AUndoableEdit(DictionaryEditorLID.SetSimilarity) {

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

        @Override
        public void redo() {
            super.redo();
            dictionary.setSimilarity(goal, search, algorithm, newValue, rowIndex);
        }

        @Override
        public void undo() {
            super.undo();
            dictionary.setSimilarity(goal, search, oldAlg, oldValue, rowIndex);
        }
    });
}
Also used : ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) DictValue(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue) 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)

Example 4 with ITermSimilarity

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

the class DictionaryEditorController method createSetAlgorithmAction.

protected IListenerAction createSetAlgorithmAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            DictionaryEditorUI.SetAlgorithmParms parms = (DictionaryEditorUI.SetAlgorithmParms) actionParms;
            double similarity;
            if (parms.rowIndices.length == 0) {
                interaction.reportProblem(ERROR_TITLE, NO_SELECTION);
                return false;
            }
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(SET_ALGORITHM, DictionaryEditorLID.SetAlgorithm);
            for (int rowIndice : parms.rowIndices) {
                DictEntry entry = dictionary.getEntry(rowIndice);
                if (entry == null) {
                    final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
                    final double oldSimilarity = pendingEntry.getSimilarity();
                    final ITermSimilarity newAlg = parms.algorithm;
                    boolean equal = (newAlg == null) ? oldAlg == null : newAlg.equals(oldAlg);
                    if (equal) {
                        interaction.setStatusMessage(ALG_UNCHANGED);
                        continue;
                    }
                    pendingEntry.setAlgorithm(newAlg);
                    pendingEntry.setSimilarity(ITermSimilarity.UNKNOWN);
                    editSeq.addEdit(new AUndoableEdit(DictionaryEditorLID.SetAlgorithm) {

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

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

                        @Override
                        public void undo() {
                            super.undo();
                            pendingEntry.setAlgorithm(oldAlg);
                            pendingEntry.setSimilarity(oldSimilarity);
                        }
                    });
                    interaction.setStatusMessage(ALG_CHANGED);
                    continue;
                }
                if (parms.algorithm.equals(entry.algorithm)) {
                    interaction.setStatusMessage(ALG_UNCHANGED);
                    continue;
                }
                if (checkNewEntry(entry.goalWord, entry.searchWord, parms.algorithm)) {
                    interaction.reportProblem(ERROR_TITLE, ENTRY_EXISTS);
                    continue;
                }
                if (parms.algorithm != ITermSimilarity.MANUAL) {
                    similarity = computeSimilarity(entry.goalWord, entry.searchWord, parms.algorithm);
                } else {
                    similarity = dictionary.getValue(entry).similarity;
                }
                setSimilarity(rowIndice, similarity, parms.algorithm, editSeq);
            }
            editSeq.end();
            if (editSeq.isSignificant()) {
                undoMgr.addEdit(editSeq);
                interaction.setStatusMessage(ALG_CHANGED);
            }
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) 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)

Example 5 with ITermSimilarity

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

the class SNIFACTDialog method addMoreFields.

@Override
protected void addMoreFields() {
    super.addMoreFields();
    responseBox.setEditable(false);
    Label lbl = new Label(dialog, SWT.NONE);
    lbl.setText(L10N.get("PM.NumTrials", "Number of Trials") + ": ");
    GridData lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_END);
    lbl.setLayoutData(lblLayout);
    numRunsSpinner = new Spinner(dialog, SWT.NONE);
    numRunsSpinner.setMinimum(1);
    numRunsSpinner.setMaximum(1000);
    numRunsSpinner.setSelection(defaultParameters.numRuns);
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    lblLayout.grabExcessHorizontalSpace = true;
    lblLayout.horizontalSpan = 3;
    numRunsSpinner.setLayoutData(lblLayout);
    lbl = new Label(dialog, SWT.NONE);
    lbl.setText(L10N.get("PM.KValue", "Eagerness to satisfy (smaller is more eager)") + ": ");
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    lbl.setLayoutData(lblLayout);
    kValueSpinner = new Spinner(dialog, SWT.NONE);
    kValueSpinner.setMinimum(1);
    kValueSpinner.setMaximum(999);
    kValueSpinner.setSelection(defaultParameters.kValue);
    kValueSpinner.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (addGroupMode == ENABLED) {
                boolean equal = kValueSpinner.getSelection() == defaultParameters.kValue;
                addToGroup.setEnabled(equal);
                if (!equal) {
                    addToGroup.setSelection(false);
                }
            }
        }
    });
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    lblLayout.grabExcessHorizontalSpace = true;
    lblLayout.horizontalSpan = 3;
    kValueSpinner.setLayoutData(lblLayout);
    lbl = new Label(dialog, SWT.NONE);
    lbl.setText(L10N.get("PM.StartFrame", "Start Frame") + ": ");
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_END);
    lbl.setLayoutData(lblLayout);
    startFrameCombo = new ComboWithEnableFix(dialog, SWT.DROP_DOWN | SWT.READ_ONLY);
    startFrameCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (addGroupMode == ENABLED) {
                int selIndex = startFrameCombo.getSelectionIndex();
                String frameName = startFrameCombo.getItem(selIndex);
                String defaultName = defaultParameters.startFrame;
                boolean equal = frameName.equals(defaultName);
                addToGroup.setEnabled(equal);
                if (!equal) {
                    addToGroup.setSelection(false);
                }
            }
        }
    });
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    lblLayout.grabExcessHorizontalSpace = true;
    lblLayout.horizontalSpan = 3;
    startFrameCombo.setLayoutData(lblLayout);
    lbl = new Label(dialog, SWT.NONE);
    lbl.setText(L10N.get("PM.TargetFrames", "Target Frames") + ": ");
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_END);
    lbl.setLayoutData(lblLayout);
    targetFrameList = new org.eclipse.swt.widgets.List(dialog, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    targetFrameList.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            okButton.setEnabled(targetFrameList.getSelectionCount() > 0);
            if (addGroupMode == ENABLED) {
                // Need to test whether the list of selected frame names
                // is identical (except for order) to the list of frame
                // names specified in defaultParameters.targetFrames, so
                // check if they are the same size and then test whether
                // any names in one list don't appear in the other
                String[] targets = targetFrameList.getSelection();
                java.util.List<String> defaultTargets = defaultParameters.targetFrames;
                boolean equal = targets.length == defaultTargets.size();
                if (equal) {
                    for (int i = 0; i < targets.length; i++) {
                        String curDefault = defaultTargets.get(i);
                        if (!(curDefault.equals(targets[i]))) {
                            equal = false;
                        }
                    }
                }
                addToGroup.setEnabled(equal);
                if (!equal) {
                    addToGroup.setSelection(false);
                }
            }
        }
    });
    for (int i = 0; i < sortedFrames.size(); i++) {
        String name = sortedFrames.get(i).getName();
        String display = SWTStringUtil.insertEllipsis(name, WIDTH, StringUtil.NO_FRONT, SWTStringUtil.DEFAULT_FONT);
        startFrameCombo.add(display);
        targetFrameList.add(display);
        if (name.equals(defaultParameters.startFrame)) {
            startFrameCombo.select(i);
        }
        if (defaultParameters.targetFrames.contains(name)) {
            targetFrameList.select(i);
        }
    }
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    lblLayout.grabExcessHorizontalSpace = true;
    lblLayout.horizontalSpan = 3;
    lblLayout.heightHint = 100;
    targetFrameList.setLayoutData(lblLayout);
    if (algorithmSet.size() > 1) {
        lbl = new Label(dialog, SWT.NONE);
        lbl.setText(L10N.get("PM.Algorithm", "Algorithm") + ": ");
        lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_END);
        lbl.setLayoutData(lblLayout);
        algCombo = new ComboWithEnableFix(dialog, SWT.DROP_DOWN | SWT.READ_ONLY);
        algCombo.add(L10N.get("PM.All", "All"));
        int i = 0;
        algArray[i++] = null;
        int selectIndex = 0;
        Iterator<ITermSimilarity> algs = algorithmSet.iterator();
        while (algs.hasNext()) {
            ITermSimilarity alg = algs.next();
            algArray[i] = alg;
            algCombo.add(DictionaryEditorUIModel.getAlgLabel(alg));
            if (alg.getClass().isInstance(defaultParameters.algorithm)) {
                selectIndex = i;
            }
            i++;
        }
        algCombo.select(selectIndex);
        lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        lblLayout.grabExcessHorizontalSpace = true;
        lblLayout.horizontalSpan = 3;
        algCombo.setLayoutData(lblLayout);
    }
    numRunsSpinner.forceFocus();
    if (addGroupMode != NONE) {
        addToGroup = new Button(dialog, SWT.CHECK);
        addToGroup.setText(L10N.get("PM.AddToGroup", "Add scripts to existing task group"));
        addToGroup.setEnabled(true);
        addToGroup.setSelection(true);
        lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        lblLayout.grabExcessHorizontalSpace = true;
        lblLayout.horizontalSpan = 3;
        addToGroup.setLayoutData(lblLayout);
    }
    exportOnly = new Button(dialog, SWT.CHECK);
    exportOnly.setText(L10N.get("PM.ExportOnly", "Only export model, do not run it"));
    exportOnly.setEnabled(true);
    exportOnly.setSelection(false);
    lblLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    lblLayout.grabExcessHorizontalSpace = true;
    lblLayout.horizontalSpan = 3;
    exportOnly.setLayoutData(lblLayout);
}
Also used : Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) List(org.eclipse.swt.widgets.List) ComboWithEnableFix(edu.cmu.cs.hcii.cogtool.util.ComboWithEnableFix)

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