Skip to content

Commit 4b21478

Browse files
authored
Merge pull request #468 from chughts/081
081
2 parents 9118eea + ac3dfa5 commit 4b21478

File tree

24 files changed

+1269
-614
lines changed

24 files changed

+1269
-614
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.8.1
11+
- Node-RED & IBM-Watson & Use of promises on API invokation & IAM URL construct migration & Removal of default endpoint of
12+
- Speech to Text node
13+
- Speech to Text Corpus Builder node
14+
- Natural Language Understanding node
15+
- Natural Language Classifier node
16+
- Language Identifier node
17+
- Language Translator node
18+
- Translator Util node
19+
- New NLU Model Manager node.
20+
- NLC CreateClassifier is broken until defect on ibm-watson is fixed.
21+
- Remove X-Watson-Technology-Preview Neural translation option for Language Translator node
22+
- Remove monolingual corpus option from Language Translator mode
23+
- Added new modes to Language Translator mode
24+
- List Custom models
25+
- List Default models
1026

1127
### New in version 0.8.0
1228
- In the 0.8.x releases the nodes are migrated to a node-red 1.0.x input

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.8.0",
3+
"version": "0.8.1",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -11,7 +11,6 @@
1111
"qs": "6.x",
1212
"image-type": "^2.0.2",
1313
"watson-developer-cloud": "^3.18.3",
14-
"ibm-cloud-sdk-core": "^0.3.7",
1514
"ibm-watson": "^5.2.1",
1615
"word-count": "^0.2.2",
1716
"is-docx": "^0.0.3",
@@ -48,6 +47,7 @@
4847
"watson-language-translator-util-v3": "services/language_translator_util/v3.js",
4948
"watson-natural-language-classifier-v1": "services/natural_language_classifier/v1.js",
5049
"watson-natural-language-understanding-v1": "services/natural_language_understanding/v1.js",
50+
"watson-natural-language-understanding-model-manager-v1": "services/natural_language_understanding/v1-model-manager.js",
5151
"watson-personality-insights-v3": "services/personality_insights/v3.js",
5252
"watson-speech-to-text-v1": "services/speech_to_text/v1.js",
5353
"watson-speech-to-text-corpus-builder-v1": "services/speech_to_text/v1-corpus-builder.js",

services/language_translator/v3.html

+40-51
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
</div>
4545

4646
<div class="form-row credentials">
47-
<label>&nbsp;</label>
48-
<input type="checkbox" id="node-input-default-endpoint" style="display: inline-block; width: auto; vertical-align: top;">
49-
<label for="node-input-default-endpoint" style="width: 70%;"> Use Default Service Endpoint</label>
50-
</div>
51-
<div class="form-row">
5247
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
5348
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/language-translator/api">
5449
</div>
@@ -59,17 +54,13 @@
5954
<option value="translate">Translate</option>
6055
<option value="custom">Customised Translate</option>
6156
<option value="train">Train</option>
57+
<option value="listcustom">List Customised Models</option>
58+
<option value="listdefault">List Default Models</option>
6259
<option value="getstatus">Get status</option>
6360
<option value="delete">Delete</option>
6461
</select>
6562
</div>
6663

67-
<div class="form-row credentials">
68-
<label>&nbsp;</label>
69-
<input type="checkbox" id="node-input-neural" style="display: inline-block; width: auto; vertical-align: top;">
70-
<label for="node-input-neural" style="width: 70%;"> Use Experimental Neural Translation</label>
71-
</div>
72-
7364
<div class="form-row">
7465
<label for="node-input-domain"><i class="fa fa-book"></i> Domains</label>
7566
<select type="text" id="node-input-domain" style="display: inline-block; vertical-align:middle; width: 70%;">
@@ -122,7 +113,6 @@
122113
<select type="text" id="node-input-filetype" style="display: inline-block; vertical-align:middle; width: 70%;">
123114
<option value="forcedglossary" selected="selected">Forced glossary</option>
124115
<option value="parallelcorpus">Parallel corpus</option>
125-
<option value="monolingualcorpus">Monolingual corpus</option>
126116
</select>
127117
</div>
128118

