Back to Compromise

README

plugins/speed/README.md

14.15.02.8 KB
Original Source
<div align="center"> <div>nlp performance plugin for <a href="https://github.com/spencermountain/compromise/">compromise</a></div> <!-- npm version --> <a href="https://npmjs.org/package/compromise-speed"> </a> <!-- file size --> <a href="https://unpkg.com/compromise-speed/builds/compromise-speed.min.js"> </a> <div align="center"> <code>npm install compromise-speed</code> </div> </div> <!-- spacer -->

WorkerPool

parse sentences of a large text in parallel:

js
import {workerPool} from 'compromise-speed'
nlp.extend(workerPool)

let doc = await nlp.workerPool(myNovel, 'the #Adjective of #Noun')
doc.debug()//results

you can pass in a compromise match, or a net:

js
let net = nlp.buildNet([
  { match: 'every single #Noun' },
  { match: 'not (a|one) #Noun' },
])
let doc = await nlp.workerPool(myNovel, net)
doc.debug()//results
<!-- spacer -->

StreamFile

parse and process a file from your filesystem, without loading it all into memory:

js
import {streamFile} from 'compromise-speed'
nlp.extend(streamFile)

nlp.streamFile('./path/to/file.txt', (s)=>{
  // map fn on each sentence
  return s.if('the #Adjective of times')
}).then(doc=>{
  // just the returned matches
  doc.debug()
})

Keypress

if you are running compromise on every keystroke, it is not necessary to re-parse all sentences, every time. This plugin will cache any already-parsed sentences, and combine them in-memory, with any changed ones.

it will also un-cache any temporary sentences, to clear-up memory.

js
import {keyPress} from 'compromise-speed'
nlp.extend(keyPress)

let doc = nlp.keyPress('parsed once. it was the blurst of')
doc = nlp.keyPress('parsed once. it was the blurst of times')

or in the browser:

html
<textarea>Chocolate microscopes? Double guitars?</textarea>
<script src="https://unpkg.com/compromise"></script>
<script src="https://unpkg.com/compromise-speed"></script>
<script defer>
  nlp.plugin(compromiseSpeed.keyPress)
  document.querySelector('textarea').onkeypress = (e) => {
    let doc = nlp.keyPress(e.target.value)
  }
</script>

MIT