当前位置: 首页>>代码示例>>Python>>正文


Python FreqDist.has_key方法代码示例

本文整理汇总了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')
开发者ID:ravikiranp,项目名称:MovieReviewClassifier,代码行数:31,代码来源:build_bigram_features.py

示例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
开发者ID:abhinavmishra590,项目名称:NLPbased-Automated_Tagging_System,代码行数:18,代码来源:SVM.py

示例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
开发者ID:ashish0038,项目名称:sentimentAnalysis,代码行数:18,代码来源:SVM.py

示例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
开发者ID:abhinavmishra590,项目名称:NLPbased-Automated_Tagging_System,代码行数:21,代码来源:SVM.py


注:本文中的nltk.probability.FreqDist.has_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。