Skip to content
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

Microsoft Azure SDK for Node.js - Cognitive Services Spellcheck not working #4248

Closed
stephanbisser opened this issue Nov 5, 2018 · 7 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Bing customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@stephanbisser
Copy link

When trying to run the sample from https://www.npmjs.com/package/azure-cognitiveservices-spellcheck it creates the spellcheck services within my Azure sub but when I then try to call it with the following code snippet I get an empty result back:

const CognitiveServicesCredentials = require('ms-rest-azure').CognitiveServicesCredentials;
const SpellCheckAPIClient = require('azure-cognitiveservices-spellcheck');
// Creating the Cognitive Services credentials
// This requires a key corresponding to the service being used (i.e. text-analytics, etc)
let credentials = new CognitiveServicesCredentials(<serviceKey>);
let client = new SpellCheckAPIClient(credentials);
let options = {
  text: 'cognituve services'
};
client.spellChecker(options, (err, result, request, response) => {
  if (err) throw err;
  console.log(result);
  console.log(result.flaggedTokens[0].token);
  console.log(result.flaggedTokens[0].suggestions[0].suggestion);
});

This is the result and error I get logged out:

C:\Users\sbi\source\repos\testspellcheck>node spellcheck.js
{ _type: 'SpellCheck', flaggedTokens: [] }
C:\Users\sbi\source\repos\testspellcheck\spellcheck.js:49
console.log(result.flaggedTokens[0].token);
^

TypeError: Cannot read property 'token' of undefined
at client.spellChecker (C:\Users\sbi\source\repos\testspellcheck\spellcheck.js:49:39)
at client.pipeline (C:\Users\sbi\source\repos\testspellcheck\node_modules\azure-cognitiveservices-spellcheck\lib\spellCheckAPIClient.js:481:12)
at retryCallback (C:\Users\sbi\source\repos\testspellcheck\node_modules\ms-rest\lib\filters\systemErrorRetryPolicyFilter.js:89:9)
at retryCallback (C:\Users\sbi\source\repos\testspellcheck\node_modules\ms-rest\lib\filters\exponentialRetryPolicyFilter.js:140:9)
at C:\Users\sbi\source\repos\testspellcheck\node_modules\ms-rest\lib\filters\rpRegistrationFilter.js:59:14
at handleRedirect (C:\Users\sbi\source\repos\testspellcheck\node_modules\ms-rest\lib\filters\redirectFilter.js:39:9)
at C:\Users\sbi\source\repos\testspellcheck\node_modules\ms-rest\lib\filters\formDataFilter.js:23:14
at Request.defaultRequest [as _callback] (C:\Users\sbi\source\repos\testspellcheck\node_modules\ms-rest\lib\requestPipeline.js:125:16)
at Request.self.callback (C:\Users\sbi\source\repos\testspellcheck\node_modules\request\request.js:185:22)
at emitTwo (events.js:126:13)

@amarzavery amarzavery transferred this issue from Azure/azure-sdk-for-node Jul 10, 2019
@kurtzeborn kurtzeborn added Client This issue points to a problem in the data-plane of the library. Cognitive Services customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team. labels Jul 15, 2019
@kurtzeborn
Copy link
Member

Thanks for opening this issue (and @amarzavery for moving it to the correct repo). It looks like this is an auth issue with the cognitive services REST endpoint for spellcheck. We apologize for not getting to this sooner while it was open in the other repo. @stephanbisser, if you're still watching this issue, can you let us know if this is still happening for you?

@stephanbisser
Copy link
Author

Hi @kurtzeborn I need to check it and come back to you asap with the result! Thanks

@ChrisHMSFT
Copy link
Member

Hi @stephanbisser,

Can you try again with the latest version of this SDK?

https://www.npmjs.com/package/@azure/cognitiveservices-spellcheck

Thanks,
Chris

@ramya-rao-a
Copy link
Contributor

@sarangan12 If this doesnt repro with the latest re-generated code, then please close this issue

@wiazur
Copy link

wiazur commented Oct 29, 2019

Hi @stephanbisser, yeah that sample you found is a year old. The snippet below is current and working. Instructions on how to run are found here: https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/javascript/BingSpellCheck/bing_spell_check_quickstart.js

"use strict";
var SpellCheck = require("@azure/cognitiveservices-spellcheck");
var msRest = require("@azure/ms-rest-js");

const key = process.env['BING_SPELL_CHECK_SUBSCRIPTION_KEY'];
if (!key) {
    throw new Error('Set/export a BING_SPELL_CHECK_SUBSCRIPTION_KEY environment variable.');
}

const endpoint = process.env['BING_SPELL_CHECK_ENDPOINT'];
if (!endpoint) {
    throw new Error('Set/export a BING_SPELL_CHECK_ENDPOINT environment variable.');
}

const creds = new msRest.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': key } });
const client = new SpellCheck.SpellCheckClient(creds, { endpoint: endpoint });

async function quickstart() {
    let query = 'bill gtaes was eher';
    let misspelledWords = [];
    let suggestedWords = [];
    await client.spellChecker(query)
        .then((response) => {
            console.log();
            for (var i = 0; i < response._response.parsedBody.flaggedTokens.length; i++) {
                var spellingFlaggedToken = response._response.parsedBody.flaggedTokens[i];
                misspelledWords.push(spellingFlaggedToken.token);
                var correction = spellingFlaggedToken.suggestions[0].suggestion; // gets each word
                suggestedWords.push(correction);
            }
            console.log('Original query: ' + query);
            console.log();
            console.log('Misspelled words: ');
            console.log(misspelledWords);
            console.log();
            console.log('Suggested correction(s): ');
            console.log(suggestedWords);
        }).catch((err) => {
            throw err;
        })
}

try {
    quickstart();
}
catch (error) {
    console.log(error);
}

@ChrisHMSFT
Copy link
Member

Closing the ticket given there has not been a response. Please re-open if this issue has not been resolved.

Thanks,
Chris

@ghost
Copy link

ghost commented Oct 30, 2019

Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Cognitive - Bing customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

7 participants