Esempio n. 1
0
  private void convertKeys2csv(String fileName, Date dateObj) {
    DateFormat df = new SimpleDateFormat("MM-dd-yy-HH-mm-ss");

    BufferedReader br;
    BufferedWriter bw;
    try {
      br = new BufferedReader(new FileReader(new File(fileName + ".txt")));
      bw =
          new BufferedWriter(
              new FileWriter(new File(fileName + "-" + df.format(dateObj) + ".csv")));

      String currentLine = "Topic,Keywords";
      bw.write(currentLine);
      bw.newLine();
      while ((currentLine = br.readLine()) != null) {
        currentLine = currentLine.replace('\t', ',');
        List<String> wordList = Arrays.asList(currentLine.split(","));
        bw.write(wordList.get(0) + "," + wordList.get(2));
        bw.newLine();
      }
      br.close();
      bw.close();
      ConsoleView.printlInConsoleln(
          "Created topic keys file " + fileName + "-" + df.format(dateObj) + ".csv");
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 2
0
  private void convertComposition2csv(String fileName, Date dateObj) {
    DateFormat df = new SimpleDateFormat("MM-dd-yy-HH-mm-ss");

    BufferedReader br;
    BufferedWriter bw;
    try {
      br = new BufferedReader(new FileReader(new File(fileName + ".txt")));
      bw =
          new BufferedWriter(
              new FileWriter(new File(fileName + "-" + df.format(dateObj) + ".csv")));

      String currentLine = br.readLine();
      currentLine = "Number,File Name";
      for (int i = 0; i < numTopics; i++) {
        currentLine = currentLine + "," + "Topic " + i + " Probability";
      }
      bw.write(currentLine);
      bw.newLine();
      while ((currentLine = br.readLine()) != null) {
        currentLine = currentLine.replace('\t', ',');
        List<String> wordList = Arrays.asList(currentLine.split(","));

        HashMap<String, String> probabilities = new HashMap<String, String>();

        for (int i = 2; i < wordList.size(); i = i + 2) {
          probabilities.put(wordList.get(i), wordList.get(i + 1));
        }
        currentLine = wordList.get(0) + "," + wordList.get(1);
        // bw.write(wordList.get(0)+","+wordList.get(1));
        for (int i = 0; i < numTopics; i++) {
          String keyVal = probabilities.get(Integer.toString(i));
          currentLine = currentLine + "," + keyVal;
        }
        bw.write(currentLine);
        bw.newLine();

        ConsoleView.printlInConsoleln(fileName + "-" + df.format(dateObj) + ".csv");
      }
      br.close();
      bw.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }