Exemplo n.º 1
0
  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.");
  }
Exemplo n.º 2
0
 public void showWordTriples() {
   wordTripleHistogram = calculateWordTriplesUI.getHistogram();
   showWordTriplesUI.createTable(wordTripleHistogram.keySet().size(), numCodes, triples, words);
   Iterator histoIterator = wordTripleHistogram.keySet().iterator();
   int rowNumber = 0;
   while (histoIterator.hasNext()) {
     Double key = (Double) histoIterator.next();
     showWordTriplesUI.addData(
         rowNumber, key.intValue(), ((Double) wordTripleHistogram.get(key)).intValue());
     rowNumber++;
   }
   showWordTriplesUI.setInfoLabelText(
       "There were " + (numCodes * numCodes * numCodes) + " possible word triples.");
 }