npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@knod/sbd

v2.0.2

Published

Split text into sentence strings or word arrays with Sentence Boundary Detection (SBD). Based on http://github.com/Tessmore/sbd by Fabiën Tesselaar.

Downloads

4

Readme

#Sentence Boundary Detection (SBD)

Split text into sentences with a vanilla rule based approach (i.e working ~95% of the time).

  • Split a text based on period, question- and exclamation marks.
    • Skips (most) abbreviations (Mr., Mrs., PhD.)
    • Skips numbers/currency
    • Skips urls, websites, email addresses, phone nr.
    • Counts ellipsis and ?! as single punctuation

Attribution

This is a fork of http://github.com/Tessmore/sbd by Fabiën Tesselaar. Most of this README is the same.

Installation

Use npm:

$ npm install @knod/sbd

How to

var tokenizer = require('sbd');

var text = "On Jan. 20, former Sen. Barack Obama became the 44th President of the U.S. Millions attended the Inauguration.";
var sentences = tokenizer.sentences(text, optional_options);

// Returns:
// [
//  'On Jan. 20, former Sen. Barack Obama became the 44th President of the U.S.',
//  'Millions attended the Inauguration.',
// ]

or

var tokenizer = require('sbd');

var text = "There are many copies. And they have a plan.";
var sentences = tokenizer.sentences(text, {parse_type: 'words'});

// Returns:
// [
//  [ 'There', 'are', 'many', 'copies.' ],
//  [ 'And', 'they', 'have', 'a', 'plan.' ]
// ]

See a demo at https://knod.github.io/sbd/

Optional options

Defaults:

var options = {
    "parse_type"          : "strings",
    "newline_boundaries"  : false,
    "html_boundaries"     : false,
    "html_boundaries_tags": ["p","div","ul","ol"],
    "sanitize"            : false,
    "allowed_tags"        : false,
    "abbreviations"       : null
};
  • parse_type: Value can be either 'strings' or 'words'. 'strings' will turn your text into a list of sentences, each of which is a string. 'words' will turn your text into a list of sentences, each of which is a list of words.
  • newline_boundaries: Force sentence split at newlines
  • html_boundaries: Force sentence split at specific tags (br, and closing p, div, ul, ol)
  • sanitize: If you don't expect nor want html in your text.
  • allowed_tags: To sanitize html, the library santize-html is used. You can pass the allowed tags option.
  • abbreviations: list of abbreviations to override the original ones for use with other languages. Don't put dots in abbreviations.

Contributing

You can run unit tests with npm test.

If you feel something is missing, you can open an issue at http://github.com/knod/sbd/issues stating the problem sentence and desired result. If code is unclear give me a @mention. Pull requests are welcome.

Building the (minified) scripts

(If you already have browserify, there's no need to include the first line)

npm install -g browserify

npm run-script build

Next

  • Update tests for new capabilities
  • New tests to show failing cases
  • Remove html parsing. The combination of the two should happen in a separate module.