@Test public void toWordsTest() throws IOException { LmVocabulary vocabulary = new LmVocabulary("a", "b", "c", "d", "e"); int[] indexes = vocabulary.toIndexes("a", "e", "b"); Assert.assertEquals("a e b", Joiner.on(" ").join(vocabulary.toWords(indexes))); indexes = vocabulary.toIndexes("a", "e", "foo"); Assert.assertEquals("a e <unk>", Joiner.on(" ").join(vocabulary.toWords(indexes))); }
public String[] toWords(int... indexes) { String[] words = new String[indexes.length]; int k = 0; for (int index : indexes) { if (contains(index)) { words[k++] = vocabulary.get(index); } else { Log.warn("Out of bounds word index is used:" + index); words[k++] = unknownWord; } } return words; }
LmVocabulary { public String[] toWords(int... indexes) { String[] words = new String[indexes.length]; int k = 0; for (int index : indexes) { if (contains(index)) { words[k++] = vocabulary.get(index); } else { Log.warn("Out of bounds word index is used:" + index); words[k++] = unknownWord; } } return words; } }
LmVocabulary { public String[] toWords(int... indexes) { String[] words = new String[indexes.length]; int k = 0; for (int index : indexes) { if (contains(index)) { words[k++] = vocabulary.get(index); } else { Log.warn("Out of bounds word index is used:" + index); words[k++] = unknownWord; } } return words; } LmVocabulary(String... vocabulary);  LmVocabulary(List<String> vocabulary); private  LmVocabulary(RandomAccessFile raf); private  LmVocabulary(DataInputStream dis); }
LmVocabulary { public String[] toWords(int... indexes) { String[] words = new String[indexes.length]; int k = 0; for (int index : indexes) { if (contains(index)) { words[k++] = vocabulary.get(index); } else { Log.warn("Out of bounds word index is used:" + index); words[k++] = unknownWord; } } return words; } LmVocabulary(String... vocabulary);  LmVocabulary(List<String> vocabulary); private  LmVocabulary(RandomAccessFile raf); private  LmVocabulary(DataInputStream dis); static LmVocabulary loadFromBinary(File binaryVocabularyFile); static LmVocabulary loadFromBinary(Path binaryVocabularyFilePath); static LmVocabulary loadFromRandomAccessFile(RandomAccessFile raf); static LmVocabulary loadFromDataInputStream(DataInputStream dis); static LmVocabulary loadFromUtf8File(File utfVocabularyFile); static Builder builder(); static LmVocabulary intersect(LmVocabulary v1, LmVocabulary v2); void saveBinary(File file); void saveBinary(DataOutputStream dos); int size(); boolean containsUnknown(int... gramIds); boolean containsSuffix(); boolean containsPrefix(); String getWord(int index); int indexOf(String word); int getSentenceStartIndex(); int getSentenceEndIndex(); int getUnknownWordIndex(); String getUnknownWord(); String getSentenceStart(); String getSentenceEnd(); Iterable<Integer> alphabeticallySortedWordsIds(Locale locale); Iterable<Integer> alphabeticallySortedWordsIds(); Iterable<String> words(); Iterable<String> wordsSorted(); Iterable<String> wordsSorted(Locale locale); String getWordsString(int... indexes); boolean containsAll(int... indexes); boolean contains(int index); boolean containsAll(String... words); boolean contains(String word); long encodeTrigram(int g0, int g1, int g2); long encodeTrigram(int... triGram); int[] toIndexes(String... words); int[] toIndexes(String[] history, String word); int[] toIndexes(int[] history, String word); String[] toWords(int... indexes); }
LmVocabulary { public String[] toWords(int... indexes) { String[] words = new String[indexes.length]; int k = 0; for (int index : indexes) { if (contains(index)) { words[k++] = vocabulary.get(index); } else { Log.warn("Out of bounds word index is used:" + index); words[k++] = unknownWord; } } return words; } LmVocabulary(String... vocabulary);  LmVocabulary(List<String> vocabulary); private  LmVocabulary(RandomAccessFile raf); private  LmVocabulary(DataInputStream dis); static LmVocabulary loadFromBinary(File binaryVocabularyFile); static LmVocabulary loadFromBinary(Path binaryVocabularyFilePath); static LmVocabulary loadFromRandomAccessFile(RandomAccessFile raf); static LmVocabulary loadFromDataInputStream(DataInputStream dis); static LmVocabulary loadFromUtf8File(File utfVocabularyFile); static Builder builder(); static LmVocabulary intersect(LmVocabulary v1, LmVocabulary v2); void saveBinary(File file); void saveBinary(DataOutputStream dos); int size(); boolean containsUnknown(int... gramIds); boolean containsSuffix(); boolean containsPrefix(); String getWord(int index); int indexOf(String word); int getSentenceStartIndex(); int getSentenceEndIndex(); int getUnknownWordIndex(); String getUnknownWord(); String getSentenceStart(); String getSentenceEnd(); Iterable<Integer> alphabeticallySortedWordsIds(Locale locale); Iterable<Integer> alphabeticallySortedWordsIds(); Iterable<String> words(); Iterable<String> wordsSorted(); Iterable<String> wordsSorted(Locale locale); String getWordsString(int... indexes); boolean containsAll(int... indexes); boolean contains(int index); boolean containsAll(String... words); boolean contains(String word); long encodeTrigram(int g0, int g1, int g2); long encodeTrigram(int... triGram); int[] toIndexes(String... words); int[] toIndexes(String[] history, String word); int[] toIndexes(int[] history, String word); String[] toWords(int... indexes); static final String DEFAULT_SENTENCE_BEGIN_MARKER; static final String DEFAULT_SENTENCE_END_MARKER; static final String DEFAULT_UNKNOWN_WORD; }