本文整理汇总了Python中nltk.probability.FreqDist.remove方法的典型用法代码示例。如果您正苦于以下问题:Python FreqDist.remove方法的具体用法?Python FreqDist.remove怎么用?Python FreqDist.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.probability.FreqDist
的用法示例。
在下文中一共展示了FreqDist.remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findKeyword
# 需要导入模块: from nltk.probability import FreqDist [as 别名]
# 或者: from nltk.probability.FreqDist import remove [as 别名]
def findKeyword(fname,apply=False,eventflg =False):
with open(fname ,'r', encoding='utf-8', errors='ignore') as file : #Opening file
text=file.read().lower()
#finding tokens using regular expression
tokens=re.findall('[a-zA-Z0-9]+',text)
#tokens = [token for token in tokens]
#Removing stopwords from tokens
#Stopwords defined in Python std library
stopw = set(stopwords.words('english'))
tokens = [token for token in tokens]
#Removing stopwords from tokens
#Stopwords are defined in stopwords.txt
tokenscopy=tokens.copy()
for token in tokenscopy:
if token in stopw:
tokens.remove(token)
elif token in stopwd:
tokens.remove(token)
#Finding mostcommon stopwords and their count
tokens = FreqDist(tokens).most_common()
if eventflg:
tokenscopy = tokens.copy()
for token in tokenscopy:
if token in dictionary:
tokens.remove(token)
if apply:
return tokens,text
keyword=[token[0] for token in tokens]
return keyword