Skip to content

Commit 11e2797

Browse files
committed
Merge branch 'g-may-patch-1'
2 parents a2bf847 + 7cf360e commit 11e2797

File tree

3 files changed

+115
-18
lines changed

3 files changed

+115
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ var NaturalLanguageUnderstandingV1 = require('watson-developer-cloud/natural-lan
411411
var nlu = new NaturalLanguageUnderstandingV1({
412412
username: '<username>',
413413
password: '<password>',
414-
version_date: NaturalLanguageUnderstandingV1.VERSION_DATE_2016_01_23
414+
version_date: NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27
415415
});
416416

417417
nlu.analyze({

natural-language-understanding/v1.js

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const BaseService = require('../lib/base_service');
2828
function NaturalLanguageUnderstandingV1(options) {
2929
BaseService.call(this, options);
3030
if (typeof this._options.version_date === 'undefined') {
31-
throw new Error('Argument error: version_date was not specified, use NaturalLanguageUnderstandingV1.VERSION_DATE_2016_01_23');
31+
throw new Error('Argument error: version_date was not specified, use NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27');
3232
}
3333
this._options.qs.version = this._options.version_date;
3434
}
@@ -37,32 +37,39 @@ NaturalLanguageUnderstandingV1.prototype.name = 'natural_language_understanding'
3737
NaturalLanguageUnderstandingV1.prototype.version = 'v1';
3838
NaturalLanguageUnderstandingV1.URL = 'https://gateway.watsonplatform.net/natural-language-understanding/api';
3939
NaturalLanguageUnderstandingV1.VERSION_DATE_2016_01_23 = '2016-01-23';
40+
// GA version date: 2017-02-27
41+
// https://www.ibm.com/watson/developercloud/doc/natural-language-understanding/release-notes.html
42+
NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27 = '2017-02-27';
4043

4144
/**
4245
* Analyze the query.
4346
* @params {object} params for the query
44-
* @param {Object} [params.headers] - The headers added
47+
* @param {object} [params.headers] - The headers added
4548
* @param {string} [params.text] - The text to analyze.
4649
* @param {string} [params.html] - The html to analyze.
4750
* @param {string} [params.url] - The url to fetch and analyze.
4851
* @param {object} [params.features] - The features to retrieve (need at least one)
49-
* @param {object} [params.features.concepts] - The concepts feature
50-
* @param {object} [params.features.entities] - The entities feature
51-
* @param {object} [params.features.keywords] - keywords feature
5252
* @param {object} [params.features.categories] - categories feature
53+
* @param {object} [params.features.concepts] - concepts feature
5354
* @param {object} [params.features.emotion] - emotion feature
54-
* @param {object} [params.features.sentiment] - sentiment feature
55+
* @param {object} [params.features.entities] - entities feature
56+
* @param {object} [params.features.keywords] - keywords feature
57+
* @param {object} [params.features.metadata] - metadata feature
5558
* @param {object} [params.features.relations] - relations feature
5659
* @param {object} [params.features.semantic_roles] - semantic roles feature
60+
* @param {object} [params.features.sentiment] - sentiment feature
5761
* @params {function} callback taking (error, jsonResult)
5862
* @example
5963
* ```
60-
* const options = { 'text': 'I am some text to analyze, am I not cool?',
61-
* 'features': {
62-
* 'concepts': {},
63-
* 'emotion': {},
64-
* },
65-
* };
64+
* const options = {
65+
* 'text': 'Natural Language Understanding analyzes unstructured text to return structured insights',
66+
* 'features': {
67+
* 'concepts': {
68+
* 'limit': 3
69+
* },
70+
* 'emotion': {},
71+
* },
72+
* };
6673
* nlu.analyze(options, myCallbackFunction);
6774
* ```
6875
* @return {void}
@@ -80,4 +87,56 @@ NaturalLanguageUnderstandingV1.prototype.analyze = function(params, callback) {
8087
return requestFactory(parameters, callback);
8188
};
8289

90+
/**
91+
* List custom models deployed to your service instance.
92+
* @params {object} params for the query
93+
* @param {object} [params.headers] - The headers added
94+
* @params {function} callback taking (error, jsonResult)
95+
* @example
96+
* ```
97+
* nlu.listModels({}, myCallbackFunction);
98+
* ```
99+
* @return {void}
100+
*/
101+
NaturalLanguageUnderstandingV1.prototype.listModels = function(params, callback) {
102+
const parameters = {
103+
options: {
104+
url: '/v1/models',
105+
method: 'GET',
106+
json: true
107+
},
108+
defaultOptions: this._options
109+
};
110+
return requestFactory(parameters, callback);
111+
};
112+
113+
/**
114+
* Delete a custom model that is deployed to your service instance.
115+
* @params {object} params for the query
116+
* @param {object} [params.headers] - The headers added
117+
* @param {string} [params.model_id] - ID of the custom model to delete
118+
* @params {function} callback taking (error, jsonResult)
119+
* @example
120+
* ```
121+
* const options = {
122+
* 'model_id': 'myModel123'
123+
* };
124+
* nlu.deleteModel(options, myCallbackFunction);
125+
* ```
126+
* @return {void}
127+
*/
128+
NaturalLanguageUnderstandingV1.prototype.deleteModel = function(params, callback) {
129+
const parameters = {
130+
options: {
131+
method: 'DELETE',
132+
url: '/v1/models/{model_id}',
133+
path: params,
134+
json: true
135+
},
136+
requiredParams: ['model_id'],
137+
defaultOptions: this._options
138+
};
139+
return requestFactory(parameters, callback);
140+
};
141+
83142
module.exports = NaturalLanguageUnderstandingV1;

test/unit/test.natural_language_understanding.v1.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('natural_language_understanding', function() {
1818
nlu = new watson.NaturalLanguageUnderstandingV1({
1919
username: 'user',
2020
password: 'pass',
21-
version_date: watson.NaturalLanguageUnderstandingV1.VERSION_DATE_2016_01_23
21+
version_date: watson.NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27
2222
});
2323
nock.disableNetConnect();
2424
});
@@ -38,17 +38,55 @@ describe('natural_language_understanding', function() {
3838
done();
3939
});
4040

41-
it('analyze()', function(done) {
42-
nock(watson.NaturalLanguageUnderstandingV1.URL)
43-
.persist()
41+
it('2016_01_23 version should work', function(done) {
42+
const mockApi = nock(watson.NaturalLanguageUnderstandingV1.URL)
4443
.post('/v1/analyze?version=' + watson.NaturalLanguageUnderstandingV1.VERSION_DATE_2016_01_23)
4544
.reply(200, {});
4645

46+
const nlu_old_version = new watson.NaturalLanguageUnderstandingV1({
47+
username: 'user',
48+
password: 'pass',
49+
version_date: watson.NaturalLanguageUnderstandingV1.VERSION_DATE_2016_01_23
50+
});
51+
4752
const options = {
4853
features: { concepts: {}, keywords: {} },
4954
text: 'hello, this is a test'
5055
};
5156

52-
nlu.analyze(options, done);
57+
nlu_old_version.analyze(options, (err) => {
58+
assert.ifError(err);
59+
mockApi.done();
60+
done();
61+
});
62+
});
63+
64+
it('analyze()', function(done) {
65+
const mockApi = nock(watson.NaturalLanguageUnderstandingV1.URL)
66+
.post('/v1/analyze?version=' + watson.NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27)
67+
.reply(200, {});
68+
69+
const options = {
70+
features: { concepts: {}, keywords: {} },
71+
text: 'hello, this is a test'
72+
};
73+
74+
nlu.analyze(options, (err) => {
75+
assert.ifError(err);
76+
mockApi.done();
77+
done();
78+
});
79+
});
80+
81+
it('should list models', function(done) {
82+
const mockApi = nock(watson.NaturalLanguageUnderstandingV1.URL)
83+
.get('/v1/models?version=' + watson.NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27)
84+
.reply(200, {});
85+
86+
nlu.listModels({}, (err) => {
87+
assert.ifError(err);
88+
mockApi.done();
89+
done();
90+
});
5391
});
5492
});

0 commit comments

Comments
 (0)