CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nlp-compromise

Natural language processing library that analyzes, transforms, and extracts meaning from English text in browsers and Node.js

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

entity-recognition.mddocs/

Entity Recognition

Automatic detection, extraction, and analysis of named entities including people, places, dates, values, and organizations. The entity classes extend the Noun class with specialized parsing and analysis methods.

Capabilities

Person Class

Person entity with name parsing and demographic analysis.

/**
 * Person class extending Noun for person name analysis
 */
class Person extends Noun {
  /** Person's title/honorific (Dr., Mr., Ms., etc.) */
  honourific: string;
  /** First name component */
  firstName: string;
  /** Middle name component */
  middleName: string;
  /** Last name component */
  lastName: string;
  
  /**
   * Parse name components from person text
   */
  parse(): void;
  
  /**
   * Detect person's gender from name
   * @returns {string} Gender: 'Male', 'Female', or undefined
   */
  gender(): string;
  
  /**
   * Get appropriate pronoun for person
   * @returns {string} Pronoun: 'he', 'she', or 'they'
   */
  pronoun(): string;
  
  /**
   * Check if term is a pronoun
   * @returns {boolean} True if pronoun
   */
  isPronoun(): boolean;
}

Usage Examples:

const nlp = require('nlp_compromise');

// Basic person parsing
const person = nlp.person('Dr. Jane Smith');
console.log(person.honourific);  // 'Dr.'
console.log(person.firstName);   // 'Jane'
console.log(person.lastName);    // 'Smith'
console.log(person.gender());    // 'Female'
console.log(person.pronoun());   // 'she'

// Full name parsing
const fullName = nlp.person('John Michael Johnson Jr.');
console.log(fullName.firstName);   // 'John'
console.log(fullName.middleName);  // 'Michael'
console.log(fullName.lastName);    // 'Johnson Jr.'

// Pronoun detection
const pronoun = nlp.person('he');
console.log(pronoun.isPronoun());  // true
console.log(pronoun.gender());     // 'Male'

Value Class

Numeric values and measurements with unit parsing and conversion awareness.

/**
 * Value class extending Noun for numeric value analysis
 */
class Value extends Noun {
  /** Numeric value extracted from text */
  number: number;
  /** Unit abbreviation (kg, ft, $, etc.) */
  unit: string;
  /** Full unit name (kilogram, foot, dollar, etc.) */
  unit_name: string;
  /** Type of measurement */
  measurement: string;
  /** What is being measured (optional context) */
  of_what: string;
  
  /**
   * Parse numeric value and unit information
   */
  parse(): void;
  
  /**
   * Check if string contains a number
   * @param {string} str - String to check
   * @returns {boolean} True if contains number
   */
  is_number(str): boolean;
  
  /**
   * Check if number is ordinal (1st, 2nd, 3rd, etc.)
   * @returns {boolean} True if ordinal number
   */
  is_ordinal(): boolean;
  
  /**
   * Convert number to ordinal form
   * @returns {string} Ordinal form (1st, 2nd, 3rd, etc.)
   */
  to_ordinal(): string;
  
  /**
   * Check if string is a unit
   * @returns {boolean} True if recognized unit
   */
  is_unit(): boolean;
  
  /**
   * Get textual representation of the value
   * @returns {string} Text form of the number
   */
  textual(): string;
}

Usage Examples:

// Currency values
const money = nlp.value('$500');
console.log(money.number);       // 500
console.log(money.unit);         // 'dollar'
console.log(money.measurement);  // 'Money'

// Written numbers
const written = nlp.value('five hundred dollars');
console.log(written.number);     // 500
console.log(written.unit_name);  // 'dollar'
console.log(written.textual());  // 'five hundred'

// Measurements
const distance = nlp.value('25 kilometers');
console.log(distance.number);       // 25
console.log(distance.unit);         // 'km'
console.log(distance.unit_name);    // 'kilometer'
console.log(distance.measurement);  // 'Distance'

// Ordinal numbers
const ordinal = nlp.value('3rd');
console.log(ordinal.is_ordinal());  // true
console.log(ordinal.number);        // 3

// Temperature
const temp = nlp.value('98.6 degrees fahrenheit');
console.log(temp.number);        // 98.6
console.log(temp.measurement);   // 'Temperature'

// Utility methods
const ordinal = nlp.value('5');
console.log(ordinal.to_ordinal());  // '5th'
console.log(ordinal.is_number('42')); // true (utility method with parameter)
const unit = nlp.value('5 kg');
console.log(unit.is_unit());   // true

Date Class

Date entity with temporal parsing and date object conversion.

/**
 * Date class extending Noun for date analysis
 */
