or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdlinguistic-analysis.mdpattern-matching.mdplugin-system.mdtext-analysis.mdtext-transformation.md
tile.json

text-transformation.mddocs/

Text Transformation

Text transformation capabilities including verb conjugation, noun pluralization, tense conversion, and text normalization. This functionality is primarily available in compromise/three.

Capabilities

Verb Conjugation

Transform verbs between different tenses and forms.

/**
 * Convert verbs to infinitive form
 * @returns View with verbs in infinitive form
 */
toInfinitive(): View;

/**
 * Convert verbs to present tense
 * @returns View with verbs in present tense
 */
toPresentTense(): View;

/**
 * Convert verbs to past tense
 * @returns View with verbs in past tense
 */
toPastTense(): View;

/**
 * Convert verbs to future tense
 * @returns View with verbs in future tense
 */
toFutureTense(): View;

/**
 * Convert verbs to gerund form (-ing)
 * @returns View with verbs in gerund form
 */
toGerund(): View;

/**
 * Convert verbs to negative form
 * @returns View with verbs negated
 */
toNegative(): View;

/**
 * Convert negative verbs to positive form
 * @returns View with verbs in positive form
 */
toPositive(): View;

Usage Examples:

const doc = nlp("I walked to the store and will be running");

// Transform verb tenses
const presentTense = doc.verbs().toPresentTense();
console.log(presentTense.out('text')); // 'walk' and 'run'

const pastTense = doc.verbs().toPastTense();
console.log(pastTense.out('text')); // 'walked' and 'ran'

const infinitive = doc.verbs().toInfinitive();
console.log(infinitive.out('text')); // 'walk' and 'run'

// Negate verbs
const negated = doc.verbs().toNegative();
console.log(negated.out('text')); // 'did not walk' and 'will not be running'

// More examples
const verbDoc = nlp("He runs quickly");
const gerund = verbDoc.verbs().toGerund();
console.log(gerund.out('text')); // 'running'

Noun Pluralization

Transform nouns between singular and plural forms.

/**
 * Convert nouns to plural form
 * @param setArticle - Whether to update articles (a/an -> some/many)
 * @returns View with nouns in plural form
 */
toPlural(setArticle?: boolean): View;

/**
 * Convert nouns to singular form
 * @param setArticle - Whether to update articles
 * @returns View with nouns in singular form
 */
toSingular(setArticle?: boolean): View;

Usage Examples:

const doc = nlp("I have a cat and three dogs");

// Convert to plural
const pluralNouns = doc.nouns().toPlural();
console.log(pluralNouns.out('text')); // 'cats' and 'dogs'

// Convert to singular  
const singularNouns = doc.nouns().toSingular();
console.log(singularNouns.out('text')); // 'cat' and 'dog'

// With article updating
const articleDoc = nlp("a cat");
const pluralWithArticle = articleDoc.toPlural(true);
console.log(pluralWithArticle.out('text')); // 'cats' (removes 'a')

Adjective Conjugation

Transform adjectives between comparative and superlative forms.

/**
 * Convert adjectives to comparative form
 * @param n - Optional limit on results
 * @returns View with comparative adjectives
 */
toComparative(n?: number): View;

/**
 * Convert adjectives to superlative form  
 * @param n - Optional limit on results
 * @returns View with superlative adjectives
 */
toSuperlative(n?: number): View;

/**
 * Convert adjectives to adverb form
 * @param n - Optional limit on results
 * @returns View with adverb forms
 */
toAdverb(n?: number): View;

/**
 * Convert adjectives to noun form
 * @param n - Optional limit on results
 * @returns View with noun forms
 */
toNoun(n?: number): View;

Usage Examples:

const doc = nlp("The quick brown fox is happy");

// Transform adjectives
const comparative = doc.adjectives().toComparative();
console.log(comparative.out('array')); // ['quicker', 'browner', 'happier']

const superlative = doc.adjectives().toSuperlative();
console.log(superlative.out('array')); // ['quickest', 'brownest', 'happiest']

const adverbs = doc.adjectives().toAdverb();
console.log(adverbs.out('array')); // ['quickly', 'happily']

const nouns = doc.adjectives().toNoun();
console.log(nouns.out('array')); // ['quickness', 'happiness']

Sentence Transformation

Transform entire sentences for tense and polarity.

/**
 * Convert sentence to past tense
 * @returns View with sentence in past tense
 */
toPastTense(): View;

/**
 * Convert sentence to present tense
 * @returns View with sentence in present tense
 */
toPresentTense(): View;

/**
 * Convert sentence to future tense
 * @returns View with sentence in future tense
 */
toFutureTense(): View;

/**
 * Convert sentence to infinitive form
 * @returns View with sentence using infinitive verbs
 */
