[英]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方法返回:
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.