15 |
16 |
--------------------------------------------------------------------------------
/javascript/LUIS/sdk-3x/.devcontainer/devcontainer.json:
--------------------------------------------------------------------------------
1 | // For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.128.0/containers/javascript-node-10
3 | {
4 | "name": "Node.js 10",
5 | "dockerFile": "Dockerfile",
6 |
7 | // Set *default* container specific settings.json values on container create.
8 | "settings": {
9 | "terminal.integrated.shell.linux": "/bin/bash"
10 | },
11 |
12 | // Add the IDs of extensions you want installed when the container is created.
13 | "extensions": [
14 | "dbaeumer.vscode-eslint"
15 | ]
16 |
17 | // Use 'forwardPorts' to make a list of ports inside the container available locally.
18 | // "forwardPorts": [],
19 |
20 | // Use 'postCreateCommand' to run commands after the container is created.
21 | ,"postCreateCommand": "yarn install",
22 |
23 | // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
24 | // "remoteUser": "node"
25 | }
--------------------------------------------------------------------------------
/javascript/LUIS/sdk-3x/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "luis-sdk-3x",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node index.js"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "@azure/cognitiveservices-luis-authoring": "^4.0.0-preview.3",
13 | "@azure/cognitiveservices-luis-runtime": "^5.0.0",
14 | "@azure/ms-rest-js": "^2.0.5"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/javascript/Personalizer/README.md:
--------------------------------------------------------------------------------
1 | # About this Quickstart
2 |
3 | This interactive sample takes the time of day and the users's taste preference as context, and sends it to an Azure Personalizer instance, which then returns the top personalized food choice, along with the recommendation probability distribution of each food item. The user then inputs whether or not Personalizer predicted correctly, which is data used to improve Personalizer's prediction model.
4 |
5 | # To try this sample
6 |
7 | ## Prerequisites
8 |
9 | The solution is a Node.js app, you will need [NPM](https://www.npmjs.com/) or an equivalent to install the packages and run the sample file.
10 |
11 | ## Set up the sample
12 |
13 | - Clone the Azure Personalizer Samples repo.
14 |
15 | ```bash
16 | git clone https://github.com/Azure-Samples/cognitive-services-quickstart-code
17 | ```
18 |
19 | - Navigate to _javascript/Personalizer_.
20 |
21 | - Open `sample.js` for editing.
22 |
23 | ## Set up Azure Personalizer Service
24 |
25 | - Create a Personalizer instance in the Azure portal.
26 |
27 | - Set your environment variables `serviceKey` and `baseUri`. These values can be found in your Cognitive Services Quick start tab in the Azure portal.
28 |
29 | ## Run the sample
30 |
31 | Build and run the sample with `npm start` at the CLI or terminal. The app will take input from the user interactively and send the data to the Personalizer instance.
32 |
--------------------------------------------------------------------------------
/javascript/Personalizer/multislot-quickstart/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "personalizer-multi-slot-quickstart",
3 | "version": "0.0.0",
4 | "description": "Sample code used in quickstart to demonstrate Personalizer's multi-slot learning loop of calling Rank and Reward",
5 | "main": "sample.js",
6 | "author": {
7 | "name": ""
8 | },
9 | "dependencies": {
10 | "@azure/ms-rest-azure-js": "^2.1.0",
11 | "@azure/ms-rest-js": "^2.2.3",
12 | "readline-sync": "^1.4.10",
13 | "requests": "^0.3.0",
14 | "uuid": "^8.3.2"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/javascript/Personalizer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "personalizer-quickstart",
3 | "version": "1.0.0",
4 | "description": "Sample code used in quickstart to demonstrate Personalizer's learning loop of calling Rank and Reward",
5 | "main": "sample.js",
6 | "scripts": {
7 | "start": "node sample.js",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC",
13 | "dependencies": {
14 | "@azure/cognitiveservices-personalizer": "^2.0.1",
15 | "@azure/ms-rest-azure-js": "^2.0.1",
16 | "@azure/ms-rest-js": "^2.0.8",
17 | "readline-sync": "^1.4.10",
18 | "uuid": "^8.3.0"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/javascript/QnAMaker/rest-based-quickstart/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "qnamker-rest-based-quickstart",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "rest-based-quickstart.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "request": "^2.88.0",
14 | "requestretry": "^4.0.2"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/javascript/QnAMaker/rest/publish-kb.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /* To install dependencies, run:
4 | * npm install requestretry
5 | */
6 | const request = require("requestretry");
7 |
8 | /*
9 | * Set the `subscriptionKey` and `endpoint` variables to your
10 | * QnA Maker authoring subscription key and endpoint.
11 | *
12 | * These values can be found in the Azure portal (ms.portal.azure.com/).
13 | * Look up your QnA Maker resource. Then, in the "Resource management"
14 | * section, find the "Keys and Endpoint" page.
15 | *
16 | * The value of `endpoint` has the format https://YOUR-RESOURCE-NAME.cognitiveservices.azure.com.
17 | *
18 | * Set the `kbId` variable to the ID of a knowledge base you have
19 | * previously created.
20 | */
21 | const subscriptionKey = "PASTE_YOUR_QNA_MAKER_AUTHORING_SUBSCRIPTION_KEY_HERE";
22 | const endpoint = "PASTE_YOUR_QNA_MAKER_AUTHORING_ENDPOINT_HERE";
23 | const kbId = "PASTE_YOUR_QNA_MAKER_KB_ID_HERE";
24 |
25 | const publishKbMethod = "/qnamaker/v4.0/knowledgebases/" + kbId
26 |
27 | const publishKb = async () => {
28 | var request_params = {
29 | uri: endpoint + publishKbMethod,
30 | method: 'POST',
31 | headers: {
32 | 'Ocp-Apim-Subscription-Key': subscriptionKey
33 | }
34 | };
35 | var response = await request(request_params);
36 | return response;
37 | };
38 |
39 | publishKb()
40 | .then(response => {
41 | // Note status code 204 is success.
42 | console.log("Result: " + response.statusCode);
43 | }).catch(err => {
44 | console.log(err);
45 | })
46 |
--------------------------------------------------------------------------------
/javascript/QnAMaker/sdk/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "qnamaker_quickstart-sdk",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "qnamaker_quickstart.js",
6 | "scripts": {
7 | "start": "node qnamaker_quickstart.js",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC",
13 | "dependencies": {
14 | "@azure/cognitiveservices-qnamaker": "^2.0.0",
15 | "@azure/cognitiveservices-qnamaker-runtime": "^1.0.0",
16 | "@azure/ms-rest-js": "^2.0.4"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/javascript/QnAMaker/sdk/readme.md:
--------------------------------------------------------------------------------
1 | # Create, update, publish, delete a knowledge base
2 |
3 | ## To use this sample
4 |
5 | 1. Create QnA Maker resource in Azure portal.
6 | 1. Get resource's key and resource name.
7 | 1. Edit values for your key and resource name.
8 | 1. Install dependencies with `npm install`.
9 | 1. Run sample with `npm start`.
10 |
11 | # Install
12 |
13 | ```javascript
14 | npm install
15 | ```
16 |
17 | ## Run
18 |
19 | ```javascript
20 | npm start
21 | ```
22 |
--------------------------------------------------------------------------------
/javascript/TextAnalytics/REST/rest-api-analyze-sentiment.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let https = require ('https');
4 |
5 | subscription_key = "PASTE_YOUR_TEXT_ANALYTICS_SUBSCRIPTION_KEY_HERE";
6 | endpoint = "PASTE_YOUR_TEXT_ANALYTICS_ENDPOINT_HERE";
7 |
8 | let path = '/text/analytics/v3.0/sentiment';
9 |
10 | let response_handler = function (response) {
11 | let body = '';
12 | response.on('data', function (d) {
13 | body += d;
14 | });
15 | response.on('end', function () {
16 | let body_ = JSON.parse(body);
17 | let body__ = JSON.stringify(body_, null, ' ');
18 | console.log(body__);
19 | });
20 | response.on('error', function (e) {
21 | console.log('Error: ' + e.message);
22 | });
23 | };
24 |
25 | let get_sentiments = function (documents) {
26 | let body = JSON.stringify(documents);
27 |
28 | let request_params = {
29 | method: 'POST',
30 | hostname: (new URL(endpoint)).hostname,
31 | path: path,
32 | headers: {
33 | 'Ocp-Apim-Subscription-Key': subscription_key,
34 | }
35 | };
36 |
37 | let req = https.request(request_params, response_handler);
38 | req.write(body);
39 | req.end();
40 | }
41 |
42 | let documents = {
43 | 'documents': [
44 | { 'id': '1', 'language': 'en', 'text': 'I really enjoy the new XBox One S. It has a clean look, it has 4K/HDR resolution and it is affordable.' },
45 | { 'id': '2', 'language': 'es', 'text': 'Este ha sido un dia terrible, llegué tarde al trabajo debido a un accidente automobilistico.' },
46 | ]
47 | };
48 |
49 | get_sentiments(documents);
--------------------------------------------------------------------------------
/javascript/TextAnalytics/REST/rest-api-detect-language.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let https = require ('https');
4 |
5 | subscription_key = "PASTE_YOUR_TEXT_ANALYTICS_SUBSCRIPTION_KEY_HERE";
6 | endpoint = "PASTE_YOUR_TEXT_ANALYTICS_ENDPOINT_HERE";
7 |
8 | let path = '/text/analytics/v3.0/languages';
9 |
10 | let response_handler = function (response) {
11 | let body = '';
12 | response.on('data', function (d) {
13 | body += d;
14 | });
15 | response.on('end', function () {
16 | let body_ = JSON.parse(body);
17 | let body__ = JSON.stringify(body_, null, ' ');
18 | console.log(body__);
19 | });
20 | response.on('error', function (e) {
21 | console.log('Error: ' + e.message);
22 | });
23 | };
24 |
25 | let get_language = function (documents) {
26 | let body = JSON.stringify(documents);
27 |
28 | let request_params = {
29 | method: 'POST',
30 | hostname: (new URL(endpoint)).hostname,
31 | path: path,
32 | headers: {
33 | 'Ocp-Apim-Subscription-Key': subscription_key,
34 | }
35 | };
36 |
37 | let req = https.request(request_params, response_handler);
38 | req.write(body);
39 | req.end();
40 | }
41 |
42 | let documents = {
43 | 'documents': [
44 | { 'id': '1', 'text': 'This is a document written in English.' },
45 | { 'id': '2', 'text': 'Este es un document escrito en Español.' },
46 | { 'id': '3', 'text': '这是一个用中文写的文件' }
47 | ]
48 | };
49 |
50 | get_language(documents);
--------------------------------------------------------------------------------
/javascript/TextAnalytics/REST/rest-api-entity-linking.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let https = require ('https');
4 |
5 | subscription_key = "PASTE_YOUR_TEXT_ANALYTICS_SUBSCRIPTION_KEY_HERE";
6 | endpoint = "PASTE_YOUR_TEXT_ANALYTICS_ENDPOINT_HERE";
7 |
8 | let path = '/text/analytics/v3.0/entities/recognition/general';
9 |
10 | let response_handler = function (response) {
11 | let body = '';
12 | response.on('data', function (d) {
13 | body += d;
14 | });
15 | response.on('end', function () {
16 | let body_ = JSON.parse(body);
17 | let body__ = JSON.stringify(body_, null, ' ');
18 | console.log(body__);
19 | });
20 | response.on('error', function (e) {
21 | console.log('Error: ' + e.message);
22 | });
23 | };
24 |
25 | let get_entities = function (documents) {
26 | let body = JSON.stringify(documents);
27 |
28 | let request_params = {
29 | method: 'POST',
30 | hostname: (new URL(endpoint)).hostname,
31 | path: path,
32 | headers: {
33 | 'Ocp-Apim-Subscription-Key': subscription_key,
34 | }
35 | };
36 |
37 | let req = https.request(request_params, response_handler);
38 | req.write(body);
39 | req.end();
40 | }
41 |
42 | let documents = {
43 | 'documents': [
44 | { 'id': '1', 'language': 'en', 'text': 'Microsoft is an It company.' }
45 | ]
46 | };
47 |
48 | get_entities(documents);
--------------------------------------------------------------------------------
/javascript/TextAnalytics/REST/rest-api-extract-key-phrases.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | let https = require ('https');
4 |
5 | subscription_key = "PASTE_YOUR_TEXT_ANALYTICS_SUBSCRIPTION_KEY_HERE";
6 | endpoint = "PASTE_YOUR_TEXT_ANALYTICS_ENDPOINT_HERE";
7 |
8 | let path = '/text/analytics/v3.0/keyPhrases';
9 |
10 | let response_handler = function (response) {
11 | let body = '';
12 | response.on('data', function (d) {
13 | body += d;
14 | });
15 | response.on('end', function () {
16 | let body_ = JSON.parse(body);
17 | let body__ = JSON.stringify(body_, null, ' ');
18 | console.log(body__);
19 | });
20 | response.on('error', function (e) {
21 | console.log('Error: ' + e.message);
22 | });
23 | };
24 |
25 | let get_key_phrases = function (documents) {
26 | let body = JSON.stringify(documents);
27 |
28 | let request_params = {
29 | method: 'POST',
30 | hostname: (new URL(endpoint)).hostname,
31 | path: path,
32 | headers: {
33 | 'Ocp-Apim-Subscription-Key': subscription_key,
34 | }
35 | };
36 |
37 | let req = https.request(request_params, response_handler);
38 | req.write(body);
39 | req.end();
40 | }
41 |
42 | let documents = {
43 | 'documents': [
44 | { 'id': '1', 'language': 'en', 'text': 'I really enjoy the new XBox One S. It has a clean look, it has 4K/HDR resolution and it is affordable.' },
45 | { 'id': '2', 'language': 'es', 'text': 'Si usted quiere comunicarse con Carlos, usted debe de llamarlo a su telefono movil. Carlos es muy responsable, pero necesita recibir una notificacion si hay algun problema.' },
46 | { 'id': '3', 'language': 'en', 'text': 'The Grand Hotel is a new hotel in the center of Seattle. It earned 5 stars in my review, and has the classiest decor I\'ve ever seen.' }
47 | ]
48 | };
49 |
50 | get_key_phrases(documents);
--------------------------------------------------------------------------------
/javascript/TranslatorText/BreakSentence.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.breakSentence([{ text: "How are you? I am fine. What did you do today?" }]);
18 |
19 | if (0 == result.length) {
20 | console.log ('No sentences found.');
21 | }
22 | else {
23 | var sentLen = result[0].sentLen;
24 | console.log ('Sentences found: ' + sentLen.length);
25 | for (var i = 0; i < sentLen.length; i++) {
26 | console.log ('Length of sentence ' + (i + 1) + ': ' + sentLen[i]);
27 | }
28 | }
29 | }
30 |
31 | try {
32 | quickstart();
33 | }
34 | catch (error) {
35 | console.log(error);
36 | }
37 |
--------------------------------------------------------------------------------
/javascript/TranslatorText/Detect.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.detect([{ text: "Salve, mondo!" }]);
18 |
19 | if (0 == result.length) {
20 | console.log ('No results found.');
21 | }
22 | else {
23 | console.log ('Language detected: ' + result[0].language);
24 | console.log ('Score: ' + result[0].score);
25 | }
26 | }
27 |
28 | try {
29 | quickstart();
30 | }
31 | catch (error) {
32 | console.log(error);
33 | }
34 |
--------------------------------------------------------------------------------
/javascript/TranslatorText/DictionaryExamples.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.dictionaryExamples('en', 'fr', [{ text: "great", translation: "formidable" }]);
18 |
19 | if (0 == result.length) {
20 | console.log ('No examples found.');
21 | }
22 | else {
23 | for (var i = 0; i < result[0].examples.length; i++) {
24 | console.log ('Example ' + (i + 1) + ':');
25 | console.log ('Source prefix: ' + result[0].examples[i].sourcePrefix);
26 | console.log ('Source term: ' + result[0].examples[i].sourceTerm);
27 | console.log ('Source suffix: ' + result[0].examples[i].sourceSuffix);
28 | console.log ('Target prefix: ' + result[0].examples[i].targetPrefix);
29 | console.log ('Target term: ' + result[0].examples[i].targetTerm);
30 | console.log ('Target suffix: ' + result[0].examples[i].targetSuffix);
31 | console.log ();
32 | }
33 | }
34 | }
35 |
36 | try {
37 | quickstart();
38 | }
39 | catch (error) {
40 | console.log(error);
41 | }
42 |
--------------------------------------------------------------------------------
/javascript/TranslatorText/DictionaryLookup.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.dictionaryLookup('en', 'fr', [{ text: "great" }]);
18 |
19 | if (0 == result.length) {
20 | console.log ('No translations found.');
21 | }
22 | else {
23 | console.log ('Translations:');
24 | for (var i = 0; i < result[0].translations.length; i++) {
25 | console.log (result[0].translations[i].displayTarget);
26 | }
27 | }
28 | }
29 |
30 | try {
31 | quickstart();
32 | }
33 | catch (error) {
34 | console.log(error);
35 | }
36 |
--------------------------------------------------------------------------------
/javascript/TranslatorText/Languages.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.languages ();
18 | console.log ('Languages available:');
19 | Object.keys(result.translation).forEach(function(key) {
20 | console.log (key + '\t' + result.translation[key].name);
21 | });
22 | }
23 |
24 | try {
25 | quickstart();
26 | }
27 | catch (error) {
28 | console.log(error);
29 | }
30 |
--------------------------------------------------------------------------------
/javascript/TranslatorText/Translate.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.translate(['it', 'de'], [{ text: "How are you? I am fine. What did you do today?" }]);
18 |
19 | if (0 == result.length) {
20 | console.log ('No translations found.');
21 | }
22 | else {
23 | var translations = result[0].translations;
24 | console.log ('Translations:');
25 | for (var i = 0; i < translations.length; i++) {
26 | console.log (translations[i].to + ': ' + translations[i].text);
27 | }
28 | }
29 | }
30 |
31 | try {
32 | quickstart();
33 | }
34 | catch (error) {
35 | console.log(error);
36 | }
37 |
--------------------------------------------------------------------------------
/javascript/TranslatorText/Transliterate.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | /* To run this sample, install the following modules.
4 | * npm install @azure/cognitiveservices-autosuggest
5 | * npm install @azure/ms-rest-js
6 | */
7 | var TranslatorText = require("@azure/cognitiveservices-translatortext");
8 | var msRest = require("@azure/ms-rest-js");
9 |
10 | const subscription_key = 'PASTE_YOUR_TRANSLATOR_SUBSCRIPTION_KEY_HERE';
11 | const endpoint = 'PASTE_YOUR_TRANSLATOR_ENDPOINT_HERE';
12 |
13 | const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } });
14 | const client = new TranslatorText.TranslatorTextClient(creds, endpoint).translator;
15 |
16 | async function quickstart() {
17 | var result = await client.transliterate('ja', 'jpan', 'latn', [{ text: 'こんにちは' }]);
18 |
19 | if (0 == result.length) {
20 | console.log ('No transliterations found.');
21 | }
22 | else {
23 | console.log (result[0].text);
24 | }
25 | }
26 |
27 | try {
28 | quickstart();
29 | }
30 | catch (error) {
31 | console.log(error);
32 | }
33 |
--------------------------------------------------------------------------------
/php/ComputerVision/analyze-image/analyze-image.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | Analyze Image Sample
4 |
5 |
6 | with a valid key.
8 | $ocpApimkey = 'PASTE_YOUR_COMPUTER_VISION_KEY_HERE';
9 | $uriBase = 'PASTE_YOUR_COMPUTER_VISION_ENDPOINT_HERE' + 'vision/v3.1/';
10 |
11 | $imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/3/3c/Shaki_waterfall.jpg';
12 |
13 | require_once 'HTTP/Request2.php';
14 |
15 | $request = new Http_Request2($uriBase . '/analyze');
16 | $url = $request->getUrl();
17 |
18 | $headers = array(
19 | // Request headers
20 | 'Content-Type' => 'application/json',
21 | 'Ocp-Apim-Subscription-Key' => $ocpApimkey
22 | );
23 | $request->setHeader($headers);
24 |
25 | $parameters = array(
26 | // Request parameters
27 | 'visualFeatures' => 'Categories,Description',
28 | 'details' => '',
29 | 'language' => 'en'
30 | );
31 | $url->setQueryVariables($parameters);
32 |
33 | $request->setMethod(HTTP_Request2::METHOD_POST);
34 |
35 | // Request body parameters
36 | $body = json_encode(array('url' => $imageUrl));
37 |
38 | // Request body
39 | $request->setBody($body);
40 |
41 | try
42 | {
43 | $response = $request->send();
44 | echo "" .
45 | json_encode(json_decode($response->getBody()), JSON_PRETTY_PRINT) . "
";
46 | }
47 | catch (HttpException $ex)
48 | {
49 | echo "" . $ex . "
";
50 | }
51 | ?>
52 |
53 |
--------------------------------------------------------------------------------
/php/ComputerVision/extract-printed-text/get-printed-text.php:
--------------------------------------------------------------------------------
1 |
3 |
4 | OCR Sample
5 |
6 |
7 | with a valid key.
9 | $ocpApimkey = 'PASTE_YOUR_COMPUTER_VISION_KEY_HERE';
10 | $uriBase = 'PASTE_YOUR_COMPUTER_VISION_ENDPOINT_HERE' + 'vision/v3.1/';
11 |
12 | $imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/' .
13 | 'Atomist_quote_from_Democritus.png/338px-Atomist_quote_from_Democritus.png';
14 |
15 | require_once 'HTTP/Request2.php';
16 |
17 | $request = new Http_Request2($uriBase . 'ocr');
18 | $url = $request->getUrl();
19 |
20 | $headers = array(
21 | // Request headers
22 | 'Content-Type' => 'application/json',
23 | 'Ocp-Apim-Subscription-Key' => $ocpApimkey
24 | );
25 | $request->setHeader($headers);
26 |
27 | $parameters = array(
28 | // Request parameters
29 | 'language' => 'unk',
30 | 'detectOrientation' => 'true'
31 | );
32 | $url->setQueryVariables($parameters);
33 |
34 | $request->setMethod(HTTP_Request2::METHOD_POST);
35 |
36 | // Request body parameters
37 | $body = json_encode(array('url' => $imageUrl));
38 |
39 | // Request body
40 | $request->setBody($body);
41 |
42 | try
43 | {
44 | $response = $request->send();
45 | echo "" .
46 | json_encode(json_decode($response->getBody()), JSON_PRETTY_PRINT) . "
";
47 | }
48 | catch (HttpException $ex)
49 | {
50 | echo "" . $ex . "
";
51 | }
52 | ?>
53 |
54 |