本文整理汇总了Python中nltk.probability.FreqDist.has_key方法的典型用法代码示例。如果您正苦于以下问题:Python FreqDist.has_key方法的具体用法?Python FreqDist.has_key怎么用?Python FreqDist.has_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.probability.FreqDist
的用法示例。
在下文中一共展示了FreqDist.has_key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import has_key [as 别名]
def build(master_dict, path, l, fh):
master = ()
master = sorted(master_dict)
m_dict = OrderedDict()
for item in master:
m_dict[item] = 0
fhl=open(path,"r")
lines = fhl.read().split()
#lines = re.sub("[()+.,\']",'',lines)
#words = nltk.tokenize.word_tokenize(lines)
bi_lines = bigrams(lines)
temp = FreqDist(bi_lines)
fhl.close()
#temp = get_bigram_file(path)
for key in m_dict.iterkeys():
if temp.has_key(key):
m_dict[key] = temp[key]
else:
m_dict[key] = 0
#m_dict.update(temp)
values = list()
for val in m_dict.itervalues():
values.append(str(val))
#print len(values)
fh.write(l+","+",".join(values))
fh.write('\n')
示例2: featureList
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import has_key [as 别名]
def featureList(corpus):
featList = []
for post in corpus:
listItem = [0]*noFeat
fileFreqDist = FreqDist()
fileFreqDist = nltk.FreqDist(nltk.word_tokenize(post))
i =0
for key in trainKeys:
if fileFreqDist.has_key(key):
listItem[i] = fileFreqDist.get(key)
i=i+1
featList.append(listItem)
return featList
示例3: featureList
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import has_key [as 别名]
def featureList(corpus):
featList = []
for trFile in corpus.fileids():
listItem = [0]*noFeat
fileFreqDist = FreqDist()
fileFreqDist = nltk.FreqDist(corpus.words(trFile))
i =0
for key in trainKeys:
if fileFreqDist.has_key(key):
listItem[i] = fileFreqDist.get(key)
i=i+1
featList.append(listItem)
return featList
示例4: createFeatures
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import has_key [as 别名]
def createFeatures(sentVect, ordList):
noFeat = len(ordList)
featList = []
for post in sentVect:
listItem = [0]*noFeat
fileFreqDist = FreqDist()
fileFreqDist = nltk.FreqDist(nltk.word_tokenize(post))
i =0
for key in ordList:
if fileFreqDist.has_key(key):
listItem[i] = fileFreqDist.get(key)
i=i+1
featList.append(listItem)
return featList