def _get_doge_descriptors(self, word_ls):
"""
Get descriptors for a set of doge words.
eg. ['person', 'run'] -> ['much', 'very']
Args:
word_ls (list[str]): List of words to use.
Returns:
list[str]: List of doge descriptors, eg. 'much', 'very', in order.
"""
tagged_words = nltk.pos_tag(word_ls)
chosen_descriptors = []
for word, tag in tagged_words:
possible_descs = [MUCH, MANY, SUCH, SO, VERY]
if tag[0] == 'J':
possible_descs.remove(VERY)
possible_descs.remove(SO)
if len(chosen_descriptors) >= 2:
allowed_descriptors = [s for s in possible_descs if s not in chosen_descriptors[-2:]]
else:
allowed_descriptors = [s for s in possible_descs if s not in chosen_descriptors]
chosen_descriptors.append(random.choice(allowed_descriptors))
return chosen_descriptors
评论列表
文章目录