Esempio n. 1
0
  /**
   * Read the vocabulary from the file.
   *
   * @param filePath
   * @return
   */
  public static Vocabulary getVocabularyFromFile(String filePath) {
    Vocabulary vocab = new Vocabulary();

    ArrayList<String> lines = FileReaderAndWriter.readFileAllLines(filePath);
    for (String line : lines) {
      String[] splits = line.trim().split(":");
      ExceptionUtility.assertAsException(splits.length == 2);
      int wordid = Integer.parseInt(splits[0]);
      String wordstr = splits[1];
      vocab.addWordstrWithWordid(wordid, wordstr);
    }

    return vocab;
  }
Esempio n. 2
0
 private void printVocabulary(Vocabulary vocab, String filepath) {
   vocab.printToFile(filepath);
 }