Is it possible to maintain newlines in .sentences.out()? #114
-
For example, let's say the following paragraphs are read into a doc.
If I do I looked through the docs, including the Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You are right, there is no helper to get that. You can use following code to meet your requirements: const winkNLP = require( 'wink-nlp' );
const model = require( 'wink-eng-lite-web-model' );
const nlp = winkNLP( model );
const its = nlp.its;
const text = 'U.S.A is my birth place. \n\nI was born on 06.12.1924.I climbed Mt. Everest. It was fun!';
const doc = nlp.readDoc( text );
doc.sentences().each(s => {
const sentence = [];
s.tokens().each( t => sentence.push( t.out(its.precedingSpaces), t.out() ));
console.log(sentence.join(''))
});
// Outputs:
// --> "U.S.A is my birth place."
// --> " \n\nI was born on 06.12.1924."
// --> "I climbed Mt. Everest."
// --> " It was fun!" A similar discussion took place here. Any suggestions on what kind of a meaningful helper can be added for such needs would be appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
You are right, there is no helper to get that. You can use following code to meet your requirements: