node-red-contrib-fuzzywuzzy
Version:
Fuzzy string matching for node red. Can be used for intent recognition.
159 lines (153 loc) • 5.45 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('fuzzy-match', {
category: 'function',
color: '#FFAAAA',
defaults: {
name: { value: "" },
inputOptions : { value: "text" },
choices : { value: "" },
scorer : { value : 'WRatio' }, // scorer function
limit: { value: '0', validate:RED.validators.number() }, // Max number of top results to return, default: no limit / 0.
cutoff: { value: '0', validate:RED.validators.number() }, // Lowest score to return, default: 0
},
inputs:1,
outputs:2,
outputLabels: [ "best match", "alternatives" ],
icon: "font-awesome/fa-search",
label: function() {
return this.name || "fuzzy-match"
},
oneditprepare: function() {
this.editor = RED.editor.createEditor({
id: 'node-input-choices-editor',
mode: 'ace/mode/text',
value: this.choices
});
$("#node-input-inputOptions").on("change", function(){
let option = $("#node-input-inputOptions").val();
if(option == "text"){
$("#textField").show();
} else if (option == "message") {
$("#textField").hide();
}
});
},
oneditsave: function() {
this.choices = this.editor.getValue()
this.editor.destroy()
delete this.editor
},
oneditcancel: function() {
this.editor.destroy()
delete this.editor
}
})
</script>
<script type="text/html" data-template-name="fuzzy-match">
<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">
<label for="node-input-inputOptions">Source</label>
<select id="node-input-inputOptions" style="width:270px !important">
<option value="text">enter choices in config</option>
<option value="message">set choices by msg.choices</option>
</select>
</div>
<div class="form-row" id="textField">
<label for="node-input-choices-editor">Choices</label>
<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-choices-editor"></div>
</div>
<div class="form-row">
<label for="node-input-scorer">Scoring</label>
<select id="node-input-scorer" style="width:270px !important">
<option value="WRatio">WRatio</option>
<option value="ratio">simple_ratio</option>
<option value="partial_ratio">partial_ratio</option>
<option value="token_sort_ratio">token_sort_ratio</option>
<option value="token_set_ratio">token_set_ratio</option>
<option value="distance">distance</option>
</select>
</div>
<div class="form-row">
<label for="node-input-limit">Limit</label>
<input type="number" id="node-input-limit" placeholder="Maximum number of results" min="0">
</div>
<div class="form-row">
<label for="node-input-cutoff">Cutoff</label>
<input type="number" id="node-input-cutoff" placeholder="Lowest score to return" min="0" max="100">
</div>
</script>
<script type="text/html" data-help-name="fuzzy-match">
<p>Fuzzy string matching for node red.</p>
<h3>Options</h3>
<dl class="message-properties">
<dt>Choices
<span class="property-type">string</span>
</dt>
<dd>
Each line contains one choice. Keys can optionaly be supplied.
<pre>
# without key:
Hello
Hi
Goodbye
# with key:
key1:Hello
key1:Hi
key2:Goodbye
</pre>
</dd>
<dt>Method
<span class="property-type">Scoring</span>
</dt>
<dd>
Selects what scoring funcion to use. Read about the scoring functions here: <a href="https://github.com/nol13/fuzzball.js">https://github.com/nol13/fuzzball.js</a>
</dd>
<dt>Limit
<span class="property-type">number</span>
</dt>
<dd>
Maximum returned results.
</dd>
<dt>Cutoff
<span class="property-type">number</span>
</dt>
<dd>
Only return results with a score higher than the cutoff value.
</dd>
</dl>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">string</span> </dt>
<dd>
The string to match against the choices from the node config</code>
</dd>
<dt>choices <span class="property-type">string</span> </dt>
<dd>
Works only in "set choices with msg.choices" mode.
A string containing lines of choices as specified in the node config.
Will overwrite the choices that were set previously.</code>
</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>best match
<dl class="message-properties">
<dt>match <span class="property-type">object</span></dt>
<dd>an object containing information on the match</dd>
</dl>
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>a string with the key of the match</dd>
</dl>
</li>
<li>best match
<dl class="message-properties">
<dt>payload <span class="property-type">string</span></dt>
<dd>an ordered array with the matching scores and keys</dd>
</dl>
</li>
</ol>
</script>