Hello,
Anybody know a fuzzy search library like Fuse.js compatible with ionic2 ?
Thx
Hello,
Anybody know a fuzzy search library like Fuse.js compatible with ionic2 ?
Thx
This is an old thread, but its a useful one to have a solution for. I just had the same need.
Anyone using āspeech recognitionā in their app to match to known tags will likely need to use both ionic/cordovaās speech recognition plugin followed by fuzzy match. Iāve often found the first match returned by the speech recognition service is not the right one Iād expect and a match lower in the returned array is ācloserā to my speech, but programatically there is no way for me to select one over the other unless I do a fuzzy match.
The latest fuse.js (well, since Dec 2016, it seems) is compatible with typescript and includes typescript bindings.
Usage:
I have an array of markers that āmarkā specific events. I just added speech to text using Ionic SpeechRecognition - folks can speak out the markers instead of tapping buttons. As it turns out, fuzzy search added much more accuracy to just plain speech to text
Marker array:
markers = [
// good markers
{ name: 'turn', val: 'turn', color: 'light' , speech: 'turn'},
{ name: 'brake', val: 'brake', color: 'light', speech: 'brake' },
{ name: 'unknown', val: 'unknown', color: 'light', speech: 'unknown' },
// bad markers
{ name: 'brake', val: 'hard-brake', color: 'alert', speech: 'hard brake' },
{ name: 'distract', val: 'distract', color: 'alert', speech: 'distract' },
{ name: 'speedup', val: 'speedup', color: 'alert', speech: 'speed up' },
{ name: 'turn', val: 'sharp-turn', color: 'alert' , speech: 'sharp turn'},
]
So letās say I need to match what the user says to the values in the āspeechā key of the marker array. Here is how I use fuse.js with the returned speech text:
npm install fuse.js --save
In index.html:
<script src="node_modules/fuse.js/dist/fuse.min.js"> </script>
In the .ts file I need to implement fuzzy search:
import * as Fuse from 'fuse.js';
myFuseOptions: Fuse.FuseOptions = {
caseSensitive: false,
keys: ['speech'],
shouldSort: true,
};
myFuse = new Fuse(this.markers, this.myFuseOptions);
After you get your speech converted to text:
let fuzzy = this.myFuse.search(s); // s = speech to text string
if (!fuzzy.length) {
console.log ("Fuzzy search failed, going with manual sanitization");
// whatever I need to do
}
else {
s = fuzzy[0]["val"];
console.log ("Fuzzy returned: "+s);
}