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;
}
};
}
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;
}
};
}
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;
}
};
}
Aggregations