def label_topic_by_number_of_words(cls, topic_description, n_words=5):
"""
Try to disambiguate a topic considering top k words in its description
:param n_words:
:param topic_description: is a list of pairs (word, word_probability)
:return: list of strings, possible wikipedia pages
"""
words = [t[0] for i, t in enumerate(topic_description) if i < n_words]
if len(words) == 0:
# if no words are over the threshold, take the first
words = [topic_description[0][0]]
res = wikipedia.search(' '.join(words))
return res
评论列表
文章目录