How to use the string-similarity.findBestMatch function in string-similarity

To help you get started, we’ve selected a few string-similarity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github all-contributors / all-contributors-cli / src / discover / findCategory.js View on Github external
function bestCat(label, showRating = false, log = false) {
  const lbl = label.toLowerCase()
  if (lbl in SIM_EXCEPTIONS) {
    const target = SIM_EXCEPTIONS[lbl]
    return showRating ? {target, rating: 1} : target
  }
  const match = {...strSim.findBestMatch(lbl, CATEGORIES).bestMatch, ref: 'M'}
  const seMatch = {...strSim.findBestMatch(lbl, SE).bestMatch, ref: 'SE'}
  const nclMatch = {
    ...strSim.findBestMatch(lbl, NON_CATEGORY_LABELS).bestMatch,
    ref: 'NC',
  }
  const clMatch = {...strSim.findBestMatch(lbl, CL).bestMatch, ref: 'CL'}

  const scores = [match, seMatch, clMatch, nclMatch].sort(
    (a, b) => b.rating - a.rating,
  )
  if (log) {
    //eslint-disable-next-line no-console
    console.log('scores=', scores)
  }
  let idx = 0
  while (scores[idx++].rating < MATCH_THRESHOLD && idx < scores.length) {
    /*  */
github nitin42 / terminal-in-react / src / js / args / utils.js View on Github external
}
      const related = this.isDefined(option, 'options');

      if (related) {
        const details = this.readOption(related);
        Object.assign(options, details);
      }

      if (!related && !definedSubcommand) {
        // Unknown Option
        const availableOptions = [];
        this.details.options.forEach((opt) => {
          availableOptions.push(...opt.usage);
        });

        const suggestOption = stringSimilarity.findBestMatch(
          option,
          availableOptions,
        );

        console.log(`The option "${option}" is unknown.`); // eslint-disable-line

        if (suggestOption.bestMatch.rating >= 0.5) {
          console.log(' Did you mean the following one?\n'); // eslint-disable-line

          const suggestion = this.details.options.filter((item) => {
            for (const flag of item.usage) {
              if (flag === suggestOption.bestMatch.target) {
                return true;
              }
            }
github bcgov / devhub-app-web / app-web / gatsby / utils / validators.js View on Github external
const getClosest = (value, list) => {
  const matches = stringSimilarity.findBestMatch(value, list);
  // only return the best match if its greater than .5 in similarity
  return matches.bestMatch.rating >= 0.5 ? matches.bestMatch.target : '';
};
github all-contributors / all-contributors-cli / src / discover / findCategory.js View on Github external
function bestCat(label, showRating = false, log = false) {
  const lbl = label.toLowerCase()
  if (lbl in SIM_EXCEPTIONS) {
    const target = SIM_EXCEPTIONS[lbl]
    return showRating ? {target, rating: 1} : target
  }
  const match = {...strSim.findBestMatch(lbl, CATEGORIES).bestMatch, ref: 'M'}
  const seMatch = {...strSim.findBestMatch(lbl, SE).bestMatch, ref: 'SE'}
  const nclMatch = {
    ...strSim.findBestMatch(lbl, NON_CATEGORY_LABELS).bestMatch,
    ref: 'NC',
  }
  const clMatch = {...strSim.findBestMatch(lbl, CL).bestMatch, ref: 'CL'}

  const scores = [match, seMatch, clMatch, nclMatch].sort(
    (a, b) => b.rating - a.rating,
  )
  if (log) {
    //eslint-disable-next-line no-console
    console.log('scores=', scores)
  }
  let idx = 0
  while (scores[idx++].rating < MATCH_THRESHOLD && idx < scores.length) {
github Sync-Codes / Ajax / commands / avatar.js View on Github external
module.exports.run = async (bot, message, args) => {
  if(message.author.bot) return;
  if(message.channel.type !== "text") return;
  
  let members = [];
  let indexes = [];
  
  message.guild.members.forEach(function(member){
    members.push(member.user.username);
    indexes.push(member.id);
  })
  
  let match = sm.findBestMatch(args.join(' '), members);
  let username = match.bestMatch.target;
  
    let member = message.guild.members.get(indexes[members.indexOf(username)])
    
     let definedUser = "";
     let definedUser2 = "";
    if(!args[0]) {
      definedUser = message.author
      definedUser2 = message.member
    } else {
      let mention = message.mentions.users.first()
      definedUser = mention || member.user
        definedUser2 = message.mentions.members.first() || message.guild.members.get(args[0]) || member
    }
    
    message.channel.send({embed: new Discord.RichEmbed()
github jhwohlgemuth / tomo-cli / src / utils / index.js View on Github external
export const getIntendedInput = (commands, command, terms = []) => {
    const VALID_COMMANDS = keys(commands);
    const {bestMatch: {target: intendedCommand}} = findBestMatch(command, VALID_COMMANDS);
    const VALID_TERMS = keys(commands[intendedCommand]);
    const intendedTerms = terms.map(term => findBestMatch(term, VALID_TERMS).bestMatch.target);
    return {intendedCommand, intendedTerms};
};
/**
github microsoft / BotFramework-WebChat / samples / 19.a.single-sign-on-for-enterprise-apps / bot / src / createBot.js View on Github external
function guessQuestion(message) {
  const match = findBestMatch(message, Object.values(QUESTIONS));

  if (match.bestMatch.rating > 0.5) {
    return Object.keys(QUESTIONS)[match.bestMatchIndex];
  }
}
github hobochild / js-fire / index.js View on Github external
.map(flag => {
      if (!argNames.includes(flag)) {
        const match = stringSimilarity.findBestMatch(flag, argNames).bestMatch

        throw new FlagNotFoundError(
          chalk.red(`Error: Flag ${chalk.red.underline(flag)} not found\n`) +
            (match.rating > 0.4
              ? chalk.yellow(
                  `Did you mean: ${chalk.yellow.underline(match.target)} ?`,
                )
              : '') +
            '\n' +
            functionHelpText(fn),
        )
      }
    })

string-similarity

Finds degree of similarity between strings, based on Dice's Coefficient, which is mostly better than Levenshtein distance.

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis