Skip to content

Commit 72bb6ab

Browse files
committed
2 parents 98e7f3e + c257069 commit 72bb6ab

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

services/language_translation/v2.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,33 @@
7676
</script>
7777

7878
<script type="text/x-red" data-help-name="watson-translate">
79-
<p>The Language Translation service enables you to translate text from one language to another.</p>
79+
<p>The Language Translation service enables you to translate text from one language to another and to add your own translation models.</p>
80+
<p></p>
81+
<p><b>Translation Mode</b>.</p>
8082
<p>The text to translate should be passed in on <code>msg.payload</code>.</p>
8183
<p>The translated text will be returned on <code>msg.payload</code>.</p>
8284
<p>Source and destination language parameters can be configured through the editor panel or set dynamically using
8385
the language codes in the following properties, <code>msg.srclang</code> and <code>msg.destlang</code>. Please see
8486
the documentation linked below for the currently supported source and destination language codes.</p>
87+
<p></p>
88+
<p><b>Training Mode</b>.</p>
89+
<p>This mode enables you to add your own customized model to the Watson translation service. </p>
90+
<p>In the Dropbox node, you must specify one ore more of the following file options to customize the training:</p>
91+
<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>
92+
<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>
93+
<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>
94+
<p>The Language Translation Node will return the ID of the created customized model.</p>
95+
<p></p>
96+
<p><b>Get Status Mode</b>.</p>
97+
<p>This mode allows you to get the status of a model sent to training by providing its ID.</p>
98+
<p>Values can be the followings:</p>
99+
<p>training - Training is still in progress.</p>
100+
<p>queued@<#> - Training has not yet started and the model is in the queue. The # indicates the number of your model in the queue.</p>
101+
<p>error - Training did not complete because of an error.</p>
102+
<p>available - Training is completed, and the service is now available to use with your custom translation model.</p>
103+
<p><b>Delete Mode</b>.</p>
104+
<p></p>
105+
<p>This mode allows you to delete a model by providing its ID</p>
85106
<p>For more information about the Language Translation service, read the <a href="http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/language-translation.html">documentation</a>.</p>
86107
</script>
87108

@@ -346,7 +367,7 @@
346367
domain: {
347368
value: 'news'
348369
},
349-
dbase_model: {
370+
basemodel: {
350371
value: ''
351372
},
352373
action: {

services/language_translation/v2.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ module.exports = function (RED) {
9999
});
100100
};
101101

102-
this.doTrain = function (msg, model_id, filetype) {
102+
this.doTrain = function (msg, basemodel, filetype) {
103103
language_translation = watson.language_translation({
104104
username: username,
105105
password: password,
@@ -122,21 +122,21 @@ module.exports = function (RED) {
122122
case 'forcedglossary':
123123
params = {
124124
name: msg.filename.replace(/[^0-9a-z]/gi, ''),
125-
base_model_id: model_id,
125+
base_model_id: basemodel,
126126
forced_glossary: fs.createReadStream(info.path)
127127
};
128128
break;
129129
case 'parallelcorpus':
130130
params = {
131131
name: msg.filename.replace(/[^0-9a-z]/gi, ''),
132-
base_model_id: model_id,
132+
base_model_id: basemodel,
133133
parallel_corpus: fs.createReadStream(info.path)
134134
};
135135
break;
136136
case 'monolingualcorpus':
137137
params = {
138138
name: msg.filename.replace(/[^0-9a-z]/gi, ''),
139-
base_model_id: model_id,
139+
base_model_id: basemodel,
140140
monolingual_corpus: fs.createReadStream(info.path)
141141
};
142142
break;
@@ -159,7 +159,6 @@ module.exports = function (RED) {
159159
text: 'model sent to training'
160160
});
161161
msg.payload = 'Model ' + model.name + ' successfully sent for training with id: ' + model.model_id;
162-
msg.id = model_id;
163162
node.send(msg);
164163
node.status({});
165164
}
@@ -213,7 +212,7 @@ module.exports = function (RED) {
213212
text: 'deleting'
214213
});
215214

216-
language_translation.deleteModel({ model_id:'{model_id}'},
215+
language_translation.deleteModel({ model_id: trainid},
217216
function(err) {
218217
node.status({});
219218
if (err) {
@@ -223,6 +222,10 @@ module.exports = function (RED) {
223222
text: 'could not delete'
224223
});
225224
node.error(err, msg);
225+
} else {
226+
msg.payload = "model deleted";
227+
node.send(msg);
228+
node.status({});
226229
}
227230
}
228231
);
@@ -306,13 +309,12 @@ module.exports = function (RED) {
306309
} else {
307310
model_id = srclang + '-' + destlang + '-' + domain;
308311
}
309-
310312
switch (action) {
311313
case 'translate':
312314
this.doTranslate(msg, model_id);
313315
break;
314316
case 'train':
315-
this.doTrain(msg, model_id, filetype);
317+
this.doTrain(msg, basemodel, filetype);
316318
break;
317319
case 'getstatus':
318320
this.doGetStatus(msg, trainid);

0 commit comments

Comments
 (0)