@@ -149,6 +139,7 @@
149139
<script type="text/x-red" data-help-name="watson-translator">
150140
<p>The Watson Language Translator service enables you to translate text from one language to another and to add your own translation models.</p>
151141
<p></p>
142+
152143
<p><b>Translation Mode</b>.</p>
153144
<p>The text to translate should be passed in on <code>msg.payload</code>.</p>
154145
<p>The translated text will be returned on <code>msg.payload</code>.</p>
@@ -163,24 +154,26 @@
163154
the documentation linked below for the currently supported source and destination
164155
languages translation permutations.</p>
165156
<p></p>
157+
166158
<p><b>Customised Translation Mode</b>.</p>
167159
<p>In this mode you can select a translation model that you have customised through
168160
the training options.</p>
169161
<p>The text to translate should be passed in on <code>msg.payload</code>.</p>
170162
<p>The translated text will be returned on <code>msg.payload</code>.</p>
171163
<p>The full response from the service will be returned on <code>msg.translation</code></p>
172164
<p></p>
165+
173166
<p><b>Training Mode</b>.</p>
174167
<p>This mode enables you to add your own customized model to the Watson Language Translator service. </p>
175168
<p>In <code>msg.payload</code>, (this can be through box, dropbox or a file-inject node.
176169
you must specify one of the following file options to customize the training:</p>
177170
<p>forced_glossary - A UTF-8 encoded TMX file that contains pairs of matching terms in the source and target language that are seen as absolute by the system. This file completely overwrites the original domain data.</p>
178171
<p>parallel_corpus - A UTF-8 encoded TMX file that contains matching phrases in the source and target language that serve as examples for Watson. Parallel corpora differ from glossaries because they do not overwrite the original domain data.</p>
179-
<p>monolingual_corpus - A UTF-8 encoded plain text file that contains a body of text in the target language that is related to what you are translating. A monolingual corpus helps improve literal translations to be more fluent and human.</p>
180172
<p>The Language Translator Node will return the ID of the created customized model.</p>
181173
<p<b>Note:</b>As the input file is expected on msg.payload, only one file can be specified. This is
182174
an enforced restriction by this Node. The service API allows more than one file to be specified.</p>
183175
<p></p>
176+
184177
<p><b>Get Status Mode</b>.</p>
185178
<p>This mode allows you to get the status of a model sent to training by providing its ID.</p>
186179
<p>Values can be the followings:</p>
@@ -189,8 +182,17 @@
189182
<p>error - Training did not complete because of an error. if you want to see the reason behind the error
190183
this will be returned in <code>msg.translation</code></p>
191184
<p>available - Training is completed, and the service is now available to use with your custom translation model.</p>
192-
<p><b>Delete Mode</b>.</p>
193185
<p></p>
186+
187+
<p><b>List Default models Mode</b>.</p>
188+
<p>This mode returns a list of all the default translation models.</p>
189+
<p></p>
190+
191+
<p><b>List Customised models Mode</b>.</p>
192+
<p>This mode returns a list of all the customised translation models.</p>
193+
<p></p>
194+
195+
<p><b>Delete Mode</b>.</p>
194196
<p>This mode allows you to delete a model by providing its ID</p>
195197
<p><b>Parameters Scope</b>.</p>
196198
<p>This parameter makes the language translation node to toogle using incoming parameters form the dashboard Dropdown list or locally.</p>
@@ -295,7 +297,6 @@
295297
$('select#node-input-filetype').parent().hide();
296298
$('input#node-input-trainid').parent().hide();
297299
$('input#node-input-lgparams2').parent().hide();
298-
$('input#node-input-neural').parent().hide();
299300
$('#languagetranslation-form-tips').show();
300301
}
301302
}
@@ -319,14 +320,6 @@
319320
return self.indexOf(value) === index;
320321
}
321322

322-
// Flush the cache
323-
tor.flushModelCache = function () {
324-
tor.models = null;
325-
tor.domains = null;
326-
tor.basemodels = null;
327-
tor.custommodels = null;
328-
tor.checkModels();
329-
}
330323

331324
// Retrieve the available models from the server, if data is returned, then
332325
// can enable the dynamic selection fields.
@@ -337,13 +330,7 @@
337330
var e = $('#node-input-service-endpoint').val();
338331
var creds = {un: u, pwd: p, key: k};
339332

340-
if ($('#node-input-neural').prop('checked')) {
341-
creds.n = 'Y';
342-
}
343-
344-
if (! $('#node-input-default-endpoint').prop('checked')) {
345-
creds.e = e;
346-
}
333+
creds.e = e;
347334

