synonym-expander

Tool for expanding strings into every possible state given a set of word / phrase synonyms

Usage no npm install needed!

<script type="module">
  import synonymExpander from 'https://cdn.skypack.dev/synonym-expander';
</script>

README

Synonym Expander

Tool for expanding strings into every possible state given a set of word / phrase synonyms

Synonym sets are expressed as a list of lists. You initialise the expander with synonyms, like this:

import SynonymExpander from 'synonym-expander'

const synonyms = [
  ["nice", "okay", "fine"],
  ["it's", "it is"]
]

const expander = new SynonymExpander(...synonyms)

When you pass a string to the expanders expand function you will receive a list of all permutations of the string in which synonyms are replaced with each of their alternatives

...

const input = "i think it is nice"

const result = expander.expand(input)

console.log(result)

/*
  i think it is nice
  i think it is okay
  i think it is fine
  i think it's nice
  i think it's okay
  i think it's fine
*/