Python自然語言處理——nltk庫入門之詞性標註

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import nltk.stem as ns

words = ['table', 'probably', 'wolves', 'playing',
         'is', 'dog', 'the', 'beaches', 'grounded'
         'dreamt', 'envision']

lemmatizer = ns.WordNetLemmatizer()
for word in words:
    n_lemma = lemmatizer.lemmatize(word, pos='n')
    v_lemma = lemmatizer.lemmatize(word, pos='v')
    print('%20s %20s %20s' % (word, n_lemma, v_lemma))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章