toInfinitive(): View;

/**
 * Convert sentence to negative form
 * @returns View with negated sentence
 */
toNegative(): View;

/**
 * Convert negative sentence to positive form
 * @returns View with positive sentence
 */
toPositive(): View;

Usage Examples:

const doc = nlp("I walk to the store");

// Transform sentence tense
const pastSentence = doc.sentences().toPastTense();
console.log(pastSentence.out('text')); // 'I walked to the store'

const futureSentence = doc.sentences().toFutureTense();
console.log(futureSentence.out('text')); // 'I will walk to the store'

// Transform sentence polarity
const negativeSentence = doc.sentences().toNegative();
console.log(negativeSentence.out('text')); // 'I do not walk to the store'

// Convert negative to positive
const negDoc = nlp("I don't like pizza");
const positive = negDoc.sentences().toPositive();
console.log(positive.out('text')); // 'I like pizza'

Text Case Transformation

Transform text case in various formats.

/**
 * Convert all text to lowercase
 * @returns View with lowercase text
 */
toLowerCase(): View;

/**
 * Convert all text to uppercase  
 * @returns View with uppercase text
 */
toUpperCase(): View;

/**
 * Capitalize first letter of each term
 * @returns View with title case text
 */
toTitleCase(): View;

/**
 * Remove whitespace and title-case each term
 * @returns View with camelCase text
 */
toCamelCase(): View;

Usage Examples:

const doc = nlp("hello WORLD how Are You");

// Transform text case
console.log(doc.toLowerCase().out('text')); // 'hello world how are you'
console.log(doc.toUpperCase().out('text')); // 'HELLO WORLD HOW ARE YOU'
console.log(doc.toTitleCase().out('text')); // 'Hello World How Are You'
console.log(doc.toCamelCase().out('text')); // 'helloWorldHowAreYou'

Text Normalization

Clean up and standardize text in various ways.

/**
 * Clean up text in various ways
 * @param options - Normalization options
 * @returns View with normalized text
 */
normalize(options?: string | object): View;

/**
 * Remove start and end whitespace
 * @returns View with trimmed text
 */
trim(): View;

/**
 * Connect words with hyphens and remove whitespace
 * @returns View with hyphenated text
 */
hyphenate(): View;

/**
 * Remove hyphens and restore whitespace
 * @returns View with dehyphenated text
 */
dehyphenate(): View;
deHyphenate(): View; // alias

Usage Examples:

const messyDoc = nlp("  HELLO    world!!!   ");

// Basic normalization
const normalized = messyDoc.normalize();
console.log(normalized.out('text')); // 'hello world'

// Specific normalization options
const customNormalized = messyDoc.normalize({
  case: true,          // normalize case
  punctuation: true,   // clean punctuation
  whitespace: true,    // normalize whitespace
  unicode: true        // normalize unicode
});

// Trim whitespace
const trimmed = messyDoc.trim();
console.log(trimmed.out('text')); // 'HELLO    world!!!'

// Hyphenation
const words = nlp("hello world");
const hyphenated = words.hyphenate();
console.log(hyphenated.out('text')); // 'hello-world'

const dehyphenated = hyphenated.dehyphenate();
console.log(dehyphenated.out('text')); // 'hello world'

Punctuation and Formatting

Add or modify punctuation and formatting.

/**
 * Add punctuation or whitespace before matches
 * @param str - String to add before
 * @param concat - Whether to concatenate to existing pre
 * @returns View with modified pre-text
 */
pre(str?: string, concat?: boolean): View;

/**
 * Add punctuation or whitespace after matches
 * @param str - String to add after
 * @param concat - Whether to concatenate to existing post
 * @returns View with modified post-text
 */
post(str?: string, concat?: boolean): View;

/**
 * Add quotation marks around selections
 * @param start - Opening quote character
 * @param end - Closing quote character  
 * @returns View with quoted text
 */
toQuotations(start?: string, end?: string): View;
toQuotation(start?: string, end?: string): View; // alias

/**
 * Add parentheses around selections
 * @param start - Opening parenthesis
 * @param end - Closing parenthesis
 * @returns View with parenthesized text
 */
toParentheses(start?: string, end?: string): View;

Usage Examples:

const doc = nlp("hello world");

// Add punctuation
const withComma = doc.first().post(", ");
console.log(withComma.all().out('text')); // 'hello, world'

const withQuotes = doc.toQuotations();
console.log(withQuotes.out('text')); // '"hello world"'

const withParens = doc.toParentheses();
console.log(withParens.out('text')); // '(hello world)'

// Custom quotes
const customQuotes = doc.toQuotations("'", "'");
console.log(customQuotes.out('text')); // "'hello world'"

