Commit 7fadc4f8 authored by Kathryn Elliott's avatar Kathryn Elliott

Clean up the functions that print the topics.

parent 59eb2107
......@@ -320,17 +320,23 @@ class TopicModel:
print(model.get_document_topics(self._bow[n]))
print()
def print_topics(self, topic_id, topn=10, compact=True):
def print_topics(self, topn=20, compact=True):
""" Print the top terms for each topic.
"""
for topic_id, max_topic in self._topics_generator():
self.print_topic(topic_id, topn=topn, compact=compact)
def print_topic(self, topic_id, topn=20, compact=True):
""" Print the top terms for all topics.
"""
if compact == True:
for topic in self._models[topic_id].show_topics(topn):
print(topic)
self._logging.info(topic)
else:
for n in range(topic_id):
self._logging.info("############## {0} ({1}) ##############".format(topic_id, n))
self._logging.info("{:20} {}".format(u'term', u'frequency') + u'\n')
self._logging.info("Terms per topic {0} (of {1})".format(n + 1, topic_id))
self._logging.info("{:20} {}".format(u'term', u'frequency'))
for term, frequency in self._models[topic_id].show_topic(n - 1, topn):
self._logging.info("{:20} {:.3f}".format(term, round(frequency, 3)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment