compromise-payload
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published
An ad-hoc datastore for compromise
npm install compromise-payload

This plugin provides a facilty for storing a retreiving more complex data than tags, for compromise documents and matches.

Payload

import plg from 'compromise-payload'
nlp.extend(plg)

let doc = nlp('i saw John Lennon in Manchester, and Bob Dylan in Southhampton')

// markup metadata
doc.match('(john lennon|bob dylan)').addPayload({ instrument: 'guitar' })

// add more
doc.people().forEach(m => {
  if (m.has('lennon')) {
    m.addPayload({ height: `5'11` })
  }
  if (m.has('ringo')) {
    m.addPayload({ height: `5'8` })
  }
})

// retrieve specific payloads
doc.match('john lennon').getPayloads()
doc.match('bob dylabn').getPayloads()

// retrieve them all
doc.getPayloads()

// inspect given payloads:
doc.debug('payload')

You can also pass a callback into .addPayload():

let doc = nlp('i saw John Lennon, and john smith and bob dylan')
doc.people().addPayload(m => {
  return { lastName: m.terms().last().text() }
})

You can remove all, or selected payloads with .clearPayload():

doc.match('bob .').clearPayloads()
doc.getPayloads().length // now 2

doc.clearPayloads()
doc.getPayloads().length // now 0

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i compromise-payload

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

11.8 kB

Total Files

8

Last publish

Collaborators

  • spencermountain