1.1.1 • Published 3 years ago

fuzzy-phrase-classifier v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

fuzzy-phrase-classifier npm version TypeScript License: MIT

Types | Functions

  • getBestFitForAll()
  • applyBestFitForAll()
  • Phrase
  • PhrasedResult
  • Phraseable

getBestFitForAll(strings: string[], phrases: Phrase[]): PhrasedResult[]

Function that takes strings and the phrases to be used in comparison and will return the best fit results.

ParameterDescription
stringsIs compared with each phrase in @phrases parameter
phrasesContains the pattern and phraseName objects that the @strings will be classified to
import { Phrase, getBestFitForAll } from "fuzzy-phrase-classifier";

const strings = [
  "The i o of the World",
  "The good Hunt",
  "The Dragqueen Reborn",
  "What Great Hunt?",
  "The iye of what Word?"
];

const phrases: Phrase[] = [
  { 
    "PhraseName": "The first book in the series",
    "Pattern": "The Eye of the World" 
  },    
  { 
    "PhraseName": "The second book in the series",
    "Pattern": "The Great Hunt" 
  },
  { 
    "PhraseName": "The third book in the series",
    "Pattern": "The Dragon Reborn" 
  }
];

console.log(getBestFitForAll(strings, phrases));

applyBestFitForAll(phraseables: Phraseable[], phrases: Phrase[]): void

Function that takes Phraseable objects and the phrases to be used in comparisons and will apply the best fit results into the appropriate properties of the working Phraseable object.

ParameterDescription
phraseablesIs compared with each phrase in the @phrases parameter using it's text property
phrasesContains the pattern and phraseName objects that the @phraseables will be classified to
import { applyBestFitForAll } from "fuzzy-phrase-classifier";

const strings = [
  "The i o of the World",
  "The good Hunt",
  "The Dragqueen Reborn",
  "What Great Hunt?",
  "The iye of what Word?"
];

const phrases: Phrase[] = [
  { 
    "PhraseName": "The first book in the series",
    "Pattern": "The Eye of the World" 
  },    
  { 
    "PhraseName": "The second book in the series",
    "Pattern": "The Great Hunt" 
  },
  { 
    "PhraseName": "The third book in the series",
    "Pattern": "The Dragon Reborn" 
  }
];

class ExampleClass {
  text; // Raw text to be used in comparisons
  score; // Best score result
  bestFitPhrase; // Best fit phrase string

  constructor(text) {
    this.text = text;
  }
}

const phraseables = strings.map(text => new ExampleClass(text));

phraser.applyBestFitForAll(phraseables, phrases);
console.log(phraseables);

Phrase: interface

The Phrase interface is a structure that defines a phraseName and a pattern required for the fuzzy string searching.

PropertyDescription
PhraseNameName of the phrase
PatternString to be searched and matched with

PhrasedResult: class

The PhraseResult class is used to contain the results from a fuzzy string search.

PropertyDescription
indexIndex of the text in the original collection
bestFitPhraseBest fit phrase identifier
scoreDecimal number from 0 to 1 like a percentage showing how sure the algorithm was of the match
textReference to the text this PhrasedResult correlates to

Phraseable: interface

The Phraseable interface is a structure that defines text, score, and bestFitPhrase properties for use.

PropertyData FlowDescription
textinText that will be used in comparisons for this object
bestFitPhraseoutBest fit phrase identifier
scoreoutDecimal number from 0 to 1 like a percentage showing how sure the algorithm was of the match

Dependencies