Overview of compromise-ast
mastercompromise-ast plugin is an experimental extension for the compromise NLP library. It attempts to generate a unist-formatted Abstract Syntax Tree (AST) by utilizing dependency parsing techniques on text.repository·master·Indexed 11 days ago
https://github.com/spencermountain/compromiseA modest natural language processing (NLP) library version 14.16.0 designed to turn text into structured data. It is optimized to be small and fast for parsing, transforming, and extracting information. The ecosystem includes plugins such as compromise-dates for temporal extraction, compromise-paragraphs for text segmentation, and compromise-payload for metadata storage.
compromise-ast plugin is an experimental extension for the compromise NLP library. It attempts to generate a unist-formatted Abstract Syntax Tree (AST) by utilizing dependency parsing techniques on text.compromise-markdown plugin provides experimental Natural Language Processing (NLP) capabilities specifically designed to work on a unified/remark Abstract Syntax Tree (AST). It allows you to apply NLP logic to markdown structures by leveraging the remark ecosystem.compromise-cmd-k plugin provides experimental NLP capabilities specifically designed for parsing command-prompt style inputs within the compromise ecosystem.The compromise-wikipedia plugin is an experimental tool designed for efficient Named-entity Recognition (NER). It uses a highly-compressed list of ~38,000 popular Wikipedia articles to scan text.
Key characteristics:
When working with or adding to the lexicon, be aware of the following rules:
[0-9,;!:|¦]../switches/person-date.js) rather than the general lexicon.Compromise allows you to create specialized sub-views of a document using selection methods. These methods return a View containing only the matched terms, which can then be further processed with specific methods related to that type of content.
Common selection methods include:
.nouns(): Noun phrases..verbs(): Verb phrases..people(): Person names..places(): Location names..organizations(): Companies and organizations..topics(): A combination of people, places, and organizations..numbers(): Numeric values..sentences(): Full sentences..adjectives(): Words like "clean"..adverbs(): Words like "quickly"..urls(), .emails(), .atMentions(), .phoneNumbers(), .addresses().The .paragraphs() method is a plugin for compromise that segments a document into paragraph objects.
Mental Model:
This plugin acts as a wrapper for sentence objects. This allows you to treat a group of sentences as a single paragraph unit (using methods like .text() or .json()), while still being able to 'drop back down' to the sentence level using .sentences() to continue standard NLP processing.
Note on Mutability:
Paragraph objects are mutable. When you apply transformations like .filter(), you are modifying the document structure.
let str = `What's with these homies dissin' my girl? Why do they gotta front?
What did we ever do to these guys that made them so violent?
Woo-hoo, but you know I'm yours.`
let doc = nlp(str).paragraphs()By default, matching in compromise does not cross sentence boundaries. For example, nlp("that's it. Back to Winnipeg!").has('it back') will return false because 'it' and 'back' are in different sentences.
To perform matching across multiple sentences or paragraphs, use the compromise-paragraphs plugin.
nlp("that's it. Back to Winnipeg!").has('it back') // falseWarning: Transform methods mutate the underlying Document in place.
Even though transform methods return a View, they change the shared document that the View points to.
.match(), .if(), .found(), .text(), .json(), .has(), and accessors) do not change the document..toPastTense(), .replace(), .remove(), .tag(), .normalize(), and case/whitespace methods) do change the document.To perform transformations without affecting the original document, call .clone() before your transformations.
let doc = nlp('I walk to work')
// This mutates 'doc'
doc.verbs().toPastTense()
doc.text() // 'I walked to work'
// This keeps 'doc' untouched
let past = doc.clone().verbs().toPastTense().text()let doc = nlp('I walk to work')
doc.verbs().toPastTense() // mutates doc, even though we didn't reassign
doc.text() // 'I walked to work' ← doc changed
// To work on a copy without touching the original, call .clone() first:
let past = doc.clone().verbs().toPastTense().text() // doc is untouchedCrucial for all users: Transform methods in Compromise change the underlying document in place. When you call a method like .verbs().toPastTense(), the original document is mutated.
Additionally, the object returned by a selection (a 'View') represents only the matched subset, not the entire document. To get the full modified text, you must call .text() on the original document object.
To perform transformations without modifying the original document, use .clone().
// ⚠️ COMMON MISTAKE
// The returned view is just the selection, not the whole document
nlp('I walk to work').verbs().toPastTense().text() // 'walked work'
// ✅ CORRECT WAY
let doc = nlp('I walk to work')
doc.verbs().toPastTense()
doc.text() // 'I walked to work'
// ✅ TRANSFORMING A COPY
let doc = nlp('I walk')
let past = doc.clone().verbs().toPastTense().text() // 'walked'
doc.text() // 'I walk' (untouched)The compromise/three entry point provides advanced tooling to zoom into and operate on specific parts of a text. It includes specialized methods for extracting and manipulating data like numbers, money, and fractions.
import nlp from 'compromise/three'
let doc = nlp("Wayne's World, party time")
let str = doc.people().normalize().text()
// "wayne"Before using compromise, be aware of the following technical limitations:
nlp('the koala eats/shoots/leaves').has('koala leaves') returns false.compromise-paragraphs plugin.nlp("that's it. Back to Winnipeg!").has('it back') returns false.(a (b|c))). Complex matches must be achieved by chaining successive .match() calls.