diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt b/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt index b73b4a1293c3..ea8fb1516028 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 Microsoft +Copyright (c) 2020 Microsoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md b/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md index 2808d897ac09..377f13cbf6eb 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/README.md @@ -17,81 +17,52 @@ npm install @azure/cognitiveservices-textanalytics #### nodejs - Authentication, client creation and detectLanguage as an example written in TypeScript. -##### Install @azure/ms-rest-azure-js +##### Install @azure/ms-rest-nodeauth +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. ```bash -npm install @azure/ms-rest-azure-js +npm install @azure/ms-rest-nodeauth@"^3.0.0" ``` ##### Sample code -The following sample detects the langauge in the provided text. In addition, it provides data such as Characters count, transaction count, etc. To know more, refer to the [Azure Documentation on Text Analytics](https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview) ```typescript -import { - TextAnalyticsClient, - TextAnalyticsModels -} from "@azure/cognitiveservices-textanalytics"; -import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js"; - -async function main(): Promise { - const textAnalyticsKey = - process.env["textAnalyticsKey"] || ""; - const textAnalyticsEndPoint = - process.env["textAnalyticsEndPoint"] || ""; - const cognitiveServiceCredentials = new CognitiveServicesCredentials( - textAnalyticsKey - ); - const client = new TextAnalyticsClient( - cognitiveServiceCredentials, - textAnalyticsEndPoint - ); - const options: TextAnalyticsModels.TextAnalyticsClientDetectLanguageOptionalParams = { - showStats: true, - languageBatchInput: { - documents: [ - { - id: "1", - text: "Sample Text" - }, - { - id: "2", - text: "Texto de ejemplo" - } - ] - } +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { TextAnalyticsClient, TextAnalyticsModels, TextAnalyticsMappers } from "@azure/cognitiveservices-textanalytics"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new TextAnalyticsClient(creds, subscriptionId); + const showStats = true; + const languageBatchInput: TextAnalyticsModels.LanguageBatchInput = { + documents: [{ + countryHint: "testcountryHint", + id: "testid", + text: "testtext" + }] }; - client - .detectLanguage(options) - .then(result => { - console.log("The result is:"); - result.documents!.forEach(document => { - console.log(`Id: ${document.id}`); - console.log("Detected Languages:"); - document.detectedLanguages!.forEach(dl => { - console.log(dl.name); - }); - console.log( - `Characters Count: ${document.statistics!.charactersCount}` - ); - console.log( - `Transactions Count: ${document.statistics!.transactionsCount}` - ); - }); - }) - .catch(err => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); - + client.detectLanguage(showStats, languageBatchInput).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` #### browser - Authentication, client creation and detectLanguage as an example written in JavaScript. +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` + ##### Sample code +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + - index.html ```html @@ -99,58 +70,36 @@ main(); @azure/cognitiveservices-textanalytics sample + @@ -161,4 +110,4 @@ main(); - [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-textanalytics%2FREADME.png) +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-textanalytics/README.png) diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/package.json b/sdk/cognitiveservices/cognitiveservices-textanalytics/package.json index 56053dea6e4b..1347d017cff5 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/package.json +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/package.json @@ -21,7 +21,7 @@ "devDependencies": { "typescript": "^3.5.3", "rollup": "^1.18.0", - "@rollup/plugin-node-resolve": "^5.2.0", + "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-sourcemaps": "^0.4.2", "uglify-js": "^3.6.0" }, diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts index 3a71da695d0b..cce51ba69f4f 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts @@ -499,12 +499,7 @@ export type KeyPhrasesResponse = KeyPhraseBatchResult & { /** * Contains response data for the sentiment operation. */ -export type SentimentResponse = { - /** - * The parsed response body. - */ - body: any; - +export type SentimentResponse = SentimentBatchResult & { /** * The underlying HTTP response. */ @@ -517,6 +512,6 @@ export type SentimentResponse = { /** * The response body as parsed JSON or XML */ - parsedBody: any; + parsedBody: SentimentBatchResult; }; }; diff --git a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts index fca998335222..3fb18c169c02 100644 --- a/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts +++ b/sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts @@ -122,13 +122,13 @@ class TextAnalyticsClient extends TextAnalyticsClientContext { /** * @param callback The callback */ - sentiment(callback: msRest.ServiceCallback): void; + sentiment(callback: msRest.ServiceCallback): void; /** * @param options The optional parameters * @param callback The callback */ - sentiment(options: Models.TextAnalyticsClientSentimentOptionalParams, callback: msRest.ServiceCallback): void; - sentiment(options?: Models.TextAnalyticsClientSentimentOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + sentiment(options: Models.TextAnalyticsClientSentimentOptionalParams, callback: msRest.ServiceCallback): void; + sentiment(options?: Models.TextAnalyticsClientSentimentOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { return this.sendOperationRequest( { options @@ -241,10 +241,9 @@ const sentimentOperationSpec: msRest.OperationSpec = { 200: { bodyMapper: Mappers.SentimentBatchResult }, - 500: { + default: { bodyMapper: Mappers.ErrorResponse - }, - default: {} + } }, serializer };