本文整理汇总了Python中nltk.stem.porter.PorterStemmer.lemmatize方法的典型用法代码示例。如果您正苦于以下问题:Python PorterStemmer.lemmatize方法的具体用法?Python PorterStemmer.lemmatize怎么用?Python PorterStemmer.lemmatize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.stem.porter.PorterStemmer
的用法示例。
在下文中一共展示了PorterStemmer.lemmatize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NLTKTokenizer
# 需要导入模块: from nltk.stem.porter import PorterStemmer [as 别名]
# 或者: from nltk.stem.porter.PorterStemmer import lemmatize [as 别名]
class NLTKTokenizer(object):
"""
http://scikit-learn.org/stable/modules/feature_extraction.html
http://stackoverflow.com/questions/15547409/how-to-get-rid-of-punctuation-using-nltk-tokenizer
http://nltk.org/api/nltk.tokenize.html
"""
def __init__(self):
#self.wnl = LancasterStemmer()
self.wnl = PorterStemmer()#best so far
#self.wnl = GermanStemmer()
#self.wnl = EnglishStemmer(ignore_stopwords=True)
#self.wnl = WordNetStemmer()
def __call__(self, doc):
words=[word_tokenize(t) for t in sent_tokenize(doc)]
words=[item for sublist in words for item in sublist]
if hasattr(self.wnl,'stem'):
words=[self.wnl.stem(t) for t in words]
else:
words=[self.wnl.lemmatize(t) for t in words]
return words