/** * 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; }
private void printVocabulary(Vocabulary vocab, String filepath) { vocab.printToFile(filepath); }