При отправке документа в API для ключевых фраз возвращаемый ответ JSON содержит ошибку «Документ в запросе слишком велик для обработки. Ограничьте размер документа до: 10240 байт».
Согласно https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-text-analytics-quick-start, "Максимальный размер одного документа, который можно отправить, составляет 10 КБ, а общий максимальный размер отправляемых входных данных составляет 1 МБ. За один звонок можно отправить не более 1000 документов».
Рассматриваемый документ представляет собой строку длиной 7713. Длина байта с использованием Encoding.UTF8.GetBytes() составляет 7763.
Весь отправленный byteArray имеет длину 7965.
Меньшие строки работают нормально, но любая строка длиной более 3000, похоже, имеет эту проблему. Ниже приведен код, написанный на VB.NET:
' Create a JSONInput object containing the data to submit
Dim myJsonObject As New JSONInput
Dim input1 As New JSONText
input1.id = "1"
input1.text = text
myJsonObject.documents.Add(input1)
' Translate the JSONInput object to a serialized JSON string
Dim jss As New JavaScriptSerializer()
Dim jsonString As String = jss.Serialize(myJsonObject)
' Windows Cognitive Services URL
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases")
' Set the Method property of the request to POST.
request.Method = "POST"
' Add a header with the account key.
request.Headers.Add("Ocp-Apim-Subscription-Key", accountKey_TextAnalytics)
' Create POST data and convert it to a byte array.
Dim postData As String = jsonString
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
' Set the ContentType property of the WebRequest.
request.ContentType = "application/json"
' Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As System.IO.Stream = request.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
Dim response As System.Net.WebResponse = request.GetResponse()
' Get the stream containing content returned by the server.
dataStream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New System.IO.StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
Console.WriteLine(responseFromServer)
' Clean up the streams.
reader.Close()
dataStream.Close()
response.Close()
' Deserialize the json data
jss = New JavaScriptSerializer()
Dim jsonData = jss.Deserialize(Of Object)(responseFromServer)
' List of key phrases to be returned
Dim phrases As New List(Of String)
For Each item As String In jsonData("documents")(0)("keyPhrases")
phrases.Add(item)
Next
Return phrases
Мой вопрос в том, что я могу делать неправильно, что я получаю сообщения о том, что размер моего документа превышает ограничение в 10240 байт, но похоже, что данные, которые я отправляю, значительно меньше этого ограничения.