New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-red-contrib-cognitive-services

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-cognitive-services - npm Package Compare versions

Comparing version

to
0.0.6

99

cognitive-services/spellcheck.js

@@ -16,67 +16,70 @@ var request = require('request');

}
else
{
var options = {
url: 'https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?mkt=en-us',
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': this.credentials.key,
'Content-Type': 'application/json'
},
form: {
"Text": msg.payload
}
};
var options = {
url: 'https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?mkt=en-us',
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': this.credentials.key,
'Content-Type': 'application/json'
},
form: {
"Text": msg.payload
}
};
console.log("options=" + JSON.stringify(options));
request.post(options, function (error, response, body)
{
try
//console.log("options=" + JSON.stringify(options));
request.post(options, function (error, response, body)
{
if (!error)
try
{
console.log("response.statusCode=" + response.statusCode + ", body=" + body);
if (response.statusCode == 200)
if (!error)
{
var flaggedTokens = JSON.parse(body).flaggedTokens;
var tmp = msg.payload;
console.log("response.statusCode=" + response.statusCode + ", body=" + body);
if (response.statusCode == 200)
{
var flaggedTokens = JSON.parse(body).flaggedTokens;
var tmp = msg.payload;
flaggedTokens = flaggedTokens.sort(function(a, b) {
return b.offset - a.offset;
});
flaggedTokens = flaggedTokens.sort(function(a, b) {
return b.offset - a.offset;
});
for (var i = 0; i < flaggedTokens.length; i++)
{
var offset = flaggedTokens[i].offset;
var token = flaggedTokens[i].token;
var suggestion = flaggedTokens[i].suggestions[0].suggestion;
for (var i = 0; i < flaggedTokens.length; i++)
{
var offset = flaggedTokens[i].offset;
var token = flaggedTokens[i].token;
var suggestion = flaggedTokens[i].suggestions[0].suggestion;
var str1 = tmp.substring(0, offset);
var str2 = tmp.substr(offset, token.length);
var str3 = tmp.substring(offset+token.length, tmp.length);
var str1 = tmp.substring(0, offset);
var str2 = tmp.substr(offset, token.length);
var str3 = tmp.substring(offset+token.length, tmp.length);
if (str2 == token)
{
tmp = str1 + suggestion + str3;
if (str2 == token)
{
tmp = str1 + suggestion + str3;
}
}
msg.flaggedTokens = flaggedTokens;
msg.payload = tmp;
node.send(msg);
}
msg.flaggedTokens = flaggedTokens;
msg.payload = tmp;
node.send(msg);
else
{
node.error(body);
}
}
else
{
node.error(body);
node.error(error);
}
}
else
catch (e)
{
node.error(error);
node.error(e, msg);
console.log("exception=" + e);
}
}
catch (e)
{
node.error(e, msg);
console.log("exception=" + e);
}
});
});
}
});

@@ -83,0 +86,0 @@ }

@@ -17,83 +17,89 @@ var request = require('request');

}
if (config.operation == "cjp") // Calculate Joint Probability
else
{
var options = {
url: 'https://api.projectoxford.ai/text/weblm/v1.0/calculateJointProbability?model=body',
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': this.credentials.key,
'Content-Type': 'application/json'
},
json: {
"queries": [msg.payload]
}
};
request.post(options, function (error, response, body)
if (config.operation == "cjp") // Calculate Joint Probability
{
try
var options = {
url: 'https://api.projectoxford.ai/text/weblm/v1.0/calculateJointProbability?model=body',
method: 'POST',
headers: {
'Ocp-Apim-Subscription-Key': this.credentials.key,
'Content-Type': 'application/json'
},
json: {
"queries": [msg.payload]
}
};
//console.log("options=" + JSON.stringify(options));
request.post(options, function (error, response, body)
{
if (!error)
try
{
console.log("response.statusCode=" + response.statusCode + ", body=" + body);
if (response.statusCode == 200 && body.results != null && body.results.length > 0)
if (!error)
{
msg.payload = body.results[0].probability;
node.send(msg);
console.log("response.statusCode=" + response.statusCode + ", body=" + body);
if (response.statusCode == 200 && body.results != null && body.results.length > 0)
{
msg.payload = body.results[0].probability;
node.send(msg);
}
else
{
node.error(body);
}
}
else
{
node.error(body);
}
node.error(error);
}
}
else
catch (e)
{
node.error(error);
}
}
catch (e)
{
node.error(e, msg);
console.log("exception=" + e);
}
});
}
else if (config.operation == "lam") // List Available Models
{
var options = {
url: 'https://api.projectoxford.ai/text/weblm/v1.0/models',
method: 'GET',
headers: {
'Ocp-Apim-Subscription-Key': this.credentials.key,
'Content-Type': 'application/json'
}
};
request(options, function (error, response, body)
node.error(e, msg);
console.log("exception=" + e);
}
});
}
else if (config.operation == "lam") // List Available Models
{
try
var options = {
url: 'https://api.projectoxford.ai/text/weblm/v1.0/models',
method: 'GET',
headers: {
'Ocp-Apim-Subscription-Key': this.credentials.key,
'Content-Type': 'application/json'
}
};
//console.log("options=" + JSON.stringify(options));
request(options, function (error, response, body)
{
if (!error)
try
{
console.log("response.statusCode=" + response.statusCode + ", body=" + body);
if (response.statusCode == 200)
if (!error)
{
msg.payload = body;
node.send(msg);
console.log("response.statusCode=" + response.statusCode + ", body=" + body);
if (response.statusCode == 200)
{
msg.payload = body;
node.send(msg);
}
else
{
node.error(body);
}
}
else
{
node.error(body);
}
node.error(error);
}
}
else
catch (e)
{
node.error(error);
}
}
catch (e)
{
node.error(e, msg);
console.log("exception=" + e);
}
});
node.error(e, msg);
console.log("exception=" + e);
}
});
}
}

@@ -100,0 +106,0 @@ });

{
"name": "node-red-contrib-cognitive-services",
"version": "0.0.5",
"version": "0.0.6",
"description": "Microsoft Cognitive Services",

@@ -5,0 +5,0 @@ "dependencies": {