Skip to content

Commit

Permalink
unified test_hdpmodel
Browse files Browse the repository at this point in the history
  • Loading branch information
markroxor committed Oct 18, 2016
1 parent ac4e93b commit 098be5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
5 changes: 4 additions & 1 deletion gensim/models/hdpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ def __init__(self, dictionary=None, topic_data=None, topic_file=None, style=None

self.style = style

def print_topics(self, num_topics=10, num_words=10):
return self.show_topics(num_topics, num_words, True)

def show_topics(self, num_topics=10, num_words=10, log=False, formatted=True):
shown = []
if num_topics < 0:
Expand Down Expand Up @@ -610,4 +613,4 @@ def format_topic(self, topic_id, topic_terms):
fmt = 'topic %i:\n%s' % (topic_id, fmt)

return fmt
#endclass HdpTopicFormatter
# endclass HdpTopicFormatter
1 change: 0 additions & 1 deletion gensim/test/test_basemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import six


class TestBaseTopicModel():
def testPrintTopic(self):
topics = self.model.show_topics(formatted=True)
Expand Down
16 changes: 5 additions & 11 deletions gensim/test/test_hdpmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from gensim.corpora import mmcorpus, Dictionary
from gensim.models import hdpmodel
from gensim import matutils
from gensim.test import test_basemodel


module_path = os.path.dirname(__file__) # needed because sample data files are located in the same folder
Expand All @@ -47,22 +48,15 @@ def testfile():
return os.path.join(tempfile.gettempdir(), 'gensim_models.tst')


class TestHdpModel(unittest.TestCase):
class TestHdpModel(unittest.TestCase, test_basemodel.TestBaseTopicModel):
def setUp(self):
self.corpus = mmcorpus.MmCorpus(datapath('testcorpus.mm'))
self.class_ = hdpmodel.HdpModel
self.model = self.class_(corpus, id2word=dictionary)

def testShowTopics(self):
topics = self.model.show_topics(formatted=False, num_topics=20, num_words=20)

for topic_no, topic in topics:
self.assertTrue(isinstance(topic_no, int))
self.assertTrue(isinstance(topic, list))
for k, v in topic:
self.assertTrue(isinstance(k, six.string_types))
self.assertTrue(isinstance(v, float))

def testShowTopic(self):
# TODO create show_topic in HdpModel and then test
return

if __name__ == '__main__':
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.DEBUG)
Expand Down

0 comments on commit 098be5f

Please sign in to comment.