private void loadAndShowHyps() { if (selectHypFileUI.getSelectedHypFile() != null) { hypotheses = selectHypFileUI.getLoadedHyps(); Iterator hypothesisIterator = hypotheses.iterator(); showLoadedHypsUI.createTable(hypotheses.size()); int rowNumber = 0; while (hypothesisIterator.hasNext()) { Hypothesis hypothesis = (Hypothesis) hypothesisIterator.next(); showLoadedHypsUI.addHyp( rowNumber, hypothesis.getNumber(), hypothesis.getHypothesisText(), hypothesis.getScore()); rowNumber++; } showLoadedHypsUI.setInfoLabelText( "You selected " + selectHypFileUI.getSelectedHypFile().getName().toString() + " as the input file." + " I found " + hypotheses.size() + " hypotheses."); } else { showLoadedHypsUI.setInfoLabelText("No hypothesis file selected."); } }
public void saveTriplesAsArff() { TreeMap tripleMap = new TreeMap(); if (hypotheses == null) { saveWordTriplesAsArffUI.setInfoLabelText("No hyps loaded!"); hypotheses = getHypsFromFile(); } if ((wordCodeMap == null) || (wordCodeMap.size() == 0)) { wordCodeMap = new HashMap(); saveWordTriplesAsArffUI.setInfoLabelText("No word list loaded!"); ArrayList wordList = getWordListFromFile(); for (int i = 0; i < wordList.size(); i++) { Word word = (Word) wordList.get(i); wordCodeMap.put(word.getText(), new Integer(word.getCode())); } } if (showWordTriplesUI.getTripleMap().size() == 0) { saveWordTriplesAsArffUI.setInfoLabelText("No word triples loaded!"); tripleMap = getTriplesFromFile(); } else { tripleMap = showWordTriplesUI.getTripleMap(); } 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)); } } saveWordTriplesAsArffUI.createTable(scoreMap.size()); Iterator scoreIterator = scoreMap.keySet().iterator(); int rowNumber = 0; while (scoreIterator.hasNext()) { Integer currentScore = (Integer) scoreIterator.next(); saveWordTriplesAsArffUI.addScore( rowNumber, currentScore.intValue(), ((Integer) scoreCounts.get(currentScore)).intValue()); rowNumber++; } saveWordTriplesAsArffUI.setHypsAndScores(hypotheses, wordCodeMap, tripleMap); saveWordTriplesAsArffUI.setInfoLabelText("Optionally edit the scores and" + " save the file."); }
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!"); } }