python – 如何制作NLTK pos_tag单词而不是字符?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 如何制作NLTK pos_tag单词而不是字符?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1465字,纯文字阅读大概需要3分钟。
内容图文
![python – 如何制作NLTK pos_tag单词而不是字符?](/upload/InfoBanner/zyjiaocheng/753/567e1f4f508d440cbf98081265ded54c.jpg)
我有这个代码在一个句子中找到名词和动词.
# -*- coding: utf-8 -*-
from nltk.corpus import wordnet as wn
from nltk import pos_tag
import nltk
syno =[]
sentence = '''His father suggested he study to become a parson instead, but Darwin was far more inclined to study natural history.DarwinDar·win (d?r'w?n),Charles Robert.1809-1882.British naturalist who revolutionized the study of biology with his theory ofevolutionbased on natural selection
Like several scientists before him, Darwin believed all the life on earth evolved (developed gradually) over millions of years from a few common ancestors.'''
sent = pos_tag(word_tokenize(sentence))
这回来了
[('H', 'NNP'), ('e', 'VBP'), ('l', 'NN'), ('l', 'NN'), ('o', 'NN'), (' ', ':'), ('m', 'NN'), ('y', 'NN'), (' ', ':'), ('n', 'NN'), ('a', 'DT'), ('m', 'NN'), ('e', 'NN'), (' ', ':'), ('i', 'PRP'), ('s', 'VBZ'), (' ', ':'), ('A', 'DT'), ('b', 'NN'), ('h', 'NN'), ('i', 'PRP'), ('s', 'VBZ'), ('h', 'JJ'), ('e', 'NN'), ('k', 'NN'), (' ', ':'), ('M', 'NNP'), ('i', 'PRP'), ('t', 'VBP'), ('r', 'JJ'), ('a', 'DT')]
我希望它能用文字操作,而不是字符!我该怎么做呢?
解决方法:
您需要先进行标记:
>>> from nltk import pos_tag, word_tokenize
>>> sentence = "Hello my name is Derek. I live in Salt Lake city."
>>> pos_tag(word_tokenize(sentence))
[('Hello', 'NNP'), ('my', 'PRP$'), ('name', 'NN'), ('is', 'VBZ'), ('Derek.', 'NNP'), ('I', 'PRP'), ('live', 'VBP'), ('in', 'IN'), ('Salt', 'NNP'), ('Lake', 'NNP'), ('city', 'NN'), ('.', '.')]
内容总结
以上是互联网集市为您收集整理的python – 如何制作NLTK pos_tag单词而不是字符?全部内容,希望文章能够帮你解决python – 如何制作NLTK pos_tag单词而不是字符?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。