Skip to content

Commit 217d66c

Browse files
Merge pull request #101 from watson-developer-cloud/visual-insights
Visual insights
2 parents ac9026c + bf2e89d commit 217d66c

File tree

12 files changed

+266
-64
lines changed

12 files changed

+266
-64
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ APIs and SDKs that use cognitive computing to solve complex problems.
2020
* [Getting the Service Credentials](#getting-the-service-credentials)
2121
* [Alchemy Services](#alchemy-services)
2222
* [Alchemy Language](#alchemy-language)
23+
* [Alchemy Vision](#alchemy-vision)
24+
* [Alchemy Data News](#alchemy-data-news)
2325
* [IBM Watson Services](#ibm-watson-services)
2426
* [Authorization](#authorization)
2527
* [Concept Expansion](#concept-expansion)
@@ -35,6 +37,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
3537
* [Speech to Text](#speech-to-text)
3638
* [Text to Speech](#text-to-speech)
3739
* [Tradeoff Analytics](#tradeoff-analytics)
40+
* [Visual Insights](#visual-insights)
3841
* [Visual Recognition](#visual-recognition)
3942
* [Running in Bluemix](#running-in-bluemix)
4043
* [Debug](#debug)
@@ -124,6 +127,55 @@ alchemy_language.sentiment(params, function (err, response) {
124127
});
125128
```
126129

130+
### Alchemy Vision
131+
[Alchemy Vision][alchemy_vision] uses deep learning innovations to understand a picture's content and context. It sees complex visual scenes in their entirety —without needing any textual clues— leveraging a holistic approach to understanding the multiple objects and surroundings.
132+
133+
Example: Extract keywords from an image.
134+
135+
```javascript
136+
var watson = require('watson-developer-cloud');
137+
var fs = require('fs');
138+
139+
var alchemy_vision = watson.alchemy_vision({
140+
api_key: '<api_key>'
141+
});
142+
143+
var params = {
144+
image: fs.fs.createReadStream('src/test/resources/obama.jpg')
145+
};
146+
147+
alchemy_vision.getImageKeywords(params, function (err, keywords) {
148+
if (err)
149+
console.log('error:', err);
150+
else
151+
console.log(JSON.stringify(keywords, null, 2));
152+
});
153+
```
154+
155+
### Alchemy Data News
156+
[Alchemy Data News][alchemy_data_news] indexes 250k to 300k English language news and blog articles every day with historical search available for the past 60 days.
157+
Example: Get the volume data from the last 7 days using 12hs of time slice.
158+
159+
```javascript
160+
var watson = require('watson-developer-cloud');
161+
162+
var alchemy_data_news = watson.alchemy_data_news({
163+
api_key: '<api_key>'
164+
});
165+
166+
var params = {
167+
start: 'now-1d',
168+
end: 'now'
169+
};
170+
171+
alchemy_data_news.getNews(params, function (err, news) {
172+
if (err)
173+
console.log('error:', err);
174+
else
175+
console.log(JSON.stringify(news, null, 2));
176+
});
177+
```
178+
127179
## IBM Watson Services
128180
The Watson Developer Cloud offers a variety of services for building cognitive
129181
apps.
@@ -491,6 +543,31 @@ tradeoff_analytics.dilemmas(params, function(err, res) {
491543
});
492544
```
493545

546+
### Visual Insights
547+
Use the [Visual Insights][visual_insights] to get insight into the themes present in a collection of images based on their visual appearance/content.
548+
549+
```js
550+
var watson = require('watson-developer-cloud');
551+
var fs = require('fs');
552+
553+
var visual_insights = watson.visual_insights({
554+
username: '<username>',
555+
password: '<password>',
556+
version: 'v1'
557+
});
558+
559+
var params = {
560+
images_file: fs.createReadStream('./resources/images.zip')
561+
};
562+
563+
visual_insights.summary(params, function(err, res) {
564+
if (err)
565+
console.log(err);
566+
else
567+
console.log(JSON.stringify(res, null, 2));
568+
});
569+
```
570+
494571
### Visual Recognition
495572
Use the [Visual Recognition][visual_recognition] service to recognize the
496573
following picture.
@@ -590,6 +667,8 @@ See [CONTRIBUTING](https://github.com/watson-developer-cloud/nodejs-wrapper/blob
590667
[concept_expansion]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/glimpseapi/
591668
[relationship_extraction]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/sireapi/
592669
[visual_recognition]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/visual-recognition/
670+
[visual_insights]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/visual-insights/
671+
593672
[text_to_speech]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/text-to-speech/
594673
[speech_to_text]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/speech-to-text/
595674
[concept_insights]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/concept-insights/
@@ -598,6 +677,9 @@ See [CONTRIBUTING](https://github.com/watson-developer-cloud/nodejs-wrapper/blob
598677

599678
[alchemy_language]: http://www.alchemyapi.com/products/alchemylanguage
600679
[sentiment_analysis]: http://www.alchemyapi.com/products/alchemylanguage/sentiment-analysis
680+
[alchemy_vision]: http://www.alchemyapi.com/products/alchemyvision
681+
[alchemy_data_news]: http://www.alchemyapi.com/products/alchemydata-news
682+
601683
[wdc]: http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/
602684
[bluemix]: https://console.ng.bluemix.net
603685
[npm_link]: https://www.npmjs.com/package/watson-developer-cloud

examples/alchemy_data_news.v1.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
var watson = require('watson-developer-cloud');
4+
5+
var alchemy_data_news = watson.alchemy_data_news({
6+
api_key: '<api_key>'
7+
});
8+
9+
var params = {
10+
start: 'now-1d',
11+
end: 'now'
12+
};
13+
14+
alchemy_data_news.getNews(params, function (err, news) {
15+
if (err)
16+
console.log('error:', err);
17+
else
18+
console.log(JSON.stringify(news, null, 2));
19+
});

examples/alchemy_vision.v1.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
var watson = require('watson-developer-cloud');
4+
var fs = require('fs');
5+
6+
var alchemy_vision = watson.alchemy_vision({
7+
api_key: '<api_key>'
8+
});
9+
10+
var params = {
11+
image: fs.fs.createReadStream('src/test/resources/obama.jpg')
12+
};
13+
14+
alchemy_vision.getImageKeywords(params, function (err, keywords) {
15+
if (err)
16+
console.log('error:', err);
17+
else
18+
console.log(JSON.stringify(keywords, null, 2));
19+
});

examples/resources/images.zip

102 KB
Binary file not shown.

examples/visual_insights.v1.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
var watson = require('watson-developer-cloud');
4+
var fs = require('fs');
5+
6+
var visual_insights = watson.visual_insights({
7+
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
8+
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
9+
version: 'v1'
10+
});
11+
12+
var params = {
13+
images_file: fs.createReadStream('./resources/images.zip')
14+
};
15+
16+
visual_insights.summary(params, function(err, res) {
17+
if (err)
18+
console.log(err);
19+
else
20+
console.log(JSON.stringify(res, null, 2));
21+
});

lib/alchemy_endpoints.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
},
1313

1414
"concepts": {
15-
"url" : "/url/URLGetRankedKeywords",
16-
"text" : "/text/TextGetRankedKeywords",
17-
"html" : "/html/HTMLGetRankedKeywords"
15+
"url" : "/url/URLGetRankedConcepts",
16+
"text" : "/text/TextGetRankedConcepts",
17+
"html" : "/html/HTMLGetRankedConcepts"
1818
},
1919

2020
"sentiment": {
@@ -29,12 +29,6 @@
2929
"html" : "/html/HTMLGetTargetedSentiment"
3030
},
3131

32-
"category": {
33-
"url" : "/url/URLGetRankedConcepts",
34-
"text" : "/text/TextGetRankedConcepts",
35-
"html" : "/html/HTMLGetRankedConcepts"
36-
},
37-
3832
"relations": {
3933
"url" : "/url/URLGetRelations",
4034
"text" : "/text/TextGetRelations",
@@ -52,6 +46,16 @@
5246
"html" : "/html/HTMLGetText"
5347
},
5448

49+
"category": {
50+
"url" : "/url/URLGetCategory",
51+
"text" : "/text/TextGetCategory"
52+
},
53+
54+
"publication_date": {
55+
"url" : "/url/URLGetPubDate",
56+
"html" : "/html/HTMLGetPubDate"
57+
},
58+
5559
"text_raw": {
5660
"url" : "/url/URLGetRawText",
5761
"html" : "/html/HTMLGetRawText"
@@ -86,7 +90,7 @@
8690

8791
"image_link": {
8892
"url" : "/url/URLGetImage",
89-
"html" : "/html/HTMLGetImage"
93+
"html" : "/url/HTMLGetImage"
9094
},
9195

9296
"image_keywords": {

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ var watson = {};
115115
'dialog',
116116
'retrieve_and_rank',
117117
'document_conversion',
118-
118+
'visual_insights',
119119
// deprecated
120120
'search',
121121
'language_identification',

services/alchemy_data_news/v1.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
var extend = require('extend');
2020
var requestFactory = require('../../lib/requestwrapper');
21-
var endpoints = require('../../lib/alchemy_endpoints.json');
22-
var helper = require('../../lib/helper');
2321

2422
function errorFormatter(cb) {
2523
return function(err, result, response) {
@@ -38,32 +36,6 @@ function errorFormatter(cb) {
3836
};
3937
}
4038

41-
function createRequest(method) {
42-
return function(_params, callback ) {
43-
var params = _params || {};
44-
var accepted_formats = Object.keys(endpoints[method]);
45-
var format = helper.getFormat(params, accepted_formats);
46-
47-
if (format === null) {
48-
callback(new Error('Missing required parameters: ' +
49-
accepted_formats.join(', ') +
50-
' needs to be specified'));
51-
return;
52-
}
53-
54-
var parameters = {
55-
options: {
56-
url: endpoints[method][format],
57-
method: 'POST',
58-
json: true,
59-
form: extend({outputMode: 'json'}, params) // change default output to json
60-
},
61-
defaultOptions: this._options
62-
};
63-
return requestFactory(parameters, errorFormatter(callback));
64-
};
65-
}
66-
6739
function AlchemyDataNews(options) {
6840
// Default URL
6941
var serviceDefaults = {

services/alchemy_language/v1.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,15 @@ AlchemyLanguage.prototype.relations = createRequest('relations');
130130
*/
131131
AlchemyLanguage.prototype.category = createRequest('category');
132132

133+
/**
134+
* Categorizes the text for text, a URL or HTML.
135+
*/
136+
AlchemyLanguage.prototype.publicationDate = createRequest('publication_date');
137+
133138
/**
134139
* Detects the RSS/ATOM feeds for a URL or HTML.
135140
*/
136-
AlchemyLanguage.prototype.feeds = createRequest('category');
141+
AlchemyLanguage.prototype.feeds = createRequest('feeds');
137142

138143
/**
139144
* Parses the microformats for a URL or HTML.

0 commit comments

Comments
 (0)