Number Transformation

Transform numbers between different formats (available on Numbers view).

/**
 * Convert number words to digits
 * @returns View with numeric digits
 */
toNumber(): View;

/**
 * Convert numbers to locale-formatted strings
 * @returns View with formatted numbers
 */
toLocaleString(): View;

/**
 * Convert numbers to word form
 * @returns View with number words
 */
toText(): View;

/**
 * Convert to cardinal number form
 * @returns View with cardinal numbers
 */
toCardinal(): View;

/**
 * Convert to ordinal number form
 * @returns View with ordinal numbers
 */
toOrdinal(): View;

Usage Examples:

const doc = nlp("I have twenty-five dollars and this is my third attempt");

// Transform numbers
const numbers = doc.numbers();
console.log(numbers.toNumber().out('text')); // '25' and '3'
console.log(numbers.toText().out('text')); // 'twenty-five' and 'three'  
console.log(numbers.toOrdinal().out('text')); // '25th' and '3rd'

// Fractions
const fractionDoc = nlp("I ate one half of the pie");
const fractions = fractionDoc.fractions();
console.log(fractions.toDecimal().out('text')); // '0.5'
console.log(fractions.toPercentage().out('text')); // '50%'

Text Removal and Redaction

Remove or redact specific types of content.

/**
 * Remove people, places, and organizations
 * @param opts - Redaction options
 * @returns View with entities redacted
 */
redact(opts?: object): View;

/**
 * Remove specified text patterns
 * @param match - Pattern to remove
 * @returns View with matches removed
 */
remove(match?: string | Net): View;
delete(match?: string | Net): View; // alias

Usage Examples:

const doc = nlp("John Smith works at Google in San Francisco");

// Redact named entities
const redacted = doc.redact();
console.log(redacted.out('text')); // '--- works at --- in ---'

// Remove specific patterns
const noVerbs = doc.remove('#Verb');
console.log(noVerbs.out('text')); // 'John Smith at Google in San Francisco'

Types

// Interfaces for transformation methods are mixed into the base View interface
interface TransformationView extends View {
  // Verb transformations
  toInfinitive(): View;
  toPresentTense(): View;
  toPastTense(): View;
  toFutureTense(): View;
  toGerund(): View;
  toNegative(): View;
  toPositive(): View;
  
  // Noun transformations
  toPlural(setArticle?: boolean): View;
  toSingular(setArticle?: boolean): View;
  
  // Case transformations
  toLowerCase(): View;
  toUpperCase(): View;
  toTitleCase(): View;
  toCamelCase(): View;
  
  // Text cleanup
  normalize(options?: string | object): View;
  trim(): View;
  hyphenate(): View;
  dehyphenate(): View;
  
  // Formatting
  pre(str?: string, concat?: boolean): View;
  post(str?: string, concat?: boolean): View;
  toQuotations(start?: string, end?: string): View;
  toParentheses(start?: string, end?: string): View;
}

interface Numbers extends View {
  /** Get parsed number */
  parse(n?: number): object[];
  /** Get numeric value */
  get(n?: number): number | number[];
  /** Return only ordinal numbers */
  isOrdinal(): View;
  /** Return only cardinal numbers */
  isCardinal(): View;
  /** Return only numbers with given unit(s) */
  isUnit(units: string | string[] | object): View;
  /** Convert number to digits */
  toNumber(): View;
  /** Add commas or nicer formatting */
  toLocaleString(): View;
  /** Convert number to words */
  toText(): View;
  /** Convert to cardinal form */
  toCardinal(): View;
  /** Convert to ordinal form */
  toOrdinal(): View;
  /** Return numbers equal to value */
  isEqual(value: number): View;
  /** Return numbers greater than n */
  greaterThan(min: number): View;
  /** Return numbers less than n */
  lessThan(max: number): View;
  /** Return numbers between min and max */
  between(min: number, max: number): View;
  /** Set number to n */
  set(n: number): View;
  /** Increase number by n */
  add(n: number): View;
  /** Decrease number by n */
  subtract(n: number): View;
  /** Increase number by 1 */
  increment(): View;
  /** Decrease number by 1 */
  decrement(): View;
}

interface Fractions extends View {
  /** Get parsed fraction */
  parse(n?: number): object[];
  /** Get numeric value */
  get(n?: number): number | number[];
  /** Convert '1/4' to 0.25 */
  toDecimal(): View;
  /** Convert 'one fourth' to '1/4' */
  toFraction(): View;
  /** Convert '1/4' to '1/4th' */
  toOrdinal(): View;
  /** Convert '1/4th' to '1/4' */
  toCardinal(): View;
  /** Convert '1/4' to '25%' */
  toPercentage(): View;
}