# ngrams-search

> search by Ngram similarity. An emitation of the python NGram module

Latest version **0.0.4** (published 2015-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngrams-search
pnpm add ngrams-search
yarn add ngrams-search
bun add ngrams-search
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2015-11-25 |
| First published | 2015-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Aviv Ron |
| Maintainers | aviv1ron1 |
| Keywords | ngram, ngrams, ngram search, ngrams search, search |

## Links

- npm: https://www.npmjs.com/package/ngrams-search
- Repository: https://github.com/aviv1ron1/ngrams
- Homepage: https://github.com/aviv1ron1/ngrams#readme
- Issues: https://github.com/aviv1ron1/ngrams/issues
- npm.io page: https://npm.io/package/ngrams-search

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.0.4 (latest) — 2015-11-25
- 0.0.3 — 2015-11-25
- 0.0.2 — 2015-11-25
- 0.0.1 — 2015-11-25

## README

# ngrams
nodejs module for [searching by Ngram](https://en.wikipedia.org/wiki/N-gram) similarity of characters. An emitation of the [python](https://pythonhosted.org/ngram/ngram.html) NGram module

[![npm package](https://nodei.co/npm/ngram-search.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/ngram-search/)


## basic usage

```javascript
var NGrams = require('ngram-search');
var n = new NGrams()    //default N=3 (size of ngram) w=1 (warp, use greater than 1 to increase the similarity of shorter string pairs)
n.add("spam");          //add single items
n.add(["span", "eg"]);  //or an array of items
console.log(n.search("spa"));   // second argument is optional - threshold - return only items with similarity greater than threshold. default is 0
/*
will output an array of items with similarity greater than threshold ordered by similarity
//[{
    item: "spam",
    similarity: 0.375
}, {
    item: "span",
    similarity: 0.375
}]
*/

n.getMaxNgram("spam");    
/*
returns the item with the maximum ngram similarity or undefined if none
{
    item: "spam",
    similarity: 1.0
}
*/
```

## more usage examples
```javascript
var n = new NGrams(2);  //create ngrams of size 2
n.pad("word");           //returns " word " padding is of size N-1
n.split("ab");
/*
returns the ngrams of the item "ab" after padding
[
  [' ', 'a'],
  ['a', 'b'],
  ['b', ' ']
]
*/

n.getSharedNgrams("abe", "abc");
/*
returns all the ngrams that both items share:
[
  [' ', 'a'],
  ['a', 'b']
]
*/
n.getCountSharedNgrams("abe", "abc");    // returns 2
n.getStatsSharedNgrams("abe", "abc");
/*
returns
{ 
  all: 8,         //count of all ngrams in both items
  same: 2,        //ngrams sahred by both items
  distinct: 6,    //count of distinct ngrams in total
  diff: 4         //count of unique ngrams - which do not appear in both items
}
*/
n.compare("abe","abc");         //third argument is warp - optional, default is 1 
/*
returns 0.3333333333333333
formula is: ((distinct ^ warp)-(diff ^ warp))/(distinct^warp)
*/
```
for more use cases look at test.js

---
_Source: https://npm.io/package/ngrams-search · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
