Skip to content

Commit 061a664

Browse files
committed
Add classifications to NLU node
1 parent e826f1d commit 061a664

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Node-RED Watson Nodes for IBM Cloud
1616
- Drop Visual Recognition nodes
1717
- Remove Username / Password fields from all nodes
1818
- Bump to latest version of services
19-
- New Discovery V2 node
19+
- New Discovery V2 node
20+
- Add Classifications to Natural Language Understanding node
2021

2122

2223
### Watson Nodes for Node-RED

services/natural_language_understanding/v1.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@
5151
id="node-input-limitcategories" />
5252
</div>
5353

54+
<div>
55+
<input style="width: 30px; margin-left: 20px; margin-top: 0;"
56+
type="checkbox" id="node-input-classifications" />
57+
<label style="width: auto;" for="node-input-classifications">Classifications</label>
58+
</div>
59+
<div>
60+
<label style="width: auto;" for="node-input-classifications-model">Classification model</label>
61+
<input type="text" id="node-input-classifications-model" />
62+
</div>
63+
5464
<div>
5565
<input style="width: 30px; margin-left: 20px; margin-top: 0;"
5666
type="checkbox" id="node-input-concepts" />
@@ -200,6 +210,7 @@
200210
<p>The following features are available for analysis:</p>
201211
<ul>
202212
<li><b>Categories</b>, categorize content into a taxonomy.</li>
213+
<li><b>Classifications</b>, text classifications for the content.</li>
203214
<li><b>Concepts</b>, recognize high-level concepts.</li>
204215
<li><b>Document Emotion</b>, generate emotion scores.</li>
205216
<li><b>Emotion Targets</b>, optionally target the emotions scores to a
@@ -241,6 +252,8 @@
241252
<code>msg.nlu_options.entity_model</code>.
242253
To override the model used for relations set
243254
<code>msg.nlu_options.relations_model</code>.
255+
To override the model used for classifications set
256+
<code>msg.nlu_options.classifications_model</code>.
244257
</p>
245258
<br>
246259
<p>Results from the API service will made available
@@ -257,6 +270,7 @@
257270
var nluV1 = new NaturalLanguageUnderstandingV1();
258271

259272
nluV1.hideAll = function() {
273+
$('#node-input-classifications-model').parent().hide();
260274
$('#node-input-maxconcepts').parent().hide();
261275
$('#node-input-limitcategories').parent().hide();
262276
$('#node-input-doc-emotion-target').parent().hide();
@@ -295,6 +309,9 @@
295309
}
296310

297311
nluV1.UIListeners = function () {
312+
nluV1.CreateIListener($('#node-input-classifications'),
313+
$('#node-input-classifications-model'));
314+
298315
nluV1.CreateIListener($('#node-input-concepts'),
299316
$('#node-input-maxconcepts'));
300317

@@ -357,6 +374,8 @@
357374
'name': {value: ''},
358375
'categories': {value: false},
359376
'limitcategories': {value: '3'},
377+
'classifications': {value: false},
378+
'classifications-model': {value: '8'},
360379
'concepts': {value: false},
361380
'maxconcepts': {value: '8'},
362381
'doc-emotion': {value: false},

services/natural_language_understanding/v1.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = function (RED) {
2121

2222
const NLU_FEATURES = {
2323
'categories': 'categories',
24+
'classifications': 'classifications',
2425
'concepts': 'concepts',
2526
'doc-emotion': 'emotion',
2627
'doc-sentiment': 'sentiment',
@@ -112,6 +113,18 @@ module.exports = function (RED) {
112113
}
113114
}
114115

116+
117+
118+
function processClassificationsOptions(msg, config, features) {
119+
if (features.classifications) {
120+
if (msg.nlu_options && msg.nlu_options.classifications_model) {
121+
features.classifications.model = msg.nlu_options.classifications_model;
122+
} else if (config['classifications-model']) {
123+
features.classifications.model = config['classifications-model'] ;
124+
}
125+
}
126+
}
127+
115128
function processCategoriesOptions(config, features) {
116129
if (features.categories) {
117130
features.categories.limit =
@@ -195,14 +208,15 @@ module.exports = function (RED) {
195208
function checkFeatureOptions(msg, config, options) {
196209
if (options && options.features) {
197210
processConceptsOptions(config, options.features);
211+
processClassificationsOptions(msg, config, options.features);
198212
processCategoriesOptions(config, options.features);
199213
processEmotionOptions(config, options.features);
200214
processSentimentOptions(config, options.features);
201-
processEntitiesOptions(msg,config, options.features);
202-
processRelationsOptions(msg,config, options.features);
215+
processEntitiesOptions(msg, config, options.features);
216+
processRelationsOptions(msg, config, options.features);
203217
processKeywordsOptions(config, options.features);
204218
processSemanticRolesOptions(config, options.features);
205-
processSyntaxOptions(msg,config, options.features);
219+
processSyntaxOptions(msg, config, options.features);
206220
}
207221
return Promise.resolve();
208222
}

0 commit comments

Comments
 (0)