【发布时间】:2016-06-09 01:53:46
【问题描述】:
我正在使用来自Expanding English language contractions in Python 的 Alko 代码
我添加了一些代码。我不明白为什么我会得到这个 =>KeyError: "没有"
import re
import csv
fileLocation = 'test.csv'
cList = {
"ain't": "am not",
"aren't": "are not",
"can't": "cannot",
"can't've": "cannot have",
"'cause": "because",
"could've": "could have",
"couldn't": "could not",
"couldn't've": "could not have",
"didn't": "did not",
"doesn't": "does not",
}
R = re.compile('(%s)' % '|'.join(cList.keys()),re.IGNORECASE)
read = csv.reader(open(fileLocation))
aList = []
def expandContractions(text,R=R):
def replace(match):
return cList[match.group(0)]
return R.sub(replace, text)
for i in read:
aList.append(i[5])
for j in aList:
print(expandContractions(j))
【问题讨论】:
-
print(expandContractions(j.lower()))
标签: python-3.x nlp nltk supervised-learning