Skip to content

Commit

Permalink
Merge pull request #693 from ajdapretnar/topic-tag-words
Browse files Browse the repository at this point in the history
Topic Modeling: Remove tags from display of topics
  • Loading branch information
PrimozGodec authored Aug 19, 2021
2 parents 03df971 + 25a61da commit f306d03
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions orangecontrib/text/widgets/owtopicmodeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ def apply(self):

def on_done(self, corpus):
self.Outputs.corpus.send(corpus)
self.topic_desc.show_model(self.model)
pos_tags = self.corpus.pos_tags is not None
self.topic_desc.show_model(self.model, pos_tags=pos_tags)
if self.__pending_selection:
self.topic_desc.select(self.__pending_selection)
self.__pending_selection = None
Expand Down Expand Up @@ -277,15 +278,17 @@ def send_topic_by_id(self, topic_id=None):

class TopicViewerTreeWidgetItem(QTreeWidgetItem):
def __init__(self, topic_id, words, weights, parent,
color_by_weights=False):
color_by_weights=False, pos_tags=False):
super().__init__(parent)
self.topic_id = topic_id
self.words = words
self.weights = weights
self.color_by_weights = color_by_weights
self.pos_tags = pos_tags

self.setText(0, '{:d}'.format(topic_id + 1))
self.setText(1, ', '.join(self._color(word, weight)
self.setText(1, ', '.join(self._color(word.rsplit("_", 1)[0], weight) if
self.pos_tags else self._color(word, weight)
for word, weight in zip(words, weights)))

def _color(self, word, weight):
Expand Down Expand Up @@ -322,15 +325,16 @@ def resize_columns(self):
for i in range(self.columnCount()):
self.resizeColumnToContents(i)

def show_model(self, topic_model):
def show_model(self, topic_model, pos_tags=False):
self.clear()
if topic_model.model:
for i in range(topic_model.num_topics):
words, weights = topic_model.get_top_words_by_id(i)
if words:
it = TopicViewerTreeWidgetItem(
i, words, weights, self,
color_by_weights=topic_model.has_negative_weights)
color_by_weights=topic_model.has_negative_weights,
pos_tags=pos_tags)
self.addTopLevelItem(it)

self.resize_columns()
Expand Down

0 comments on commit f306d03

Please sign in to comment.