简体   繁体   English

在Google Cloud NLP API中为每个单词获取相反的极性

[英]Get polar opposite for every word in google cloud nlp api

I'm working with Google Cloud NLP Api with Python(3.6), my client asked to get polar-opposite/replaced-word-for-opposite-word for every word of provided text file. 我正在使用带有Python(3.6)的Google Cloud NLP Api,我的客户要求为提供的文本文件中的每个单词获取相反的单词/相反的单词

Here's what I have tried: 这是我尝试过的:

From views.py: 从views.py:

if form.is_valid():
    obj = form
    obj.textFile = form.cleaned_data['textFile']
    obj.save()
    text_path = os.path.join(settings.MEDIA_ROOT, 'texts/', obj.textFile.name)
    txt = Path(text_path).read_text(encoding='cp1252')
    service = discovery.build('language', 'v1beta1', credentials=credentials)
    service_request = service.documents().analyzeSentiment(
        body={
            'document': {
                'type': 'PLAIN_TEXT',
                'content': txt
            }
        }
    )
    response = service_request.execute()
    print(response)

Here's the response: 这是回应:

{'documentSentiment': {'polarity': 0.3, 'magnitude': 0.1, 'score': 0}, 'language': 'en', 'sentences': [{'text': {'content': 'hello!', 'beginOffset': -1}, 'sentiment': {'polarity': 1, 'magnitude': 0, 'score': 0}}, {'text': {'content': 'This is Abdul.', 'beginOffset': -1}, 'sentiment': {'polarity': -1, 'magnitude': 0, 'score': 0}}]}

I have explored the documentation of Google's NLP API, but couldn't find any option to get polar opposite for every word. 我已经浏览了Google NLP API的文档,但是找不到任何使每个单词都相反的选项。

Is there any possible option to achieve this? 有没有可能实现这一目标的选择?

Help me, please! 请帮帮我!

Thanks in advance! 提前致谢!

The analyzeSentiment method of NLP API, returns: NLP API的analyticsSentiment方法返回:

  • The overall sentiment of the input document. 输入文档的总体情绪。
  • The language of the text. 文字的语言。
  • A list of sentences, which contains the sentiment of each sentence. 句子列表,其中包含每个句子的情感。

It is probably easier to see those parameters in the REST API reference . REST API参考中可能更容易看到这些参数。

If the information you are looking for is not there, it probably means the feature you want is not supported yet. 如果您要查找的信息不存在,则可能意味着您所需的功能尚未受支持。

You can open a feature request describing your requirements and providing some examples of what you want to accomplish, by filling this form . 您可以通过填写此表单来打开描述您需求的功能请求,并提供一些您想完成的任务的示例。 This doesn't guarantee the feature would be included, but this is a good way to bring your requirement to Google engineers attention. 这并不保证会包含该功能,但这是使您的要求引起Google工程师注意的好方法。 Opening a feature request also allows other users to upvote the request if it is relevant for them. 如果功能请求与其他用户相关,则打开功能请求也允许其他用户投票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Google Cloud NLP API 实体情绪输出转换为 JSON - converting Google Cloud NLP API entity sentiment output to JSON NLP 字处理和 dataframe unpivot for word cloud - NLP word processing and dataframe unpivot for word cloud Python NLP:谷歌 ngram API - Python NLP: Google ngram API 有没有办法找到python的单词的反义词(具有相反含义的单词)? 你知道数据集或 nlp 工具包吗? - Is there a way to find the antonym(word with the opposite meaning) of a word with python? Do you know a dataset or an nlp toolkit? 通过Google Cloud Speech API获取每个转录单词的时间戳吗? - Getting timestamps for each transcribed word through Google Cloud Speech API? 是否可以对大量文档以批处理模式运行 Google Cloud Platform NLP-API 实体情感分析? - Is it possible to run Google Cloud Platform NLP-API entity sentiment analysis in a batch processing mode for a large number of documents? 无论如何,在Google Cloud Datastore上每次插入/删除后都会收到回调吗? - Is there anyway to get a callback after every insert/delete on Google Cloud Datastore? Python NLP:使用 TextBlob、StanfordNLP 或 Google Cloud 识别句子的时态 - Python NLP: identifying the tense of a sentence using TextBlob, StanfordNLP or Google Cloud Aspose Word Cloud API-NodeJS - Aspose Word Cloud API - NodeJS google-cloud使用python api获取实例ID和区域 - google-cloud get instance id and zone with python api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM