my rawdata.json
file
{"Inputs":[
{"Id":"1","Text":"I loved the food at this restaurant"},
{"Id":"2","Text":"I loved the food at sadthis restaurant"},
{"Id":"3","Text":"I loved the food at tsadhis restaurant"},
......,
{"Id":"100","Text":"I hated the decor"}
],
"StopPhrases":[
"restaurant", “visitor"
]}
i read this file in my module
file_path = '/home/sujith/pylzdata/rawdata.json'
f = open(file_path, 'r')
input_texts = f.read()
and this
print('Starting topic detection.')
uri = base_url + 'text/analytics/v2.0/topics'
req = urllib2.Request(uri, input_texts, headers)
response_headers = urllib2.urlopen(req).info()
uri = response_headers['operation-location']
error output
Starting topic detection. Traceback (most recent call last):
File "./lzdata.py", line 25, in
response_headers = urllib2.urlopen(req).info()
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 410, in open
response = meth(req, response)
File "/usr/lib/python2.7/urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.7/urllib2.py", line 448, in error
return self._call_chain(*args)
File "/usr/lib/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
sources: https://text-analytics-demo.azurewebsites.net/Home/SampleCode, https://learn.microsoft.com/en-us/azure/machine-learning/machine-learning-apps-text-analytics#topic-detection-apis
Looks like your input format is wrong. Should be documents
and not Inputs
:
{
"documents": [
{
"id": "1",
"text": "First document"
},
...
{
"id": "100",
"text": "Final document"
}
],
"stopWords": [
"issue", "error", "user"
],
"stopPhrases": [
"Microsoft", "Azure"
]
}
See the following blog post for more details - https://learn.microsoft.com/en-us/azure/cognitive-services/text-analytics/quick-start