考虑以下类和函数:
class DictEntry:
term = ""
docFreq = 0
termFreq = 0
postingList = []
def __init__(self, t, df, tf, pl):
self.term = t
self.docFreq = df
self.termFreq = tf
self.postingList = pl
def insertDict(docId, token, termFreq, dictionary):
entry = dictionary.get(token)
if entry is None:
postList = []
entry = DictEntry(token, 0, 0, postList)
dictionary[token] = entry
entry.docFreq +=1
entry.postingList.extend([docId])
entry.termFreq += termFreq
函数insertDict
为不在字典中的键创建一个对象。在
在main中,我需要将dictionary
与键和类实例一起保存到一个文件中。在
目前没有回答
相关问题 更多 >
编程相关推荐