1.0.19 • Published 4 years ago
sbd v1.0.19
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
Installation
$ npm install sbd
$ yarn add sbd
How to
var tokenizer = require('sbd');
var optional_options = {};
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);
// [
// 'On Jan. 20, former Sen. Barack Obama became the 44th President of the U.S.',
// 'Millions attended the Inauguration.',
// ]
Optional options
var options = {
"newline_boundaries" : false,
"html_boundaries" : false,
"sanitize" : false,
"allowed_tags" : false,
"preserve_whitespace" : false,
"abbreviations" : null
};
newline_boundaries
, force sentence split at newlineshtml_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.preserve_whitespace
: Preserve the literal whitespace between words and sentences (otherwise, internal spaces are normalized to a single space char, and inter-sentence whitespace is omitted). Preserve whitespace has no effect if either newline_boundaries or html_boundaries is specified.abbreviations
: list of abbreviations to override the original ones for use with other languages. Don't put dots in your custom abbreviations.
Contributing
You can run unit tests with npm test
.
If you feel something is missing, you can open an issue stating the problem sentence and desired result. If code is unclear give me a @mention. Pull requests are welcome.
Building the (minified) scripts
npm install -g browserify
npm run-script build
1.0.19
4 years ago
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
7 years ago
1.0.13
7 years ago
1.0.12
8 years ago
1.0.11
9 years ago
1.0.10
9 years ago
1.0.9
9 years ago
1.0.8
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.0.6
10 years ago
0.0.5
10 years ago
0.0.4
10 years ago
0.0.3
10 years ago
0.0.2
11 years ago
0.0.1
11 years ago