Drop the payload limitations that term ids fix

This commit is contained in:
dualfroz committed 2026-10-04 17:09:02 +02:00
1 parent 6a37de09a7
commit 641379c79c
1 file changed
-23
-23
View File
@@ -74,27 +74,4 @@ doc.clearPayloads()
doc.getPayloads().length // now 0
```
### Limitations
Payloads are saved by sentence number and term position, in one store that every document from the same `nlp` shares. That means:
- **Removing a sentence breaks the payloads that come after it.** They move to the wrong sentence, and the last one can go missing. Add payloads after you remove sentences, or add them again. Changing words inside a sentence is fine.
```js
let doc = nlp('One is red. Two is blue. Three is green.')
doc.match('(red|blue|green)').forEach(m => m.addPayload({ color: m.text() }))
doc.remove('two is blue')
doc.getPayloads().map(p => [p.match.text(), p.val.color])
// [['red', 'red'], ['Three is green', 'blue']]
```
- **A new document can see payloads from an older one** at the same sentence and term positions. Call `.clearPayloads()` on a document when you are done with it.
```js
nlp('the red car').match('car').addPayload({ kind: 'vehicle' })
nlp('a blue bike').getPayloads().length // 1, from the first document
```
See [#1188](https://github.com/spencermountain/compromise/issues/1188).
MIT