python - Python机器学习对句子中的单词进行分类
问题描述
我想使用人工智能和机器学习技术制作个人助理。我正在使用 Python 3.7,我有一个问题。
软件启动时,首先会询问用户名。我希望它获取用户名。
in = input('Hey, what is your name?')
#some classifier things
#...
print = input('Nice to meet you ' + in + '!')
但是如果用户输入一个句子,我想正确地知道名字。这是一个例子:
Hey, what is your name?
John
Nice to meet you John!
但即使有人这样输入,我也想得到名字:
Hey, what is your name?
It's John.
Nice to meet you John!
但我不明白我怎么才能得到用户的名字。我想我应该对句子中的单词进行分类,但我不知道。你能帮我吗?
解决方案
你需要得到专有名词。下面的代码做到了:
from nltk.tag import pos_tag
sentence = " It's John"
tagged_sent = pos_tag(sentence.split())
propernouns = [word for word,pos in tagged_sent if pos == 'NNP']
推荐阅读
- docker - 如何为非 docker Jenkins master 创建 docker slave 构建
- php - 提交表单按钮后重定向到 2 个不同的页面
- python - 预期 2 个值得到一个函数
- cassandra-3.0 - 如何在 Embedded-Cassandra 中获取特定版本的 Cassandra
- sql - 为“stat”多次指定了“30”列
- java - 为什么即使启用了 Wi-Fi 呼叫,方法 telephonyManager.getVoiceNetworkType() 也会返回 Network_LTE 的值?
- c# - AWS Lambda 函数在 .Net 核心中调用自身
- typescript - 打字稿什么是更好的方法类或接口
- asp.net - 如何从 ajax 选项卡容器中获取客户端 ID
- mysql - mysql中只有一条记录的“limit 10”和“limit 100”有什么区别吗?