時產生的錯誤是:Python的鍵錯誤
File "/home/tweet_v8/tweetSum/Summarizer/Sentence.py", line 42, in _tfIdfSentence
w.append(self.lsa.getCell(doc, self.vectorSpace.keywords()[(term,)]))
KeyError: (u'l.a.',)
的功能是這樣寫的:
# tf-idf computation for one sentence
def _tfIdfSentence (self, sent, doc):
w = []
for term in sent:
w.append(self.lsa.getCell(doc, self.vectorSpace.keywords()[(term,)]))
#print sent
if max(w) > 0:
#print [float(i)/max(w) for i in w], w, doc, sent
return [float(i)/max(w) for i in w]
else:
return [0]
我不知道什麼是這行代碼的問題。
w.append(self.lsa.getCell(doc, self.vectorSpace.keywords()[(term,)]))
有誰知道如何解決這個問題?
我們不能幫你這個辦法。你試圖獲得的關鍵不存在,因爲我們不知道你的字典是什麼樣的,我不認爲這很容易幫助你。 – aIKid
你試過這個嗎? 'w.append(self.lsa.getCell(doc,self.vectorSpace.keywords()[term]))' –