class Date extends Noun {
  /** Parsed date components */
  data: {
    day: number | null;
    month: number | null;
    year: number | null;
  };
  
  /**
   * Convert to JavaScript Date object
   * @returns {Date} JavaScript Date object
   */
  date(): Date;
  
  /**
   * Validate if parsed as valid date
   * @returns {boolean} True if valid date
   */
  is_date(): boolean;
}

Usage Examples:

// Date parsing
const dateEntity = nlp.date('March 15, 2024');
console.log(dateEntity.data.day);    // 15
console.log(dateEntity.data.month);  // 3
console.log(dateEntity.data.year);   // 2024
console.log(dateEntity.is_date());   // true

// Convert to JavaScript Date
const jsDate = dateEntity.date();
console.log(jsDate instanceof Date); // true

// Various date formats
const shortDate = nlp.date('3/15/24');
console.log(shortDate.data.month);   // 3

const relative = nlp.date('yesterday');
console.log(relative.is_date());     // true

Place Class

Place entity with location component parsing.

/**
 * Place class extending Noun for location analysis
 */
class Place extends Noun {
  /** City name component */
  city: string;
  /** State/region component */
  region: string;
  /** Country component */
  country: string;
  /** Full place title */
  title: string;
}

Usage Examples:

// City parsing
const city = nlp.place('New York City');
console.log(city.city);    // 'New York City'
console.log(city.title);   // 'New York City'

// Full location
const location = nlp.place('San Francisco, California');
console.log(location.city);    // 'San Francisco'
console.log(location.region);  // 'California'

// International location
const intl = nlp.place('London, England');
console.log(intl.city);     // 'London'
console.log(intl.country);  // 'England'

Organization Class

Organization entity for company and institution names.

/**
 * Organization class extending Noun for organization analysis
 */
class Organization extends Noun {
  // Inherits all Noun properties and methods
  // Specialized for organization name recognition
}

Usage Examples:

// Company names
const company = nlp.organization('Apple Inc.');
console.log(company.text);         // 'Apple Inc.'
console.log(company.is_organization()); // true

// Institutions
const university = nlp.organization('Harvard University');
console.log(university.text);      // 'Harvard University'

// Government organizations
const agency = nlp.organization('FBI');
console.log(agency.text);          // 'FBI'
console.log(agency.is_acronym());  // true

Entity Detection from Text

All entity types can be automatically detected and extracted from text:

Usage Examples:

const text = nlp.text(`
  Dr. Jane Smith from Harvard University visited Apple Inc. 
  in Cupertino on March 15th, 2024. The meeting cost $1,500 
  and lasted 2.5 hours.
`);

// Extract all entities
const people = text.people();
console.log(people[0].firstName);     // 'Jane'
console.log(people[0].honourific);    // 'Dr.'

const organizations = text.organizations();
console.log(organizations[0].text);   // 'Harvard University'
console.log(organizations[1].text);   // 'Apple Inc.'

const places = text.places();
console.log(places[0].text);          // 'Cupertino'

const dates = text.dates();
console.log(dates[0].data.month);     // 3
console.log(dates[0].data.day);       // 15

const values = text.values();
console.log(values[0].number);        // 1500
console.log(values[0].unit);          // 'dollar'
console.log(values[1].number);        // 2.5
console.log(values[1].unit);          // 'hour'

Measurement Types

Value entities recognize various measurement categories:

// Available measurement types
const measurementTypes = [
  'Temperature',  // degrees, celsius, fahrenheit
  'Volume',       // liters, gallons, cups
  'Distance',     // meters, feet, miles, kilometers
  'Weight',       // grams, pounds, kilograms
  'Area',         // square feet, acres, hectares
  'Frequency',    // hertz, rpm, bpm
  'Speed',        // mph, kph, knots
  'Data',         // bytes, MB, GB, TB
  'Energy',       // watts, calories, joules
  'Time',         // seconds, minutes, hours, days
  'Money'         // dollars, euros, yen, pounds
];

Usage Examples:

// Different measurement types
console.log(nlp.value('100 mph').measurement);        // 'Speed'
console.log(nlp.value('500 GB').measurement);         // 'Data'
console.log(nlp.value('98.6°F').measurement);         // 'Temperature'
console.log(nlp.value('2.5 acres').measurement);      // 'Area'
console.log(nlp.value('150 calories').measurement);   // 'Energy'
console.log(nlp.value('60 bpm').measurement);         // 'Frequency'

docs

core-functions.md

entity-recognition.md

index.md

plugin-system.md

sentence-processing.md

text-analysis.md

word-operations.md

tile.json