Compromise

is a JavaScript library that can parse, transform, and help use text. github , site , docs

To run Compromise client-side, we uploaded an HTML document named importCompromise.html to an Assets section:

pages/compromise

See Compromise-quickstart page .

In the HTML document above, we load the Compromise library from the CDN (content delivery network) of unpkg.com. The latest version of the library is used, and the file is loaded in a minimized version from the builds directory.

We create a new variable t and assign it the result of calling the nouns and toPlural methods on the window.nlp('dinosaur') object:

var t = nlp('dinosaur').nouns().toPlural();

This object is created by calling the nlp function loaded from the Compromise library via the importCompromise.html file.

We add an ECMAScript module import statement that uses the import keyword to import the $compile function from the "@thi.ng/rdom" package:

import { $compile } from "https://cdn.skypack.dev/@thi.ng/rdom";

The import statement specifies the source of the package as "https://cdn.skypack.dev/@thi.ng/rdom", which is a CDN that hosts the package files.

We create the output frame [⇒ Static Import Snippet] using our importCompromise.html file based on importjs.html:

//wiki.ralfbarkow.ch/assets/pages/compromise/importCompromise.html HEIGHT 75

~

We send a message to the Frame asking it to send us info about the page surrounding it. mdn

window.addEventListener("message", handler) let message = { action:"sendFrameContext" } window.parent.postMessage(message, "*")

We stop listening then process the data we got.

function handler ({data}) { if (data.action == "frameContext") { window.removeEventListener("message", handler) const {slug, item, page} = data

$compile( ["pre", {}, t.out('text')] ).mount(document.getElementById("output"));

We show the result by calling the out method on the t object, passing in the argument 'text' to indicate that we want the result as a plain text string, that we send to the output frame where "dinosaurs" is displayed.

} // end if

} // end of function handler

~

For a compromise-version of Joseph Weizenbaum's amazing ELIZA bot, see page , video .