Skip to content

Commit

Permalink
added SDK for version 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
laramume committed Feb 28, 2019
1 parent 886306d commit 53123d7
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class BaseTests
{
public static bool IsTestTenant = false;
// BaseEndpoint only contains protocol and hostname
private static string BaseEndpoint = "https://westus.api.cognitive.microsoft.com";
private static string BaseEndpoint = "https://westcentralus.api.cognitive.microsoft.com";
private static string SubscriptionKey = "000";

protected ITextAnalyticsClient GetClient(DelegatingHandler handler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Entries": [
{
"RequestUri": "/text/analytics/v2.1-preview/languages",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9sYW5ndWFnZXM=",
"RequestUri": "/text/analytics/v2.1/languages",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEvbGFuZ3VhZ2Vz",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"id\": \"id\",\r\n \"text\": \"I love my team mates\"\r\n }\r\n ]\r\n}",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Entries": [
{
"RequestUri": "/text/analytics/v2.1-preview/entities",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9lbnRpdGllcw==",
"RequestUri": "/text/analytics/v2.1/entities",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEvZW50aXRpZXM=",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"Microsoft released Windows 10\"\r\n }\r\n ]\r\n}",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Entries": [
{
"RequestUri": "/text/analytics/v2.1-preview/keyPhrases",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9rZXlQaHJhc2Vz",
"RequestUri": "/text/analytics/v2.1/keyPhrases",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEva2V5UGhyYXNlcw==",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"I love my team mates\"\r\n }\r\n ]\r\n}",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Entries": [
{
"RequestUri": "/text/analytics/v2.1-preview/sentiment",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEtcHJldmlldy9zZW50aW1lbnQ=",
"RequestUri": "/text/analytics/v2.1/sentiment",
"EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjEvc2VudGltZW50",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"documents\": [\r\n {\r\n \"language\": \"en\",\r\n \"id\": \"id\",\r\n \"text\": \"I love my team mates\"\r\n }\r\n ]\r\n}",
"RequestHeaders": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task DetectLanguage()
HttpMockServer.Initialize(this.GetType().FullName, "DetectLanguage");
ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance());
LanguageBatchResult result = await client.DetectLanguageAsync(
true,
null,
new LanguageBatchInput(
new List<LanguageInput>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task Entities()
HttpMockServer.Initialize(this.GetType().FullName, "Entities");
ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance());
EntitiesBatchResult result = await client.EntitiesAsync(
true,
null,
new MultiLanguageBatchInput(
new List<MultiLanguageInput>()
{
Expand All @@ -30,8 +30,8 @@ public async Task Entities()
}
}));

Assert.Equal("Windows 10", result.Documents[0].Entities[0].Name);
Assert.Equal("5f9fbd03-49c4-39ef-cc95-de83ab897b94", result.Documents[0].Entities[0].BingId);
Assert.Equal("Microsoft", result.Documents[0].Entities[0].Name);
Assert.Equal("a093e9b9-90f5-a3d5-c4b8-5855e1b01f85", result.Documents[0].Entities[0].BingId);
Assert.Equal("Microsoft", result.Documents[0].Entities[0].Matches[0].Text);
Assert.Equal(0.12508682244047509, result.Documents[0].Entities[0].Matches[0].WikipediaScore);
Assert.Equal(0.99999618530273438, result.Documents[0].Entities[0].Matches[0].EntityTypeScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task KeyPhrases()
HttpMockServer.Initialize(this.GetType().FullName, "KeyPhrases");
ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance());
KeyPhraseBatchResult result = await client.KeyPhrasesAsync(
true,
null,
new MultiLanguageBatchInput(
new List<MultiLanguageInput>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task Sentiment()
HttpMockServer.Initialize(this.GetType().FullName, "Sentiment");
ITextAnalyticsClient client = GetClient(HttpMockServer.CreateInstance());
SentimentBatchResult result = await client.SentimentAsync(
true,
null,
new MultiLanguageBatchInput(
new List<MultiLanguageInput>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,14 +856,21 @@ private void Initialize()
HttpStatusCode _statusCode = _httpResponse.StatusCode;
cancellationToken.ThrowIfCancellationRequested();
string _responseContent = null;
if ((int)_statusCode != 200 && (int)_statusCode != 500)
if ((int)_statusCode != 200)
{
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
if (_httpResponse.Content != null) {
var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
try
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, DeserializationSettings);
if (_errorBody != null)
{
ex.Body = _errorBody;
}
}
else {
_responseContent = string.Empty;
catch (JsonException)
{
// Ignore the exception
}
ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
Expand Down Expand Up @@ -900,24 +907,6 @@ private void Initialize()
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
}
// Deserialize Response
if ((int)_statusCode == 500)
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
try
{
_result.Body = SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, DeserializationSettings);
}
catch (JsonException ex)
{
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
}
if (_shouldTrace)
{
ServiceClientTracing.Exit(_invocationId, _result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<![CDATA[
Microsoft Cognitive Services Text Analytics SDK.
This is a preview package which calls the API version "v2.1"
This package calls the API version "v2.1"
Changes in this release:
1. Add support for v2.1 API version which includes improvements to the /Entities endpoint.
1. Add support for v2.1 API version which includes Entity Type and Wikipedia confidence score to the /Entities endpoint.
]]></PackageReleaseNotes>
</PropertyGroup>
Expand Down

0 comments on commit 53123d7

Please sign in to comment.