UNPKG

compromise

Version:

modest natural language processing

340 lines (316 loc) • 11.3 kB
import type View from './two.d.ts' import type { JsonProps } from '../misc.d.ts' interface Three extends View { // Selections /** split-up results into multi-term phrases */ clauses: (n?: number) => View /** split-up noun-phrase and verb-phrases */ chunks: () => View /** clean-up the document, in various ways */ normalize: (options?: string | object) => View /** remove any people, places, and organizations */ redact: (opts?: object, blockStr?: string, keepTags?: boolean) => View /** return all terms connected with a hyphen or dash like `'wash-out'`*/ hyphenated: (n?: number) => View /** return terms like `'#nlp'` */ hashTags: (n?: number) => View /** return terms like `'hi@compromise.cool'` */ emails: (n?: number) => View /** return terms like `💋` */ emoji: (n?: number) => View /** return terms like `:)` */ emoticons: (n?: number) => View /** return terms like `'@nlp_compromise'`*/ atMentions: (n?: number) => View /** return terms like `'compromise.cool'` */ urls: (n?: number) => View /** return terms like `'he'` */ pronouns: (n?: number) => View /** return terms like `'but'`*/ conjunctions: (n?: number) => View /** return terms like `'of'`*/ prepositions: (n?: number) => View /** return terms like `'Dr.'`*/ honorifics: (n?: number) => View /** return terms like `'st.'`*/ abbreviations: (n?: number) => View /** return terms like `'(939) 555-0113'` */ phoneNumbers: (n?: number) => View /** return terms like `'23 Park Avenue'` */ addresses: (n?: number) => View // Subsets /** return terms like `'FBI'` */ acronyms: (n?: number) => Acronyms /** return anything inside (parentheses) */ parentheses: (n?: number) => Parentheses /** return terms like "Spencer's" */ possessives: (n?: number) => Possessives /** return any terms inside 'quotation marks' */ quotations: (n?: number) => Quotations /** return any slashed terms like 'love/hate' */ slashes: (n?: number) => Slashes /** return words like "clean" */ adjectives: (n?: number) => Adjectives /** return words like "quickly" */ adverbs: (n?: number) => Adverbs /** return noun phrases in the view */ nouns: (n?: number, opts?: object) => Nouns /** return any numbers in the view */ numbers: (n?: number, opts?: object) => Numbers /** return any percentages in the view */ percentages: (n?: number, opts?: object) => Numbers /** return any money in the view */ money: (n?: number, opts?: object) => Money /** return any fractions in the view */ fractions: (n?: number, opts?: object) => Fractions /** return full sentences in the view */ sentences: (n?: number, opts?: object) => Sentences /** find full sentences of any questions in the view */ questions: (n?: number, opts?: object) => View /** return any subsequent terms tagged as a Verb */ verbs: (n?: number) => Verbs /** return person names like `'John A. Smith'`*/ people: (n?: number) => People /** return location names like `'Paris, France'`*/ places: (n?: number) => View /** return companies and org names like `'Google Inc.'`*/ organizations: (n?: number) => View /** return people, places, and organizations */ topics: (n?: number) => View } // Nouns class export interface Nouns extends View { /** grab the parsed noun-phrase */ parse: (n?: number) => object[] /** return only plural nouns */ isPlural: () => View /** get any adjectives describing this noun*/ adjectives: () => View /** 'a football captain' → 'football captains'. Pass {agree: false} to keep the article and verb as they are */ toPlural: (n?: number | { agree?: boolean }, opts?: { agree?: boolean }) => View /** 'sells seashells' → 'sells a seashell'. Pass {agree: false} to keep the article and verb as they are */ toSingular: (n?: number | { agree?: boolean }, opts?: { agree?: boolean }) => View } export interface Numbers extends View { /** grab the parsed number */ parse: (n?: number) => object[] /** grab the parsed number */ get: (n?: number) => number | number[] /** grab 'kilos' from `25 kilos' */ // units: () => View /** return only ordinal numbers */ /** drop matches that do not parse to a usable number */ isValid: () => View isOrdinal: () => View /** return only cardinal numbers */ isCardinal: () => View /** return only numbers with the given unit(s), like 'km' */ isUnit: (units: string | string[] | object) => View /** convert number to `5` or `5th` */ toNumber: () => View /** add commas, or nicer formatting for numbers */ toLocaleString: () => View /** convert number to `five` or `fifth` */ toText: () => View /** convert number to `five` or `5` */ toCardinal: () => View /** convert number to `fifth` or `5th` */ toOrdinal: () => View /** convert decimals to reduced fractions, or percentages to fractions over 100 */ toFraction: () => Fractions /** convert decimals to percentages */ toPercentage: () => Numbers /** convert percentages to decimals */ toDecimal: () => Numbers /** return numbers with this value */ isEqual: (n?: number) => View /** return numbers bigger than n */ greaterThan: (min: number) => View /** return numbers smaller than n */ lessThan: (max: number) => View /** return numbers between min and max */ between: (min: number, max: number) => View /** set number to n. The counted noun, and its verb, follow - 'two dogs bark' → 'one dog barks' - unless {agree: false} */ set: (n: number, opts?: { agree?: boolean }) => View /** increase number by n. The counted noun, and its verb, follow, unless {agree: false} */ add: (n: number, opts?: { agree?: boolean }) => View /** decrease number by n. The counted noun, and its verb, follow, unless {agree: false} */ subtract: (n: number, opts?: { agree?: boolean }) => View /** increase number by 1 */ increment: () => View /** decrease number by 1*/ decrement: () => View } export interface MoneyValue { currency: string num: number } export interface MoneyJson { money: MoneyValue [key: string]: unknown } export interface Money extends Omit<Numbers, 'toOrdinal' | 'toCardinal' | 'toFraction' | 'toPercentage' | 'toDecimal'> { parse: (n?: number) => MoneyValue[] get: (n?: number) => number[] json: (n?: number | JsonProps | string) => MoneyJson[] values: (n?: number, opts?: object) => Numbers units: () => View /** drop matches that do not parse to a usable number */ isValid: () => this isOrdinal: () => this isCardinal: () => this isUnit: (units: string | string[] | object) => this clone: (shallow?: boolean) => this filter: (fn: (m: this) => boolean) => this numbers: (n?: number, opts?: object) => Numbers currency: (n?: number) => string[] set: (n: number | string) => this add: (n: number | string) => this subtract: (n: number) => this increment: () => this decrement: () => this plus: (n: number | string) => this minus: (n: number) => this isEqual: (n?: number) => this equals: (n: number) => this greaterThan: (n: number) => this lessThan: (n: number) => this between: (min: number, max: number) => this isBetween: (min: number, max: number) => this toNumber: () => this toText: () => this toLocaleString: () => this toNice: () => this first: (n?: number) => this last: (n?: number) => this eq: (n: number) => this slice: (start: number, end?: number) => this } export interface Fractions extends View { /** grab the parsed number */ parse: (n?: number) => object[] /** grab the parsed number */ get: (n?: number) => number | number[] /** convert '1/4' to `0.25` */ toDecimal: () => Numbers /** convert 'one fourth' to `1/4` */ toFraction: () => Fractions /** convert '1/4' to 'one fourth' */ toOrdinal: () => View /** convert '1/4' to 'one out of four' */ toCardinal: () => View /** convert '1/4' to 'one fourth' */ toText: () => Three /** convert '1/4' to `25%` */ toPercentage: (n?: number) => Three first: (n?: number) => this last: (n?: number) => this eq: (n: number) => this slice: (start: number, end?: number) => this } // Sentences class export interface Sentences extends View { /** grab the parsed sentence */ parse: (n?: number) => object[] /** 'will go' → 'went' */ toPastTense: () => View /** 'walked' → 'walks' */ toPresentTense: () => View /** 'walked' → 'will walk' */ toFutureTense: () => View /** 'walks' → 'walk' */ toInfinitive: () => View /** 'walks' → 'walking' */ // toGerund: () => View /** 'he is cool' → 'he is not cool' */ toNegative: () => View /** 'he isn't cool' -> 'he is cool' */ toPositive: () => View /** keep only questions */ isQuestion: () => View /** keep only sentences with an exclamation-mark*/ isExclamation: () => View /** remove questions, and exclamations */ isStatement: () => View } export interface People extends View { /** get first/last/middle names */ parse: () => object[] } // Verbs class export interface Verbs extends View { /** grab the parsed verb-phrase */ parse: (n?: number) => object[] /** grab what [doing] the verb */ subjects: () => View /** return the adverbs describing this verb */ adverbs: () => View /** return only singular nouns */ isSingular: () => View /** return only plural nouns */ isPlural: () => View /** only verbs that are instructions*/ isImperative: () => View /** 'walks' → 'walk' */ toInfinitive: () => View /** 'walked' → 'walks' */ toPresentTense: () => View /** 'will go' → 'went' */ toPastTense: () => View /** 'walked' → 'will walk' */ toFutureTense: () => View /** 'walks' → 'walking' */ toGerund: () => View /** 'walks' → 'has walked' */ toPastParticiple: () => View /** return all forms of these verbs */ conjugate: () => object[] /** return verbs with 'not' */ isNegative: () => View /** only verbs without 'not'*/ isPositive: () => View /** "didn't study" → 'studied' */ toPositive: () => View /** 'went' → 'did not go'*/ toNegative: () => View } export interface Acronyms extends View { /** 'F.B.I.' -> 'FBI' */ strip: () => View /** 'FBI' -> 'F.B.I.' */ addPeriods: () => View } export interface Parentheses extends View { /** remove ( and ) punctuation */ strip: () => View } export interface Possessives extends View { /** "spencer's" -> "spencer" */ strip: () => View } export interface Quotations extends View { /** remove leading and trailing quotation marks */ strip: () => View } export interface Slashes extends View { /** turn 'love/hate' into 'love hate' */ split: () => View } export interface Adjectives extends View { /** get the words describing this adjective */ adverbs: () => View /** return all forms of these */ conjugate: () => object[] toRoot: (n?: number) => View /** 'quick' -> 'quicker' */ toComparative: (n?: number) => View /** 'quick' -> 'quickest' */ toSuperlative: (n?: number) => View /** 'quick' -> 'quickly' */ toAdverb: (n?: number) => View /** 'quick' -> 'quickness' */ toNoun: (n?: number) => View } // only overloads .json() export interface Adverbs extends View { } export default Three