node-red-node-watson
Version:
A collection of Node-RED nodes for IBM Watson services
192 lines (170 loc) • 8.58 kB
HTML
<!--
Copyright 2013,2022 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="watson-natural-language-classifier">
<div id="credentials-check" class="form-row">
<div class="form-tips">
<i class="fa fa-question-circle"></i><b> Please wait: </b> Checking for bound service credentials...
</div>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row credentials" style="display: none;">
<label for="node-input-apikey"><i class="fa fa-key"></i> API Key</label>
<input type="password" id="node-input-apikey" placeholder="API Key"></input>
</div>
<div class="form-row credentials">
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/natural-language-classifier/api">
</div>
<div class="form-row">
<label for="node-input-mode"><i class="fa fa-question"></i> Mode</label>
<select type="text" id="node-input-mode" style="display: inline-block; width: 70%;" >
<option value="classify">Classify</option>
<option value="createClassifier">Train</option>
<option value="listClassifiers">List</option>
<option value="getClassifier">Classifier details</option>
<option value="deleteClassifier">Remove</option>
</select>
</div>
<div class="form-row mode classify getClassifier deleteClassifier">
<label for="node-input-classifier"><i class="fa fa-tag"></i> Classifier ID</label>
<input type="text" id="node-input-classifier" placeholder="Classifier ID">
</div>
<div class="form-row mode createClassifier">
<label for="node-input-language"><i class="fa fa-language"></i> Language</label>
<select type="text" id="node-input-language" style="display: inline-block; width: 70%;" >
<option value="ar">Arabic</option>
<option value="en">English</option>
<option value="de">German</option>
<option value="fr">French</option>
<option value="it">Italian</option>
<option value="ja">Japanese</option>
<option value="ko">Korean</option>
<option value="pt">Portuguese</option>
<option value="es">Spanish</option>
</select>
</div>
<div class="form-row mode classify">
<label> </label>
<input type="checkbox" id="node-input-collections-off" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-collections-off" style="width: 70%;"> Do not auto detect collections</label>
</div>
</script>
<script type="text/x-red" data-help-name="watson-natural-language-classifier">
<p>The Natural Language Classifier service uses machine learning algorithms to return the top matching predefined classes for short text inputs.</p>
<p>The node can either train new classifiers or match text against existing classifiers.
Use the drop-down menu in the node configuration window to select the mode.</p>
<p></p>
<p><b>Classifier Mode</b>.</p>
<p>Set the classifier id in the node configuration window.</p>
<p>The classifier can be overriden by setting msg.nlcparams.classifier_id</p>
<p>The text to classify should be passed in on <code>msg.payload</code>.</p>
<p> If <code>msg.payload</code> contains multiple sentences then the sentences will
be split and the set will be classified as a collection. If there are no sentence
terminators then it will not be recognised as a sentence.
</p>
<p> If <code>msg.payload</code> contains an array of strings, then each string will be
treated as a separate sentence and the set treated as a collection. </p>
<p>If <code>msg.payload</code> contains an array of objects, then there is a
search for the <code>text</code> key in each object. Each text object will be
treated as part of the collection.</p>
<p>The returned classification and confidence values will be returned on <code>msg.payload</code>.</p>
<p></p>
<p><b>Training Mode</b>.</p>
<p>Set the training data language in the node configuration window.</p>
<p>The CSV training data should be passed in on <code>msg.payload</code> as a String or String Array. For more details on the training data format, see this <a href="https://console.bluemix.net/docs/services/natural-language-classifier/using-your-data.html">link</a></p>
<p>The returned classification training status will be returned on <code>msg.payload</code>.</p>
<p><b>List Mode</b>.</p>
<p>Set the mode in the node configuration window.</p>
<p>The request is triggered by a request to the input node
<p>The returned list of classifiers will be returned on <code>msg.payload</code>.</p>
<p><b>Classifier Details Mode</b>.</p>
<p>Set the mode in the node configuration window.</p>
<p>If not set in the configuration the Classifier ID should be passed in on
<code>msg.payload</code> as a String<p>
<p>The details of the classifier be returned on <code>msg.payload</code>.</p>
<p><b>Remove Mode</b>.</p>
<p>Set the mode in the node configuration window.</p>
<p>The status of the delete be returned on <code>msg.payload</code>. It will contain {} if successful.
<p>For more information about the Natural Language Classifier service, read the <a href="http://www.ibm.com/watson/developercloud/natural-language-classifier/api/v1/">documentation</a>.</p>
</script>
<script type="text/javascript">
// Need to simulate a namespace, so that some of the variables don't leak across nodes
function NaturalLanguageClassifierV1 () {}
// This is the namespace for this version of this Node.
var nlcV1 = new NaturalLanguageClassifierV1();
nlcV1.CreateIListener = function(listen, action, opp) {
opp = typeof opp === 'undefined' ? false : opp;
listen.change(function(val){
var isSet = listen.prop('checked');
if (opp) {
isSet = !isSet;
}
nluV1.setVisibility(action, isSet);
});
}
nlcV1.UIListeners = function () {
$('#node-input-mode').change(function () {
var mode = $('#node-input-mode').val();
$('.form-row.mode.' + mode).show();
$('.form-row.mode:not(.' + mode + ')').hide();
});
};
nlcV1.checkForPrepare = function () {
nlcV1.UIListeners();
};
// This is the on edit prepare function, which will be
//invoked everytime the dialog is shown.
function nlconeditprepare() {
nlcV1.checkForPrepare();
$.getJSON('watson-natural-language-classifier/vcap/')
.done(function (service) {
$('.credentials').toggle(!service);
})
.fail(function () {
$('.credentials').show();
}).always(function () {
$('#credentials-check').hide();
})
}
(function() {
RED.nodes.registerType('watson-natural-language-classifier', {
category: 'IBM Watson',
defaults: {
name: {value: ""},
mode: {value: "classify"},
language: {value: "en"},
classifier: {value: ""},
'collections-off' :{value: true},
'service-endpoint' :{value: ''}
},
credentials: {
apikey: {type: 'password'}
},
color: "rgb(140, 198, 63)",
inputs: 1,
outputs: 1,
icon: "NLClassifier.png",
paletteLabel: "natural language classifier",
label: function() {
return this.name || "natural language classifier";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: nlconeditprepare
});
})();
</script>