/** * @param topic * @param number of keywords required * @return key words for topic */ public List<String> forTopic(int topic, int number) { return model .getSortedWords() .get(topic) .stream() .map(IDSorter::getID) .map(model.getAlphabet()::lookupObject) .map(Object::toString) .limit(number) .collect(Collectors.toList()); } }
/** * @param topic * @param number of keywords required * @return key words for topic */ public List<String> forTopic(int topic, int number) { return model .getSortedWords() .get(topic) .stream() .map(IDSorter::getID) .map(model.getAlphabet()::lookupObject) .map(Object::toString) .limit(number) .collect(Collectors.toList()); } }
public void topicXMLReport (PrintWriter out, int numWords) { ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); out.println("<?xml version='1.0' ?>"); out.println("<topicModel>"); for (int topic = 0; topic < numTopics; topic++) { out.println(" <topic id='" + topic + "' alpha='" + alpha[topic] + "' totalTokens='" + tokensPerTopic[topic] + "'>"); int word = 1; Iterator<IDSorter> iterator = topicSortedWords.get(topic).iterator(); while (iterator.hasNext() && word <= numWords) { IDSorter info = iterator.next(); out.println(" <word rank='" + word + "'>" + alphabet.lookupObject(info.getID()) + "</word>"); word++; } out.println(" </topic>"); } out.println("</topicModel>"); }
public void topicXMLReport (PrintWriter out, int numWords) { ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); out.println("<?xml version='1.0' ?>"); out.println("<topicModel>"); for (int topic = 0; topic < numTopics; topic++) { out.println(" <topic id='" + topic + "' alpha='" + alpha[topic] + "' totalTokens='" + tokensPerTopic[topic] + "'>"); int rank = 1; Iterator<IDSorter> iterator = topicSortedWords.get(topic).iterator(); while (iterator.hasNext() && rank <= numWords) { IDSorter info = iterator.next(); out.println(" <word rank='" + rank + "' count='" + info.getWeight() + "'>" + alphabet.lookupObject(info.getID()) + "</word>"); rank++; } out.println(" </topic>"); } out.println("</topicModel>"); }
public void topicXMLReport (PrintWriter out, int numWords) { ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); out.println("<?xml version='1.0' ?>"); out.println("<topicModel>"); for (int topic = 0; topic < numTopics; topic++) { out.println(" <topic id='" + topic + "' alpha='" + alpha[topic] + "' totalTokens='" + tokensPerTopic[topic] + "'>"); int rank = 1; Iterator<IDSorter> iterator = topicSortedWords.get(topic).iterator(); while (iterator.hasNext() && rank <= numWords) { IDSorter info = iterator.next(); out.println(" <word rank='" + rank + "' count='" + info.getWeight() + "'>" + alphabet.lookupObject(info.getID()) + "</word>"); rank++; } out.println(" </topic>"); } out.println("</topicModel>"); }
/** Return an array (one element for each topic) of arrays of words, which * are the most probable words for that topic in descending order. These * are returned as Objects, but will probably be Strings. * * @param numWords The maximum length of each topic's array of words (may be less). */ public Object[][] getTopWords(int numWords) { ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); Object[][] result = new Object[ numTopics ][]; for (int topic = 0; topic < numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); // How many words should we report? Some topics may have fewer than // the default number of words with non-zero weight. int limit = numWords; if (sortedWords.size() < numWords) { limit = sortedWords.size(); } result[topic] = new Object[limit]; Iterator<IDSorter> iterator = sortedWords.iterator(); for (int i=0; i < limit; i++) { IDSorter info = iterator.next(); result[topic][i] = alphabet.lookupObject(info.getID()); } } return result; }
/** Return an array (one element for each topic) of arrays of words, which * are the most probable words for that topic in descending order. These * are returned as Objects, but will probably be Strings. * * @param numWords The maximum length of each topic's array of words (may be less). */ public Object[][] getTopWords(int numWords) { ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); Object[][] result = new Object[ numTopics ][]; for (int topic = 0; topic < numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); // How many words should we report? Some topics may have fewer than // the default number of words with non-zero weight. int limit = numWords; if (sortedWords.size() < numWords) { limit = sortedWords.size(); } result[topic] = new Object[limit]; Iterator<IDSorter> iterator = sortedWords.iterator(); for (int i=0; i < limit; i++) { IDSorter info = iterator.next(); result[topic][i] = alphabet.lookupObject(info.getID()); } } return result; }
public void printSummary(PrintWriter out, int numWords) throws IOException { Formatter buffer = new Formatter(); ArrayList<TreeSet<IDSorter>> topicSortedWords = model.getSortedWords(); buffer.format("["); // Print results for each topic for (int topic = 0; topic < model.numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); int word = 0; Iterator<IDSorter> iterator = sortedWords.iterator(); buffer.format("{\"topic\":%d, \"smoothing\":%f, \"words\":{", topic, model.alpha[topic]); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); buffer.format("\"%s\": %f", model.alphabet.lookupObject(info.getID()), info.getWeight()); if (iterator.hasNext() && word < numWords - 1) { buffer.format(","); } word++; } buffer.format ("}}"); if (topic < model.numTopics - 1) { buffer.format(","); } } buffer.format("]"); out.println(buffer); }
/** Return an array (one element for each topic) of arrays of words, which * are the most probable words for that topic in descending order. These * are returned as Objects, but will probably be Strings. * * @param numWords The maximum length of each topic's array of words (may be less). */ public Object[][] getTopWords(int numWords) { ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); Object[][] result = new Object[ numTopics ][]; for (int topic = 0; topic < numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); // How many words should we report? Some topics may have fewer than // the default number of words with non-zero weight. int limit = numWords; if (sortedWords.size() < numWords) { limit = sortedWords.size(); } result[topic] = new Object[limit]; Iterator<IDSorter> iterator = sortedWords.iterator(); for (int i=0; i < limit; i++) { IDSorter info = iterator.next(); result[topic][i] = alphabet.lookupObject(info.getID()); } } return result; }
public void printSummary(PrintWriter out, int numWords) throws IOException { Formatter buffer = new Formatter(); ArrayList<TreeSet<IDSorter>> topicSortedWords = model.getSortedWords(); buffer.format("["); // Print results for each topic for (int topic = 0; topic < model.numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); int word = 0; Iterator<IDSorter> iterator = sortedWords.iterator(); buffer.format("{\"topic\":%d, \"smoothing\":%f, \"words\":{", topic, model.alpha[topic]); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); buffer.format("\"%s\": %f", model.alphabet.lookupObject(info.getID()), info.getWeight()); if (iterator.hasNext() && word < numWords - 1) { buffer.format(","); } word++; } buffer.format ("}}"); if (topic < model.numTopics - 1) { buffer.format(","); } } buffer.format("]"); out.println(buffer); }
public String displayTopWords (int numWords, boolean usingNewLines) { StringBuilder out = new StringBuilder(); ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); // Print results for each topic for (int topic = 0; topic < numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); int word = 0; Iterator<IDSorter> iterator = sortedWords.iterator(); if (usingNewLines) { out.append (topic + "\t" + formatter.format(alpha[topic]) + "\n"); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.append(alphabet.lookupObject(info.getID()) + "\t" + formatter.format(info.getWeight()) + "\n"); word++; } } else { out.append (topic + "\t" + formatter.format(alpha[topic]) + "\t"); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.append(alphabet.lookupObject(info.getID()) + " "); word++; } out.append ("\n"); } } return out.toString(); }
public String displayTopWords (int numWords, boolean usingNewLines) { StringBuilder out = new StringBuilder(); ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); // Print results for each topic for (int topic = 0; topic < numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); int word = 0; Iterator<IDSorter> iterator = sortedWords.iterator(); if (usingNewLines) { out.append (topic + "\t" + formatter.format(alpha[topic]) + "\n"); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.append(alphabet.lookupObject(info.getID()) + "\t" + formatter.format(info.getWeight()) + "\n"); word++; } } else { out.append (topic + "\t" + formatter.format(alpha[topic]) + "\t"); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.append(alphabet.lookupObject(info.getID()) + " "); word++; } out.append ("\n"); } } return out.toString(); }
public String displayTopWords (int numWords, boolean usingNewLines) { StringBuilder out = new StringBuilder(); ArrayList<TreeSet<IDSorter>> topicSortedWords = getSortedWords(); // Print results for each topic for (int topic = 0; topic < numTopics; topic++) { TreeSet<IDSorter> sortedWords = topicSortedWords.get(topic); int word = 0; Iterator<IDSorter> iterator = sortedWords.iterator(); if (usingNewLines) { out.append (topic + "\t" + formatter.format(alpha[topic]) + "\n"); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.append(alphabet.lookupObject(info.getID()) + "\t" + formatter.format(info.getWeight()) + "\n"); word++; } } else { out.append (topic + "\t" + formatter.format(alpha[topic]) + "\t"); while (iterator.hasNext() && word < numWords) { IDSorter info = iterator.next(); out.append(alphabet.lookupObject(info.getID()) + " "); word++; } out.append ("\n"); } } return out.toString(); }
for (TreeSet<IDSorter> topic : model.getSortedWords()) { int wordCount = 0;
topicSortedWords = model.getSortedWords();
topicSortedWords = model.getSortedWords();
topicSortedWords = model.getSortedWords();
for (TreeSet<IDSorter> topic : model.getSortedWords()) { Map<String, Double> topicWords = new HashMap<>(nWords);
ArrayList<TreeSet<IDSorter>> topicSortedWords = model.getSortedWords();
TreeSet<IDSorter> sortedWords = model.getSortedWords().get(topicNum); Iterator<IDSorter> iterator = sortedWords.iterator();