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.00
# nlp_compromise
1
2
nlp_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.
3
4
## Package Information
5
6
- **Package Name**: nlp_compromise
7
- **Package Type**: npm
8
- **Language**: JavaScript
9
- **Installation**: `npm install nlp_compromise`
10
11
## Core Imports
12
13
```javascript
14
const nlp = require('nlp_compromise');
15
```
16
17
For browser environments:
18
19
```html
20
<script src="https://unpkg.com/nlp_compromise@latest/builds/nlp_compromise.min.js"></script>
21
<script>
22
const nlp = window.nlp_compromise;
23
</script>
24
```
25
26
## Basic Usage
27
28
```javascript
29
const nlp = require('nlp_compromise');
30
31
// Parse and transform text
32
nlp.sentence('She sells seashells').to_past().text();
33
// 'She sold seashells'
34
35
// Extract entities
36
nlp.text('Tony Hawk did a kickflip').people();
37
// [Person { text: 'Tony Hawk' ... }]
38
39
// Word-level operations
40
nlp.noun('dinosaur').pluralize();
41
// 'dinosaurs'
42
43
nlp.verb('speak').conjugate();
44
// { past: 'spoke', infinitive: 'speak', gerund: 'speaking', ... }
45
```
46
47
## Architecture
48
49
nlp_compromise is built around several key components:
50
51
- **Factory Functions**: Core constructors (`text`, `sentence`, `noun`, `verb`, etc.) that create typed objects
52
- **Text Processing**: Multi-sentence text analysis with entity extraction and transformations
53
- **Sentence Analysis**: Single sentence operations including POS tagging, pattern matching, and grammatical transformations
54
- **Term Hierarchy**: Specialized term types (Noun, Verb, Adjective, Adverb) with part-of-speech specific methods
55
- **Entity Recognition**: Automatic detection and classification of people, places, dates, values, and organizations
56
- **Plugin System**: Extensible architecture for adding custom functionality
57
58
## Capabilities
59
60
### Core Factory Functions
61
62
Factory functions for creating and analyzing different text units and linguistic elements.
63
64
```javascript { .api }
65
function text(string, options?): Text;
66
function sentence(string, options?): Sentence;
67
function statement(string): Statement;
68
function question(string): Question;
69
function term(string): Term;
70
function noun(string): Noun;
71
function verb(string): Verb;
72
function adjective(string): Adjective;
73
function adverb(string): Adverb;
74
function value(string): Value;
75
function person(string): Person;
76
function date(string): Date;
77
function place(string): Place;
78
function organization(string): Organization;
79
```
80
81
[Core Functions](./core-functions.md)
82
83
### Text Analysis
84
85
Multi-sentence text processing with comprehensive entity extraction, pattern matching, and document-level transformations.
86
87
```javascript { .api }
88
class Text {
89
sentences: Sentence[];
90
raw_text: string;
91
92
text(): string;
93
normal(): string;
94
root(): string;
95
terms(): Term[];
96
tags(): string[][];
97
match(pattern: string, options?): Result[];
98
replace(pattern: string, replacement: string, options?): Text;
99
}
100
```
101
102
[Text Analysis](./text-analysis.md)
103
104
### Sentence Processing
105
106
Single sentence analysis including grammatical transformations, pattern matching, and entity extraction.
107
108
```javascript { .api }
109
class Sentence {
110
terms: Term[];
111
str: string;
112
113
text(): string;
114
normal(): string;
115
sentence_type(): string;
116
terminator(): string;
117
match(pattern: string, options?): Result[];
118
replace(pattern: string, replacement: string, options?): Sentence;
119
}
120
```
121
122
[Sentence Processing](./sentence-processing.md)
123
124
### Word-Level Operations
125
126
Individual word and term analysis with part-of-speech specific methods for inflection, conjugation, and classification.
127
128
```javascript { .api }
129
class Term {
130
text: string;
131
normal: string;
132
pos: object;
133
tag: string;
134
135
root(): string;
136
match(pattern: string, options?): boolean;
137
forms(): object;
138
}
139
```
140
141
[Word-Level Operations](./word-operations.md)
142
143
### Entity Recognition
144
145
Automatic detection, extraction, and analysis of named entities including people, places, dates, values, and organizations.
146
147
```javascript { .api }
148
class Person extends Noun {
149
firstName: string;
150
lastName: string;
151
gender(): string;
152
pronoun(): string;
153
}
154
155
class Value extends Noun {
156
number: number;
157
unit: string;
158
measurement: string;
159
}
160
```
161
162
[Entity Recognition](./entity-recognition.md)
163
164
### Plugin System
165
166
Extensible plugin architecture for adding custom functionality and extending existing classes.
167
168
```javascript { .api }
169
function plugin(obj): void;
170
function lexicon(obj?): object;
171
```
172
173
[Plugin System](./plugin-system.md)
174
175
## Types
176
177
```javascript { .api }
178
// Core result types
179
interface Result {
180
terms: Term[];
181
match(string, options?): Result[];
182
normal(): string;
183
replace(words: string[]): Result;
184
text(): string;
185
}
186
187
// Contractions helper
188
interface Contractions {
189
expand(): Text | Sentence;
190
contract(): Text | Sentence;
191
}
192
193
// Topic extraction result
194
interface Topic {
195
count: number;
196
text: string;
197
}
198
```