0.1.1 • Published 2 years ago
compromise-speed v0.1.1
WorkerPool
parse sentences of a large text in parallel:
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:
let net = nlp.buildNet([
{ match: 'every single #Noun' },
{ match: 'not (a|one) #Noun' },
])
let doc = await nlp.workerPool(myNovel, net)
doc.debug()//results
StreamFile
parse and process a file from your filesystem, without loading it all into memory:
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.
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:
<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