python中如何判断词性

您所在的位置:网站首页 怎样辨别英语单词的词性 python中如何判断词性

python中如何判断词性

2024-07-14 16:39| 来源: 网络整理| 查看: 265

在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:

<


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3