348335
$.getJSON('watson-translator/models/', creds)
349336
.done(function (data) {
@@ -445,12 +432,25 @@
445432
}
446433
}
447434

435+
tor.modelcompare = function(a, b) {
436+
let result = 0;
437+
if (a.model_id && b.model_id) {
438+
if (a.model_id > b.model_id) {
439+
result = 1;
440+
} else if (a.model_id < b.model_id) {
441+
result = -1;
442+
}
443+
}
444+
return result;
445+
}
446+
448447
// Populates the base model field. These are the models that are available to be customised.
449448
tor.checkBaseModels = function () {
450449
if (!tor.basemodels && tor.models) {
451450
tor.basemodels = tor.models.filter(function (model) {
452451
return model.customizable === true;
453452
});
453+
tor.basemodels.sort(tor.modelcompare);
454454
}
455455
if (tor.basemodels) {
456456
$('select#node-input-basemodel').empty();
@@ -517,7 +517,6 @@
517517
$('select#node-input-basemodel, select#node-input-filetype').parent('').hide();
518518
$('input#node-input-trainid').parent('').hide();
519519
$('input#node-input-lgparams2').parent().show();
520-
$('input#node-input-neural').parent().show();
521520
$('#languagetranslation-form-tips').show();
522521
break;
523522
case 'custom':
@@ -527,7 +526,6 @@
527526
$('select#node-input-basemodel, select#node-input-filetype').parent('').hide();
528527
$('input#node-input-trainid').parent('').hide();
529528
$('input#node-input-lgparams2').parent().show();
530-
$('input#node-input-neural').parent().hide();
531529
$('#languagetranslation-form-tips').show();
532530
break;
533531
case 'train':
@@ -537,7 +535,6 @@
537535
$('select#node-input-basemodel, select#node-input-filetype').parent('').show();
538536
$('input#node-input-trainid').parent('').hide();
539537
$('input#node-input-lgparams2').parent().show();
540-
$('input#node-input-neural').parent().hide();
541538
$('#languagetranslation-form-tips').show();
542539
break;
543540
case 'getstatus':
@@ -548,9 +545,17 @@
548545
$('select#node-input-domain').parent().hide();
549546
$('select#node-input-basemodel, select#node-input-filetype').parent('').hide();
550547
$('input#node-input-lgparams2').parent().show();
551-
$('input#node-input-neural').parent().hide();
552548
$('#languagetranslation-form-tips').show();
553549
break;
550+
case 'listcustom':
551+
case 'listdefault':
552+
$('select#node-input-custom').parent().hide();
553+
$('input#node-input-trainid').parent('').hide();
554+
$('select#node-input-srclang, select#node-input-destlang').parent().hide();
555+
$('select#node-input-domain').parent().hide();
556+
$('select#node-input-basemodel, select#node-input-filetype').parent('').hide();
557+
$('input#node-input-lgparams2').parent().hide();
558+
$('#languagetranslation-form-tips').show();
554559
}
555560
tor.checkDomains();
556561
tor.checkBaseModels();
@@ -664,20 +669,6 @@
664669
$('#node-input-basemodel').change(function (val) {
665670
tor.base_model_selected = $('#node-input-basemodel').val();
666671
});
667-
668-
$('#node-input-default-endpoint').change(function () {
669-
var checked = $('#node-input-default-endpoint').prop('checked')
670-
if (checked) {
671-
$('#node-input-service-endpoint').parent().hide();
672-
} else {
673-
$('#node-input-service-endpoint').parent().show();
674-
}
675-
});
676-
677-
$('#node-input-neural').change(function () {
678-
tor.flushModelCache();
679-
});
680-
681672
}
682673

683674
// The dynamic nature of the selection fields in this node has caused problems.
@@ -775,9 +766,7 @@
775766
filetype: {value: 'forcedglossary'},
776767
trainid: {value: ''},
777768
lgparams2: {value: 'lparams'},
778-
neural: {value: false},
779-
'default-endpoint' :{value: true},
780-
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/language-translator/api'}
769+
'service-endpoint' :{value: ''}
781770
},
782771
credentials: {
783772
username: {type: 'text'}

0 commit comments

Comments
 (0)