-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Updating Language/Language SDK with new /entities endpoint #4286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed697be
Updating TA SDK with new /entities endpoint
6925d52
Bring back AssemblyInfo.cs
856eaa9
Merge branch 'psSdkJson6' into assafi/old_ta_sdk
eb243fc
Update release notes with link to new SDK + Remove VersionPrefix
d076a30
Moving Version tag to top of .csproj file + reverting changes from th…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...tiveServices/dataPlane/Language/Language/Language.Tests/ApiKeyServiceClientCredentials.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics | ||
| { | ||
| using System; | ||
| using System.Net.Http; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Rest; | ||
|
|
||
| /// <summary> | ||
| /// Allows authentication to the API using a basic apiKey mechanism | ||
| /// </summary> | ||
| public class ApiKeyServiceClientCredentials : ServiceClientCredentials | ||
| { | ||
| private readonly string subscriptionKey; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of the ApiKeyServiceClientCredentails class | ||
| /// </summary> | ||
| /// <param name="subscriptionKey">The subscription key to authenticate and authorize as</param> | ||
| public ApiKeyServiceClientCredentials(string subscriptionKey) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(subscriptionKey)) | ||
| throw new ArgumentNullException("subscriptionKey"); | ||
|
|
||
| this.subscriptionKey = subscriptionKey; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Add the Basic Authentication Header to each outgoing request | ||
| /// </summary> | ||
| /// <param name="request">The outgoing request</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation</param> | ||
| public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| if (request == null) | ||
| throw new ArgumentNullException("request"); | ||
|
|
||
| request.Headers.Add("Ocp-Apim-Subscription-Key", this.subscriptionKey); | ||
|
|
||
| return Task.FromResult<object>(null); | ||
| } | ||
| } | ||
| } |
20 changes: 6 additions & 14 deletions
20
src/SDKs/CognitiveServices/dataPlane/Language/Language/Language.Tests/BaseTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,20 @@ | ||
| using Microsoft.Azure.CognitiveServices.Language.TextAnalytics; | ||
| using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models; | ||
| using System.Net.Http; | ||
|
|
||
| namespace Language.Tests | ||
| { | ||
| public abstract class BaseTests | ||
| { | ||
| public static bool IsTestTenant = false; | ||
| private static string SubscriptionKey = ""; | ||
| private static string Region = null; | ||
|
|
||
| static BaseTests() | ||
| { | ||
| // Retrieve the configuration information. | ||
|
|
||
| Region = "WestUS"; | ||
| } | ||
| private static string SubscriptionKey = "000"; | ||
|
|
||
| protected ITextAnalyticsAPI GetClient(DelegatingHandler handler) | ||
| { | ||
| ITextAnalyticsAPI client; | ||
| client = new TextAnalyticsAPI(handlers: handler); | ||
| client.SubscriptionKey = SubscriptionKey; | ||
|
|
||
| return client; | ||
| return new TextAnalyticsAPI(new ApiKeyServiceClientCredentials(SubscriptionKey), handlers: handler) | ||
| { | ||
| AzureRegion = AzureRegions.Westus | ||
| }; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
...icrosoft.Azure.CognitiveServices.Language.TextAnalytics.Tests.EntitiesTests/Entities.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| { | ||
| "Entries": [ | ||
| { | ||
| "RequestUri": "/text/analytics/v2.0/entities", | ||
| "EncodedRequestUri": "L3RleHQvYW5hbHl0aWNzL3YyLjAvZW50aXRpZXM=", | ||
| "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": { | ||
| "Content-Type": [ | ||
| "application/json; charset=utf-8" | ||
| ], | ||
| "Content-Length": [ | ||
| "123" | ||
| ], | ||
| "Ocp-Apim-Subscription-Key": [ | ||
| "" | ||
| ], | ||
| "User-Agent": [ | ||
| "FxVersion/4.6.25211.01", | ||
| "Microsoft.CognitiveServices.Language.TextAnalytics.TextAnalyticsAPI/1.0.0" | ||
| ] | ||
| }, | ||
| "ResponseBody": "{ \"documents\": [{\"id\": \"1\", \"entities\": [ { \"name\": \"Windows 10\", \"matches\": [ { \"text\": \"Windows 10\", \"offset\": 19, \"length\": 10 } ], \"wikipediaLanguage\": \"en\", \"wikipediaId\": \"Windows 10\", \"wikipediaUrl\": \"https://en.wikipedia.org/wiki/Windows_10\", \"bingId\": \"5f9fbd03-49c4-39ef-cc95-de83ab897b94\" }, { \"name\": \"Microsoft\", \"matches\": [ { \"text\": \"Microsoft\", \"offset\": 0, \"length\": 9 } ], \"wikipediaLanguage\": \"en\", \"wikipediaId\": \"Microsoft\", \"wikipediaUrl\": \"https://en.wikipedia.org/wiki/Microsoft\", \"bingId\": \"a093e9b9-90f5-a3d5-c4b8-5855e1b01f85\" } ] }\r\n ],\r\n \"errors\": []\r\n}", | ||
| "ResponseHeaders": { | ||
| "Content-Type": [ | ||
| "application/json; charset=utf-8" | ||
| ], | ||
| "Date": [ | ||
| "Wed, 30 Aug 2017 02:11:17 GMT" | ||
| ], | ||
| "Transfer-Encoding": [ | ||
| "chunked" | ||
| ], | ||
| "x-ms-transaction-count": [ | ||
| "1" | ||
| ], | ||
| "x-aml-ta-request-id": [ | ||
| "460baaca-7f57-42c1-8cc7-8852957d05b9" | ||
| ], | ||
| "X-Content-Type-Options": [ | ||
| "nosniff" | ||
| ], | ||
| "apim-request-id": [ | ||
| "3f09b1c9-fe3b-46bb-badf-98108c599825" | ||
| ], | ||
| "Strict-Transport-Security": [ | ||
| "max-age=31536000; includeSubDomains; preload" | ||
| ] | ||
| }, | ||
| "StatusCode": 200 | ||
| } | ||
| ], | ||
| "Names": {}, | ||
| "Variables": {} | ||
| } |
File renamed without changes.
File renamed without changes.
13 changes: 8 additions & 5 deletions
13
...eServices/dataPlane/Language/Language/Language.Tests/TextAnalytics/DetectLanguageTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...gnitiveServices/dataPlane/Language/Language/Language.Tests/TextAnalytics/EntitiesTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using Language.Tests; | ||
| using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models; | ||
| using Microsoft.Azure.Test.HttpRecorder; | ||
| using Microsoft.Rest.ClientRuntime.Azure.TestFramework; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Tests | ||
| { | ||
| public class EntitiesTests : BaseTests | ||
| { | ||
| [Fact] | ||
| public async Task Entities() | ||
| { | ||
| using (MockContext context = MockContext.Start(this.GetType().FullName)) | ||
| { | ||
| HttpMockServer.Initialize(this.GetType().FullName, "Entities"); | ||
| ITextAnalyticsAPI client = GetClient(HttpMockServer.CreateInstance()); | ||
| EntitiesBatchResult result = await client.EntitiesAsync( | ||
| new MultiLanguageBatchInput( | ||
| new List<MultiLanguageInput>() | ||
| { | ||
| new MultiLanguageInput() | ||
| { | ||
| Id ="id", | ||
| Text ="Microsoft released Windows 10", | ||
| Language ="en" | ||
| } | ||
| })); | ||
|
|
||
| Assert.Equal("Windows 10", result.Documents[0].Entities[0].Name); | ||
| Assert.Equal("5f9fbd03-49c4-39ef-cc95-de83ab897b94", result.Documents[0].Entities[0].BingId); | ||
| context.Stop(); | ||
| } | ||
| } | ||
| } | ||
| } |
13 changes: 8 additions & 5 deletions
13
...itiveServices/dataPlane/Language/Language/Language.Tests/TextAnalytics/KeyPhrasesTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
...nitiveServices/dataPlane/Language/Language/Language.Tests/TextAnalytics/SentimentTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no changes required to this file