获取句子的主题或关键词

问题描述 投票:0回答:1

大家早上好

你们中有人知道有一个工具或 API 或其他东西可以将句子作为输入和输出,并给出该句子的主题或关键字吗?

我在在线演示中尝试了TextRazor,它工作得很好,就像你在屏幕截图中看到的那样 但是当我在 python 代码中用作库时,即使对于演示中使用的句子,它也总是给我一个空白列表 这是我的Python代码:

import textrazor
import ssl
textrazor.api_key ="bdd69bdc3f91045cdb6d4261d39df34d887278602cb8f60401b7eb0b"
client = textrazor.TextRazor(extractors=["entities", "topics"])
client.set_cleanup_mode("cleanHTML")
client.set_classifiers(["textrazor_newscodes"])
sentence = "Adam Hill,b It's Super Bowl Sunday  pastors. Get your Jesus Jukes ready! Guilt is an awesome motivator! #sarcasm"
response = client.analyze(sentence)
print(sentence)
print(len(response.topics()))
entities = list(response.entities())
print(len(entities))
for topic in response.topics():
    if topic.score > 0.3:
        print (topic.label)

它给我的实体和主题长度为零

有人建议我使用 OpenNlp,但我不知道如何提取主题和关键字,如果你们有任何教程或说明,请帮助我

提前谢谢你

python nlp data-analysis
1个回答
1
投票

您必须删除该行

client.set_cleanup_mode("cleanHTML")
。那么它应该可以正常工作。

据我了解 cleanup_mode,它会将您的文本视为 html。由于您的示例文本不是 html,因此它不会在 html 标签之间找到任何原始文本。

© www.soinside.com 2019 - 2024. All rights reserved.