If you're parsing a document that's changing in real-time, it's wasteful to re-parse the whole document each time one character changes.
This plugin adds a new function nlp.keypress()
to the compromise object.
This method works the same as the main nlp()
object, except it remembers each sentence, and only re-analyses a sentence if it changes.
npm install compromise-keypress
const nlp = require('compromise')
nlp.extend(require('compromise-keypress'))
let doc = nlp.keypress('Seven bottles of beer on the wall.')
doc = nlp.keypress('Seven bottles of beer on the wall. Six bottles of beer...')
// only re-tags the second sentence
nlp.clear() // invalidate the cache
// (free-up any cached sentences from memory)
.keypress()
automatically deletes unused cached sentences, so extended-use shouldn't hog-up memory needlessly.
Work in progress.
See Also
MIT