private void scoreBySingleWords() { if (hypotheses == null) { scoreHypsByWordsUI.setInfoLabelText("No hyps loaded!"); hypotheses = getHypsFromFile(); } if (showWordsUI.getWordListTableModel() == null) { scoreHypsByWordsUI.setInfoLabelText("No word list loaded!"); ArrayList allWords = getWordListFromFile(); showWordsUI.createTable(allWords.size()); for (int i = 0; i < allWords.size(); i++) { Word word = (Word) allWords.get(i); showWordsUI.addWord(i, word.getText(), word.getCount(), word.getGroup(), word.getCode()); } showWordsUI.setInfoLabelText("I found " + allWords.size() + " words."); } // load the scoring table as a HashMap Object[][] wordListTable = showWordsUI.getWordListTableModel().getAllWords(); int wordCount = showWordsUI.getWordListTableModel().getRowCount(); wordCodeMap = new HashMap(); for (int i = 0; i < wordCount; i++) { if (((Integer) wordListTable[i][3]).intValue() != 0) { wordCodeMap.put(wordListTable[i][0], wordListTable[i][3]); } } // make list of words words = new String[wordCodeMap.size() + 1]; Iterator wordIterator = wordCodeMap.keySet().iterator(); while (wordIterator.hasNext()) { String currentWord = (String) wordIterator.next(); int code = ((Integer) wordCodeMap.get(currentWord)).intValue(); words[code] = currentWord; } // score the hyps and display scoreHypsByWordsUI.createTable(hypotheses.size(), words); for (int i = 0; i < hypotheses.size(); i++) { Hypothesis hypothesis = (Hypothesis) hypotheses.get(i); int[] singleWordScores = hypothesis.scoreBySingleWords(wordCodeMap); scoreHypsByWordsUI.addHyp(i, hypothesis.getHypothesisText(), singleWordScores); } scoreHypsByWordsUI.setInfoLabelText( "I scored " + hypotheses.size() + " hypotheses with " + wordCodeMap.size() + " words."); }
public void saveSinglesAsArff() { if (scoreHypsByWordsUI.getScoresTableModel() != null) { // tally up all the possible scores Iterator hypIterator = hypotheses.iterator(); TreeMap scoreMap = new TreeMap(); TreeMap scoreCounts = new TreeMap(); while (hypIterator.hasNext()) { Hypothesis hypothesis = (Hypothesis) hypIterator.next(); Integer score = new Integer(hypothesis.getScore()); scoreMap.put(score, score); if (!scoreCounts.containsKey(score)) { scoreCounts.put(score, new Integer(1)); } else { int oldCount = ((Integer) scoreCounts.get(score)).intValue(); scoreCounts.put(score, new Integer(oldCount + 1)); } } saveSingleWordAsArffUI.createTable(scoreMap.size()); Iterator scoreIterator = scoreMap.keySet().iterator(); int rowNumber = 0; while (scoreIterator.hasNext()) { Integer currentScore = (Integer) scoreIterator.next(); saveSingleWordAsArffUI.addScore( rowNumber, currentScore.intValue(), ((Integer) scoreCounts.get(currentScore)).intValue()); rowNumber++; } saveSingleWordAsArffUI.setHypsAndScores(hypotheses, scoreHypsByWordsUI.getScoresTableModel()); saveSingleWordAsArffUI.setInfoLabelText("Optionally edit the scores and" + " save the file."); } else { saveSingleWordAsArffUI.setInfoLabelText("No hyps have been scored yet!"); } }