Natural language processing library that analyzes, transforms, and extracts meaning from English text in browsers and Node.js
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Individual word and term analysis with part-of-speech specific methods for inflection, conjugation, and classification. The Term hierarchy provides specialized functionality for different grammatical categories.
Base class for individual word analysis with core linguistic operations.
/**
* Term class for individual word analysis and transformation
*/
class Term {
/** Original word text */
text: string;
/** Normalized word text */
normal: string;
/** Expanded form (for contractions) */
expansion: string;
/** Part-of-speech flags object */
pos: object;
/** Primary POS tag */
tag: string;
/** Surrounding whitespace information */
whitespace: {
preceding: string;
trailing: string;
};
}Core methods for analyzing and manipulating individual terms.
/**
* Get the root/lemma form of the word
* @returns {string} Root form of the word
*/
root(): string;
/**
* Change the term text and rebuild derived properties
* @param {string} str - New text for the term
*/
changeTo(str): void;
/**
* Check if term matches a pattern
* @param {string} pattern - Pattern to match against
* @param {object} [options] - Matching options
* @returns {boolean} True if pattern matches
*/
match(pattern, options): boolean;
/**
* Get all inflection forms for this term
* @returns {object} Object containing available forms
*/
forms(): object;Methods for checking term properties and classifications.
/**
* Check if term is capitalized
* @returns {boolean} True if first letter is uppercase
*/
is_capital(): boolean;
/**
* Check if term is an acronym
* @returns {boolean} True if term appears to be an acronym
*/
is_acronym(): boolean;
/**
* Check if term is a word (not punctuation)
* @returns {boolean} True if term contains letters
*/
is_word(): boolean;
/**
* Check if term ends with a comma
* @returns {boolean} True if term has trailing comma
*/
has_comma(): boolean;
/**
* Check if term has possessive apostrophe
* @returns {boolean} True if term has apostrophe
*/
has_abbreviation(): boolean;Usage Examples:
const nlp = require('nlp_compromise');
const term = nlp.term('running');
console.log(term.root()); // 'run'
console.log(term.is_word()); // true
console.log(term.is_capital()); // false
const acronym = nlp.term('NASA');
console.log(acronym.is_acronym()); // true
console.log(acronym.is_capital()); // trueSpecialized term class for nouns with inflection and classification methods.
/**
* Noun class extending Term with noun-specific operations
*/
class Noun extends Term {
/**
* Convert noun to plural form
* @returns {string} Plural form of the noun
*/
pluralize(): string;
/**
* Convert noun to singular form
* @returns {string} Singular form of the noun
*/
singularize(): string;
/**
* Check if noun is in plural form
* @returns {boolean} True if plural
*/
is_plural(): boolean;
/**
* Check if noun is uncountable
* @returns {boolean} True if uncountable (water, information, etc.)
*/
is_uncountable(): boolean;
/**
* Get appropriate article for noun
* @returns {string} Article: 'a', 'an', or 'the'
*/
article(): string;
/**
* Get appropriate pronoun for noun
* @returns {string} Pronoun: 'it', 'they', 'he', 'she'
*/
pronoun(): string;
}Methods for checking noun entity types.
/**
* Check if noun represents a person
* @returns {boolean} True if person noun
*/
is_person(): boolean;
/**
* Check if noun represents a place
* @returns {boolean} True if place noun
*/
is_place(): boolean;
/**
* Check if noun represents an organization
* @returns {boolean} True if organization noun
*/
is_organization(): boolean;
/**
* Check if noun represents a date
* @returns {boolean} True if date noun
*/
is_date(): boolean;
/**
* Check if noun represents a value/measurement
* @returns {boolean} True if value noun
*/
is_value(): boolean;Usage Examples:
// Basic noun operations
const noun = nlp.noun('cat');
console.log(noun.pluralize()); // 'cats'
console.log(noun.article()); // 'a'
console.log(noun.pronoun()); // 'it'
// Plural nouns
const plural = nlp.noun('children');
console.log(plural.is_plural()); // true
console.log(plural.singularize()); // 'child'
// Uncountable nouns
const uncountable = nlp.noun('water');
console.log(uncountable.is_uncountable()); // true
// Entity classification
const person = nlp.noun('doctor');
console.log(person.is_person()); // trueSpecialized term class for verbs with conjugation and tense methods.
/**
* Verb class extending Term with verb-specific operations
* Note: Tense conversion methods (to_past, to_present, to_future) both modify the verb object and return the new form
*/
class Verb extends Term {
/**
* Convert verb to past tense
* @returns {string} Past tense form
*/
to_past(): string;
/**
* Convert verb to present tense
* @returns {string} Present tense form
*/
to_present(): string;
/**
* Convert verb to future tense
* @returns {string} Future tense form
*/
to_future(): string;
/**
* Get all conjugation forms
* @returns {object} Object with all verb forms
*/
conjugate(): object;
/**
* Get current tense of verb
* @returns {string} Tense: 'present', 'past', or 'future'
*/
tense(): string;
/**
* Get specific conjugation tag
* @returns {string} Conjugation tag
*/
conjugation(): string;
/**
* Negate the verb
* @returns {Verb} Negated verb
*/
negate(): Verb;
/**
* Check if verb is negated
* @returns {boolean} True if negative
*/
isNegative(): boolean;
/**
* Convert verb to adjective form
* @returns {string} Adjective form if available
*/
to_adjective(): string;
}Usage Examples:
// Basic verb operations
const verb = nlp.verb('run');
console.log(verb.to_past()); // 'ran'
console.log(verb.to_future()); // 'will run'
console.log(verb.tense()); // 'present'
// Full conjugation
const conjugation = verb.conjugate();
console.log(conjugation);
// {
// infinitive: 'run',
// present: 'runs',
// past: 'ran',
// gerund: 'running',
// actor: 'runner'
// }
// Negation
const negated = verb.negate();
console.log(negated.text); // 'doesn\'t run'
console.log(negated.isNegative()); // true
// Adjective conversion
const perfect = nlp.verb('perfect');
console.log(perfect.to_adjective()); // 'perfect'Specialized term class for adjectives with comparison methods.
/**
* Adjective class extending Term with adjective-specific operations
*/
class Adjective extends Term {
/**
* Convert to comparative form
* @returns {string} Comparative form (bigger, more beautiful)
*/
to_comparative(): string;
/**
* Convert to superlative form
* @returns {string} Superlative form (biggest, most beautiful)
*/
to_superlative(): string;
/**
* Convert to noun form
* @returns {string} Noun form if available
*/
to_noun(): string;
/**
* Convert to adverb form
* @returns {string} Adverb form
*/
to_adverb(): string;
/**
* Get all adjective forms
* @returns {object} Object with all forms
*/
conjugate(): object;
}Usage Examples:
// Basic adjective operations
const adj = nlp.adjective('big');
console.log(adj.to_comparative()); // 'bigger'
console.log(adj.to_superlative()); // 'biggest'
console.log(adj.to_adverb()); // 'bigly'
// Complex adjective
const beautiful = nlp.adjective('beautiful');
console.log(beautiful.to_comparative()); // 'more beautiful'
console.log(beautiful.to_superlative()); // 'most beautiful'
console.log(beautiful.to_adverb()); // 'beautifully'
// Get all forms
const forms = adj.conjugate();
console.log(forms);
// {
// comparative: 'bigger',
// superlative: 'biggest',
// adverb: 'bigly',
// noun: 'bigness'
// }Specialized term class for adverbs with conversion methods.
/**
* Adverb class extending Term with adverb-specific operations
*/
class Adverb extends Term {
/**
* Convert to adjective form
* @returns {string} Adjective form if available
*/
to_adjective(): string;
}Usage Examples:
// Adverb operations
const adverb = nlp.adverb('quickly');
console.log(adverb.to_adjective()); // 'quick'
const beautifully = nlp.adverb('beautifully');
console.log(beautifully.to_adjective()); // 'beautiful'The forms returned by different term types have specific structures:
// Noun forms
interface NounForm {
singular: string;
plural: string;
}
// Verb forms
interface VerbForm {
infinitive: string;
present: string;
past: string;
gerund: string;
actor?: string;
}
// Adjective forms
interface AdjectiveForm {
comparative: string;
superlative: string;
adverb: string;
noun?: string;
}
// Adverb forms
interface AdverbForm {
adjective: string;
}