当前位置:   article > 正文

python中如何判断词性_Python nltk 英文词性分析

python nlp词性检测

在NLP任务中,常需要分析单词的词性,借助nltk库的pos_tag方法可以较好地实现。

以下是一个例子:

import nltk

line = 'i love this world which was beloved by all the people here'

tokens = nltk.word_tokenize(line)

# ['i', 'love', 'this', 'world', 'which', 'was', 'beloved', 'by',

# 'all', 'the', 'people', 'here']

pos_tags = nltk.pos_tag(tokens)

# [('i', 'RB'), ('love', 'VBP'), ('this', 'DT'), ('world', 'NN'), ('which', 'WDT'),

# ('was', 'VBD'), ('beloved', 'VBN'), ('by', 'IN'), ('all', 'PDT'), ('the', 'DT'),

# ('people', 'NNS'), ('here', 'RB')]

for word,pos in pos_tags:

<
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/355515
推荐阅读
相关标签
  

闽ICP备14008679号