无法从Microsoft文本分析主题识别

时间:2017-03-06 21:17:19

标签: python-2.7 azure-hub text-analytics-api

我的rawdata.json文件

{"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"
]}

我在我的模块中读到了这个文件

file_path = '/home/sujith/pylzdata/rawdata.json'
f = open(file_path, 'r')
input_texts = f.read()

和这个

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']

错误输出

开始主题检测。 回溯(最近一次调用最后一次):

文件“./lddata.py”,第25行,

response_headers = urllib2.urlopen(req).info()

文件“/usr/lib/python2.7/urllib2.py”,第127行,在urlopen中

return _opener.open(url, data, timeout)

文件“/usr/lib/python2.7/urllib2.py”,第410行,打开

response = meth(req, response)

文件“/usr/lib/python2.7/urllib2.py”,第523行,http_response

'http', request, response, code, msg, hdrs)

文件“/usr/lib/python2.7/urllib2.py”,第448行,错误

return self._call_chain(*args)

文件“/usr/lib/python2.7/urllib2.py”,第382行,_call_chain

result = func(*args)

文件“/usr/lib/python2.7/urllib2.py”,第531行,http_error_default

raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

urllib2.HTTPError:HTTP错误400:错误请求

来源:https://text-analytics-demo.azurewebsites.net/Home/SampleCodehttps://docs.microsoft.com/en-us/azure/machine-learning/machine-learning-apps-text-analytics#topic-detection-apis

1 个答案:

答案 0 :(得分:1)

看起来您的输入格式有误。应该是documents而不是Inputs

{
     "documents": [  
         {
             "id": "1",
             "text": "First document"
         },
         ...
         {
             "id": "100",
             "text": "Final document"
         }
     ],
     "stopWords": [
         "issue", "error", "user"
     ],
     "stopPhrases": [
         "Microsoft", "Azure"
     ]
}

有关详细信息,请参阅以下博客文章 - https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/quick-start