Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trigram-utils

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trigram-utils

A few language trigram utilities

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
74K
increased by27.62%
Maintainers
1
Weekly downloads
 
Created
Source

trigram-utils

Build Coverage Downloads Size

Trigram language statistics utility functions, in their own repository to make sure trigrams (trigram info for the universal declaration of human rights) and franc (language detection) use the same cleaning and classification methods.

Install

npm:

npm install trigram-utils

Use

var utils = require('trigram-utils')

utils.clean(' t@rololol ') // => 't rololol'

utils.trigrams(' t@rololol ')
// => [ ' t ', 't r', ' ro', 'rol', 'olo', 'lol', 'olo', 'lol', 'ol ' ]

utils.asDictionary(' t@rololol ')
// => { 'ol ': 1, lol: 2, olo: 2, rol: 1, ' ro': 1, 't r': 1, ' t ': 1 }

var tuples = utils.asTuples(' t@rololol ')
// => [ [ 'ol ', 1 ],
//     [ 'rol', 1 ],
//     [ ' ro', 1 ],
//     [ 't r', 1 ],
//     [ ' t ', 1 ],
//     [ 'lol', 2 ],
//     [ 'olo', 2 ] ]

utils.tuplesAsDictionary(tuples)
// => { olo: 2, lol: 2, ' t ': 1, 't r': 1, ' ro': 1, rol: 1, 'ol ': 1 }

API

utils.clean(value)

Clean a given string: strips some (for language detection) useless punctuation, symbols, and numbers. Collapses white space, trims, and lowercases.

utils.trigrams(value)

Get clean, padded trigrams (see n-gram).

utils.asDictionary(value)

Get clean trigrams as a dictionary: keys are trigrams, values are occurrence counts.

utils.asTuples(value)

Get clean trigrams with occurrence counts as a tuple: first index (0) the trigram, second (1) the occurrence count.

utils.tuplesAsDictionary(tuples)

Transform an Array of trigram–occurrence tuples (as returned by asTuples()) as a dictionary (as returned by asDictionary())

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 27 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc