CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
README.md135 linesDownload Raw Back to didyoumean
1didYouMean.js - A simple JavaScript matching engine2===================================================3 4[Available on GitHub](https://github.com/dcporter/didyoumean.js).5 6A super-simple, highly optimized JS library for matching human-quality input to a list of potential7matches. You can use it to suggest a misspelled command-line utility option to a user, or to offer8links to nearby valid URLs on your 404 page. (The examples below are taken from a personal project,9my [HTML5 business card](http://dcporter.aws.af.cm/me), which uses didYouMean.js to suggest correct10URLs from misspelled ones, such as [dcporter.aws.af.cm/me/instagarm](http://dcporter.aws.af.cm/me/instagarm).)11Uses the [Levenshtein distance algorithm](https://en.wikipedia.org/wiki/Levenshtein_distance).12 13didYouMean.js works in the browser as well as in node.js. To install it for use in node:14 15```16npm install didyoumean17```18 19 20Examples21--------22 23Matching against a list of strings:24```25var input = 'insargrm'26var list = ['facebook', 'twitter', 'instagram', 'linkedin'];27console.log(didYouMean(input, list));28> 'instagram'29// The method matches 'insargrm' to 'instagram'.30 31input = 'google plus';32console.log(didYouMean(input, list));33> null34// The method was unable to find 'google plus' in the list of options.35```36 37Matching against a list of objects:38```39var input = 'insargrm';40var list = [ { id: 'facebook' }, { id: 'twitter' }, { id: 'instagram' }, { id: 'linkedin' } ];41var key = 'id';42console.log(didYouMean(input, list, key));43> 'instagram'44// The method returns the matching value.45 46didYouMean.returnWinningObject = true;47console.log(didYouMean(input, list, key));48> { id: 'instagram' }49// The method returns the matching object.50```51 52 53didYouMean(str, list, [key])54----------------------------55 56- str: The string input to match.57- list: An array of strings or objects to match against.58- key (OPTIONAL): If your list array contains objects, you must specify the key which contains the string59  to match against.60 61Returns: the closest matching string, or null if no strings exceed the threshold.62 63 64Options65-------66 67Options are set on the didYouMean function object. You may change them at any time.68 69### threshold70 71  By default, the method will only return strings whose edit distance is less than 40% (0.4x) of their length.72  For example, if a ten-letter string is five edits away from its nearest match, the method will return null.73 74  You can control this by setting the "threshold" value on the didYouMean function. For example, to set the75  edit distance threshold to 50% of the input string's length:76 77  ```78  didYouMean.threshold = 0.5;79  ```80 81  To return the nearest match no matter the threshold, set this value to null.82 83### thresholdAbsolute84 85  This option behaves the same as threshold, but instead takes an integer number of edit steps. For example,86  if thresholdAbsolute is set to 20 (the default), then the method will only return strings whose edit distance87  is less than 20. Both options apply.88 89### caseSensitive90 91  By default, the method will perform case-insensitive comparisons. If you wish to force case sensitivity, set92  the "caseSensitive" value to true:93 94  ```95  didYouMean.caseSensitive = true;96  ```97 98### nullResultValue99 100  By default, the method will return null if there is no sufficiently close match. You can change this value here.101 102### returnWinningObject103 104  By default, the method will return the winning string value (if any). If your list contains objects rather105  than strings, you may set returnWinningObject to true.106  107  ```108  didYouMean.returnWinningObject = true;109  ```110  111  This option has no effect on lists of strings.112 113### returnFirstMatch114  115  By default, the method will search all values and return the closest match. If you're simply looking for a "good-116  enough" match, you can set your thresholds appropriately and set returnFirstMatch to true to substantially speed117  things up.118 119 120License121-------122 123didYouMean copyright (c) 2013-2014 Dave Porter.124 125Licensed under the Apache License, Version 2.0 (the "License");126you may not use this file except in compliance with the License.127You may obtain a copy of the License128[here](http://www.apache.org/licenses/LICENSE-2.0).129 130Unless required by applicable law or agreed to in writing, software131distributed under the License is distributed on an "AS IS" BASIS,132WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.133See the License for the specific language governing permissions and134limitations under the License.135 
basant307/AI_Governance_Project · CoolFace