优先队列会对放进队列的元素进行排序,用法。
要对对象重载小于号,也就是def __lt__(self, other):
import queue
class Sentence_similarity():
def __init__(self,sentence,title_words_set):
self.sentence = sentence
self.sentence_words_set = eliminate_stopwords_punctuations(sentence)
self.title_words_set = title_words_set
self.similarity_with_title = calc_similarity(self.sentence_words_set, title_words_set)
def __lt__(self, other):
return self.similarity_with_title > other.similarity_with_title
similarity_prio_queue = queue.PriorityQueue()
similarity_prio_queue.put(Sentence_similarity(sentence,title_words_set))