0.0.3 • Published 3 years ago

compromise-export v0.0.3

Weekly downloads
36
License
MIT
Repository
github
Last release
3 years ago

Compromise documents include a lot of methods, circular, and denormalized data. This plugin adds two methods, (.export and .import) that allow you to serialize and compress a document into a JSON object, which can easily be written to a database or text-file.

It also allows sending parsed documents in/out of web-workers, which can massively speed-up performance.

You can always call .text() on a compromise object to get its text back out, to store it, and then re-parse the text at a later time. But in terms of performance, parsing and tagging a document is quite involved, and can be avoided using .export() and .import().

Tradeoffs:

In rough terms, storing an exported document is around 3x larger than the text itself. However, using import() to 'pop it back' into a document is about 10x faster than re-parsing it.

Install

const nlp = require('compromise')
nlp.extend(require('compromise-export'))

let doc = nlp(`bake 'em away, toys`)
let data = doc.export()
//{ tags:[..], words:[..], list:[] }

let doc2 = nlp.import(data)
doc2.debug() // same

Demo

API:

  • .export() - serialize and compress a document into JSON
  • .import() - uncompress JSON data into a compromise object.

See Also

MIT