MalletLdaTopicModelUtils { public static List<Map<String, Double>> getTopWords(File modelFile, int nWords, boolean normalize) throws IOException { LOGGER.info("Reading model file " + modelFile + "..."); ParallelTopicModel model; try { model = ParallelTopicModel.read(modelFile); } catch (Exception e) { throw new IOException(e); } Alphabet alphabet = model.getAlphabet(); List<Map<String, Double>> topics = new ArrayList<>(model.getNumTopics()); for (TreeSet<IDSorter> topic : model.getSortedWords()) { Map<String, Double> topicWords = new HashMap<>(nWords); for (IDSorter id : topic) { double weight = normalize ? id.getWeight() / alphabet.size() : id.getWeight(); String word = (String) alphabet.lookupObject(id.getID()); topicWords.put(word, weight); if (topicWords.size() >= nWords) { break; } } topics.add(topicWords); } return topics; }  static List<Map<String, Double>> getTopWords(File modelFile, int nWords,
            boolean normalize); static void printTopicWords(File modelFile, File targetFile, int nWords);  }
@Test public void testGetTopWords() throws Exception { File modelFile = new File(testContext.getTestOutputFolder(), "model"); MalletLdaUtil.trainModel(modelFile); int nWords = 10; List<Map<String, Double>> topWords = MalletLdaTopicModelUtils .getTopWords(modelFile, nWords, false); assertEquals(N_TOPICS, topWords.size()); for (Map<String, Double> topic : topWords) { assertEquals(nWords, topic.size()); } }