Getting lemmas for all words in sentence #1136
-
I'm trying to process a sentence, to get base form for each word
and
which produces this result:
is also not enough: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
hi @moskaliukua - i think this is probably what you're looking for - let doc = nlp(' I am going to the store')
doc.compute('root')
doc.json() https://runkit.com/spencermountain/66b243b9e0d0c900085ae794 |
Beta Was this translation helpful? Give feedback.
-
Since your goal is "I am going to the store" => "I be go to the store", it tells me that each word needs to be processed, since "am going" and "am going to" can sometimes be considered as being derived from "to go" in some contexts. And since you want "be" instead of "is", here are 2 alternatives: (i noticed that "am" and also "had" were otherwise not turning into their infinitives "be" and "have") const sentence = 'I am going to the store';
const docs = sentence.split(' ').map(word => nlp(word));
docs.forEach(word => word.verbs().toInfinitive());
const output_1 = docs.map(doc => doc.text()).join(' ');
document.body.querySelector('#output_1').innerText = output_1;
// I be go to the store or: const sentence = 'I am going to the store';
const doc = nlp(sentence);
const output_2 = doc.terms().map(view => {
const wordDoc = nlp(view.text());
wordDoc.verbs().toInfinitive();
return wordDoc.text();
}).join(' ');
document.body.querySelector('#output_2').innerText = output_2;
// I be go to the store Here's a demo you edit live without login: https://codepen.io/hchiam/pen/NWZgORW?editors=1000 |
Beta Was this translation helpful? Give feedback.
hi @moskaliukua - i think this is probably what you're looking for -
https://runkit.com/spencermountain/66b243b9e0d0c900085ae794
you can see the documentation for root-words here
cheers