Skip to content

Is it possible to maintain newlines in .sentences.out()? #114

Discussion options

You must be logged in to vote

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!"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Chaddeus
Comment options

Answer selected by Chaddeus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants