Search in sources :

Example 1 with ISitedTermSimilarity

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

the class ProjectInteraction method requestGenerateDictionaryParms.

/**
     * Request new information (name, device type set) about a new or
     * existing dictionary.
     */
public ProjectInteraction.GenerateEntriesData requestGenerateDictionaryParms(String request, ITermSimilarity defaultAlg, boolean hasDict) {
    String defaultSite = "";
    String defaultSpace = "";
    String defaultURL = "";
    if (defaultAlg instanceof ISitedTermSimilarity) {
        defaultSite = ((ISitedTermSimilarity) defaultAlg).getContextSite();
    } else if (defaultAlg instanceof LSASimilarity) {
        LSASimilarity algLSA = (LSASimilarity) defaultAlg;
        defaultSpace = algLSA.getSpace();
        defaultURL = algLSA.getURL();
    } else if (defaultAlg instanceof GensimLSASimilarity) {
        GensimLSASimilarity algLSA = (GensimLSASimilarity) defaultAlg;
        defaultSpace = algLSA.getSpace();
        defaultURL = algLSA.getURL();
    }
    GenerateDictEntriesDialog dictDialog = new GenerateDictEntriesDialog(window, request, defaultAlg, defaultSite, defaultSpace, defaultURL, hasDict);
    ProjectInteraction.GenerateEntriesData data = null;
    boolean notDone = true;
    while (notDone) {
        Object response = dictDialog.open();
        if ((response != null) && response.equals(WindowUtil.PromptDialog.OK)) {
            data = dictDialog.getData();
            notDone = false;
        } else {
            notDone = false;
        }
    }
    return data;
}
Also used : GensimLSASimilarity(edu.cmu.cs.hcii.cogtool.model.GensimLSASimilarity) LSASimilarity(edu.cmu.cs.hcii.cogtool.model.LSASimilarity) ISitedTermSimilarity(edu.cmu.cs.hcii.cogtool.model.ISitedTermSimilarity) GensimLSASimilarity(edu.cmu.cs.hcii.cogtool.model.GensimLSASimilarity)

Example 2 with ISitedTermSimilarity

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

the class DictionaryEditorUI method updateView.

protected void updateView() {
    Table dictTable = view.getDictTable();
    int selectionCount = 0;
    try {
        selectionCount = dictTable.getSelectionCount();
    } catch (SWTException e) {
        return;
    }
    if (selectionCount == 1) {
        int index = dictTable.getSelectionIndex();
        DictEntry entry = dictionary.getEntry(index);
        if (entry != null) {
            String url = null;
            String space = null;
            if (entry.algorithm instanceof ISitedTermSimilarity) {
                url = ((ISitedTermSimilarity) entry.algorithm).getContextSite();
                view.setURLEnabled(true);
                view.setSpaceEnabled(false);
            } else if (entry.algorithm instanceof LSASimilarity) {
                LSASimilarity lsa = (LSASimilarity) entry.algorithm;
                space = lsa.getSpace();
                url = lsa.getURL();
                if (url == null) {
                    url = LSASimilarity.DEFAULT_LSA_URL;
                }
                view.setURLEnabled(true);
                view.setSpaceEnabled(true);
            } else if (entry.algorithm instanceof GensimLSASimilarity) {
                GensimLSASimilarity lsa = (GensimLSASimilarity) entry.algorithm;
                space = lsa.getSpace();
                url = lsa.getURL();
                if (url == null) {
                    url = GensimLSASimilarity.DEFAULT_LSA_URL;
                }
                view.setURLEnabled(true);
                view.setSpaceEnabled(true);
            } else {
                view.setURLEnabled(false);
                view.setSpaceEnabled(false);
            }
            view.setURL(url);
            view.setSpace(space);
        } else {
            TableItem row = dictTable.getItem(index);
            Combo c = (Combo) row.getData();
            int seln = c.getSelectionIndex();
            boolean isLSA = (seln == DictionaryEditorUIModel.LSA_INDEX);
            view.setURLEnabled((seln == DictionaryEditorUIModel.GOOGLE_WORD_INDEX) || (seln == DictionaryEditorUIModel.GOOGLE_PHRASE_INDEX) || isLSA);
            view.setSpaceEnabled(isLSA);
        }
    } else {
        // disable if 0 or more than 1 are selected
        view.setURL(null);
        view.setSpace(null);
        view.setURLEnabled(false);
        view.setSpaceEnabled(false);
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) SWTException(org.eclipse.swt.SWTException) TableItem(org.eclipse.swt.widgets.TableItem) DictEntry(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry) GensimLSASimilarity(edu.cmu.cs.hcii.cogtool.model.GensimLSASimilarity) LSASimilarity(edu.cmu.cs.hcii.cogtool.model.LSASimilarity) Combo(org.eclipse.swt.widgets.Combo) ISitedTermSimilarity(edu.cmu.cs.hcii.cogtool.model.ISitedTermSimilarity) Point(org.eclipse.swt.graphics.Point) GensimLSASimilarity(edu.cmu.cs.hcii.cogtool.model.GensimLSASimilarity)

Example 3 with ISitedTermSimilarity

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

the class DictionaryEditorCmd method exportDictionaryToCSV.

public static boolean exportDictionaryToCSV(ISimilarityDictionary dictionary, Interaction interaction) {
    File dest = interaction.selectCSVFileDest(DEFAULT_DICT_PREFIX + "" + nextNewDictSuffix++);
    if (dest == null) {
        return false;
    }
    if (dictionary.size() == 0) {
        interaction.reportProblem("Export Dictionary", "Selected dictionary is empty");
        return true;
    }
    FileWriter fw = null;
    BufferedWriter buffer = null;
    try {
        fw = new FileWriter(dest);
        buffer = new BufferedWriter(fw);
        // first write out header, version, and column titles
        CSVSupport.writeCell(ISimilarityDictionary.COGTOOL_DICT_HEADER, buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(DICT_CSV_VERSION_0, buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Term", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell("Display Labels", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell("Algorithm", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell("Limiting URL", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell("Similarity", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell("Date computed", buffer);
        CSVSupport.addLineEnding(buffer);
        Iterator<DictEntry> values = dictionary.getEntries().iterator();
        while (values.hasNext()) {
            DictEntry entry = values.next();
            DictValue value = dictionary.getValue(entry);
            String url = "";
            if (entry.algorithm instanceof ISitedTermSimilarity) {
                url = ((ISitedTermSimilarity) entry.algorithm).getContextSite();
                if (url == null) {
                    url = "";
                }
            }
            String simil = toString(value.similarity);
            CSVSupport.writeCell(entry.goalWord, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(entry.searchWord, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(getAlgorithmName(entry.algorithm), buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(url, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(simil, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(value.editedDate.toString(), buffer);
            CSVSupport.addLineEnding(buffer);
        }
    } catch (IOException e) {
        interaction.reportProblem("File I/O Error", e.getMessage());
        return false;
    } finally {
        try {
            if (buffer != null) {
                buffer.close();
            }
            if (fw != null) {
                fw.close();
            }
        } catch (IOException e) {
            interaction.reportProblem("File I/O Error on Close", e.getMessage());
            return false;
        }
    }
    interaction.setStatusMessage("Export successful");
    return true;
}
Also used : DictValue(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue) FileWriter(java.io.FileWriter) DictEntry(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry) IOException(java.io.IOException) ISitedTermSimilarity(edu.cmu.cs.hcii.cogtool.model.ISitedTermSimilarity) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

ISitedTermSimilarity (edu.cmu.cs.hcii.cogtool.model.ISitedTermSimilarity)3 GensimLSASimilarity (edu.cmu.cs.hcii.cogtool.model.GensimLSASimilarity)2 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)2 LSASimilarity (edu.cmu.cs.hcii.cogtool.model.LSASimilarity)2 DictValue (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SWTException (org.eclipse.swt.SWTException)1 Point (org.eclipse.swt.graphics.Point)1 Combo (org.eclipse.swt.widgets.Combo)1 Table (org.eclipse.swt.widgets.Table)1 TableItem (org.eclipse.swt.widgets.TableItem)1