search - 如何使用 NLP 技术创建搜索,以搜索输入的命名实体以及它可能具有的任何潜在名称变体?
问题描述
我目前正在使用 TextBlob 制作一个聊天机器人,到目前为止,我一直在使用名词短语提取来提取命名实体并找到 pos 标签 NNP。当输入诸如“Will Smith 的最新单曲?”之类的测试用户问题时,我正确地检索到了“Will Smith”。但我希望不仅能够搜索“will smith”,还能够搜索“william smith”、“bill smith”、“willie smith”、“billy smith”——基本上是其他众所周知的英文名称变体。我正在使用 Spotipy API,因为我正在尝试检索 Spotify 艺术家。我目前在 PyCharm 中所做的事情:
while True:
response = input()
searchQuery = TextBlob(response)
who = []
for item, tag in searchQuery.tags:
if tag == "NNP":
for nounPhrase in searchQuery.noun_phrases:
np = TextBlob(nounPhrase)
if item.lower() in np.words:
if nounPhrase not in who:
who.append(nounPhrase)
print(who)
if who:
for name in who:
if spotifyObject.search(name, 50, 0, 'artist', None):
searchResults = spotifyObject.search(name, 50, 0, 'artist', None)
artists = searchResults['artists']['items']
for a in artists:
print(a['name'])
解决方案
快速提问:
为什么您希望“Bill Smith”出现在对 Will Smith 的同一搜索中?我相信他们是两个不同的艺术家。
选项 1 如果我正确理解您的问题,我相信您可能想在艺术家的名字上使用正则表达式。
例如 name LIKE %(任何拳头名字)% + smith
我假设如果搜索返回“Will Sutton”,则搜索在您的情况下无效。
选项 2
你想要类似于 SpaCy 的 sense2vec 功能的东西吗?它返回具有百分比相似度的单词。例如,您可以设置一个只返回结果 >70% 的目标。 https://explosion.ai/demos/sense2vec
如果这没有用,请再次解释您的问题;更详细一点(例如是什么构成了有效的搜索案例)
谢谢
推荐阅读
- list - 使用 JPA 查询从存储库中获取地图中的数据
- python - 从纯文本获取 Xpath
- next.js - 无法从包中覆盖样式化组件的 SSR 样式
- unity3d - 场景中的空游戏对象作为层次分隔符
- linux - 如何从 Outlook 类型的电子邮件地址中对全名进行排序
- php - ow 为每种语言使用不同的代码
- javascript - 未捕获的错误:根据提供的形状 [1024,3],张量应该有 3072 个值,但有 30 个
- python - 如何从 Python 中的大 Json 文件制作存储桶?
- c++ - 在向量c ++中按值对向量进行排序
- android - 是否可以在 Flutter 中发送 Facebook 游戏请求?