Natural language processing library that analyzes, transforms, and extracts meaning from English text in browsers and Node.js
npx @tessl/cli install tessl/npm-nlp-compromise@6.5.0nlp_compromise is a lightweight natural language processing library for JavaScript that performs NLP operations directly in browsers and Node.js environments. It provides a fluent API for understanding, analyzing, transforming, and extracting meaning from English text without dependencies or configuration.
npm install nlp_compromiseconst nlp = require('nlp_compromise');For browser environments:
<script src="https://unpkg.com/nlp_compromise@latest/builds/nlp_compromise.min.js"></script>
<script>
const nlp = window.nlp_compromise;
</script>const nlp = require('nlp_compromise');
// Parse and transform text
nlp.sentence('She sells seashells').to_past().text();
// 'She sold seashells'
// Extract entities
nlp.text('Tony Hawk did a kickflip').people();
// [Person { text: 'Tony Hawk' ... }]
// Word-level operations
nlp.noun('dinosaur').pluralize();
// 'dinosaurs'
nlp.verb('speak').conjugate();
// { past: 'spoke', infinitive: 'speak', gerund: 'speaking', ... }nlp_compromise is built around several key components:
text, sentence, noun, verb, etc.) that create typed objectsFactory functions for creating and analyzing different text units and linguistic elements.
function text(string, options?): Text;
function sentence(string, options?): Sentence;
function statement(string): Statement;
function question(string): Question;
function term(string): Term;
function noun(string): Noun;
function verb(string): Verb;
function adjective(string): Adjective;
function adverb(string): Adverb;
function value(string): Value;
function person(string): Person;
function date(string): Date;
function place(string): Place;
function organization(string): Organization;Multi-sentence text processing with comprehensive entity extraction, pattern matching, and document-level transformations.
class Text {
sentences: Sentence[];
raw_text: string;
text(): string;
normal(): string;
root(): string;
terms(): Term[];
tags(): string[][];
match(pattern: string, options?): Result[];
replace(pattern: string, replacement: string, options?): Text;
}Single sentence analysis including grammatical transformations, pattern matching, and entity extraction.
class Sentence {
terms: Term[];
str: string;
text(): string;
normal(): string;
sentence_type(): string;
terminator(): string;
match(pattern: string, options?): Result[];
replace(pattern: string, replacement: string, options?): Sentence;
}Individual word and term analysis with part-of-speech specific methods for inflection, conjugation, and classification.
class Term {
text: string;
normal: string;
pos: object;
tag: string;
root(): string;
match(pattern: string, options?): boolean;
forms(): object;
}Automatic detection, extraction, and analysis of named entities including people, places, dates, values, and organizations.
class Person extends Noun {
firstName: string;
lastName: string;
gender(): string;
pronoun(): string;
}
class Value extends Noun {
number: number;
unit: string;
measurement: string;
}Extensible plugin architecture for adding custom functionality and extending existing classes.
function plugin(obj): void;
function lexicon(obj?): object;// Core result types
interface Result {
terms: Term[];
match(string, options?): Result[];
normal(): string;
replace(words: string[]): Result;
text(): string;
}
// Contractions helper
interface Contractions {
expand(): Text | Sentence;
contract(): Text | Sentence;
}
// Topic extraction result
interface Topic {
count: number;
text: string;
}