Unexpected Verb Normalization Behavior Inside .forEach() Loop
Author: rossromaCreated Feb 19, 2025Updated Feb 23, 2025
When using normalize verbs within a .forEach() loop, the output is not as expected. Specifically, the term 'are' in the phrase 'books are not' becomes 'books be not' after normalization inside the loop, whereas the same normalization outside the loop works correctly and returns 'be'.
Version 14.4.4
Steps to reproduce:
- Run the following code:
const nlp = require('compromise');
nlp('books are not').terms().forEach(word => {
const result = word.normalize({
verbs: true
}).text();
console.log('forEach output =>', result);
});
const result = nlp('are').normalize({
verbs: true
}).text();
console.log('single output => ', result);- Observe the output:
forEach output => booksforEach output => books be notforEach output => notsingle output => be
Expected Behavior:
The normalization inside the .forEach() loop should return the expected normalized verb form (e.g., 'be'), similar to how it behaves when called directly outside the loop.
Actual Behavior:
When normalize() is applied inside the .forEach() loop, the result is 'books be not', which is not the expected behavior.
Source: spencermountain/compromise