5.3.0 • Published 1 year ago

synonym-optimizer v5.3.0

Weekly downloads
155
License
Apache-2.0
Repository
-
Last release
1 year ago

synonym-optimizer

Gives a score to a string depending on the variety of the synonyms used.

For instance, let's compare The coffee is good. I love that coffee with The coffee is good. I love that bewerage. The second alternative is better because a synonym is used for coffee. This module will give a better score to the second alternative.

The lowest score the better.

Fully supported languages are French German English Italian and Spanish.

What it does / How it works:

  • single words are extracted thanks to a tokenizer wink-tokenizer
  • words are lowercased
  • stopwords are removed
    • for fully supported languages, a default stopwords list is included, which you can customize
    • for all other languages, no default list is included, but you can provide a custom stop words lists
  • for fully supported languages, words are stemmed using snowball-stemmer (for all other languages: no stemming)
  • when the same word appears multiples times, it raises the score depending on the distance of the two occurrences (if the occurrences are closes it raises the score a lot)

Designed primarly to test the output of a NLG (Natural Language Generation) system.

The stemmer is not perfect. For instance in Italian, cameriere and cameriera have the same stem (camerier), while camerieri and cameriera have a different one (camer and camerier).

Installation

npm install synonym-optimizer

Usage

var synOptimizer = require('synonym-optimizer');

alts = [
  'The coffee is good. I love that coffee.',
  'The coffee is good. I love that bewerage.'
]

/*
The coffee is good. I love that coffee.: 0.5
The coffee is good. I love that bewerage.: 0
*/
alts.forEach((alt) => {
  let score = synOptimizer.scoreAlternative('en_US', alt, null, null, null, null);
  console.log(`${alt}: ${score}`);
});

The main function is scoreAlternative. It takes a string and returns its score. Arguments are:

  • lang (string, mandatory): the language.
    • fully supported languages are fr_FR, en_US, de_DE, it_IT and es_ES
    • with any other language (for instance Dutch nl_NL) stemming is disabled and stopwords are not removed
  • alternative (string, mandatory): the string to score
  • stopWordsToAdd (string[], optional): list of stopwords to add to the standard stopwords list
  • stopWordsToRemove (string[], optional): list of stopwords to remove to the standard stopwords list
  • stopWordsOverride (string[], optional): replaces the standard stopword list
  • identicals (string, optional): list of words that should be considered as beeing identical, for instance [ ['phone', 'cellphone', 'smartphone'] ].

You can also use the getBest function. Most arguments are exactly the same, but instead of alternative, use alternatives (string[]). The output number will not be the score, but simply the index of the best alternative.

The tokenizer is wink-tokenizer, it does works with many languages (English, French, German, Hindi, Sanskrit, Marathi etc.) but not asian languages. Therefore the module will not work properly with Japanese, Chinese etc.

Adding new languages (for developpers / maintainers)

  • check for existence of stopwords module: stopwords-*
  • check for stemmer in snowball-stemmer collection (or plug another stemmer)
  • plug everything and add tests
  • find a proper tokenizer if wink-tokenizer does not work

Misc

The build writes stopwords a asciidoc in the rosaenlg-doc module.

Dependencies and licences

  • wink-tokenizer to tokenize sentences in multiple languages (MIT).
  • stopwords-en/de/fs/it/es for standard stopwords lists per language (MIT).
  • snowball-stemmer to stem words per language (MIT).
5.3.0

1 year ago

5.2.2

1 year ago

5.2.1

1 year ago

5.2.0

1 year ago

4.4.0

2 years ago

5.0.0

2 years ago

4.3.1

2 years ago

4.3.0

2 years ago

5.1.0

2 years ago

4.2.6

2 years ago

4.2.3

2 years ago

4.2.5

2 years ago

4.2.4

2 years ago

4.2.2

2 years ago

4.2.1

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.1.9

3 years ago

3.1.8

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.20.2

4 years ago

2.20.1

4 years ago

2.20.0

4 years ago

2.19.0

4 years ago

2.18.1

4 years ago

2.18.0

4 years ago

2.17.2

4 years ago

2.17.1

4 years ago

2.17.0

4 years ago

2.16.10

4 years ago

2.16.9

4 years ago

2.16.7

4 years ago

2.16.8

4 years ago

2.16.6

4 years ago

2.16.5

4 years ago

2.16.4

4 years ago

2.16.3

4 years ago

2.16.2

4 years ago

2.16.1

4 years ago

2.16.0

4 years ago

2.15.4

4 years ago

2.15.3

4 years ago

2.15.2

4 years ago

2.15.1

4 years ago

2.15.0

4 years ago

2.14.3

4 years ago

2.14.2

4 years ago

2.14.1

5 years ago

2.14.0

5 years ago

2.13.0

5 years ago

2.12.3

5 years ago

2.12.2

5 years ago

2.12.0

5 years ago

2.12.1

5 years ago

2.11.0

5 years ago

2.10.2

5 years ago

2.10.1

5 years ago

2.10.0

5 years ago

2.9.2

5 years ago

2.9.1

5 years ago

2.9.0

5 years ago

2.8.3

5 years ago

2.8.2

5 years ago

2.8.0

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.6.2

5 years ago

2.5.8

5 years ago

2.5.7

5 years ago

2.5.6

5 years ago

2.5.5

5 years ago

2.5.4

5 years ago

2.5.3

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.4

5 years ago