首页 > 解决方案 > 如何使用 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'])

标签: searchnlpnltktextblobnatural-language-processing

解决方案


快速提问:

为什么您希望“Bill Smith”出现在对 Will Smith 的同一搜索中?我相信他们是两个不同的艺术家。

选项 1 如果我正确理解您的问题,我相信您可能想在艺术家的名字上使用正则表达式。

例如 name LIKE %(任何拳头名字)% + smith

我假设如果搜索返回“Will Sutton”,则搜索在您的情况下无效。


选项 2

你想要类似于 SpaCy 的 sense2vec 功能的东西吗?它返回具有百分比相似度的单词。例如,您可以设置一个只返回结果 >70% 的目标。 https://explosion.ai/demos/sense2vec

如果这没有用,请再次解释您的问题;更详细一点(例如是什么构成了有效的搜索案例)

谢谢


推荐阅读