sentences()
sentences() → { collection of sentences }
This API returns a collection of sentences in the winkNLP document. If the input text contains one sentence, then we get a collection of sentences with a single member. Likewise, if no sentence-break is found in the input text, we get the output in the same manner!
You can chain it further with other winkNLP APIs like each()
, length()
, filter()
, etc. However, to get the output in a JavaScript data type, you need to follow this API with out()
.
Example:
const text = 'AI Inc. is focussing on AI. I work for AI Inc. My mail is r2d2@yahoo.com! The U.S.A is my birth place. I was born on 06.12.1996. I climbed Mt. Everest.';
const doc = nlp.readDoc( text );
const sentences = doc.sentences().out();
console.log( sentences );
// -> [ 'AI Inc. is focussing on AI.',
// 'I work for AI Inc.',
// 'My mail is r2d2@yahoo.com!',
// 'U.S.A is my birth place.',
// 'I was born on 06.12.1996.',
// 'I climbed Mt. Everest.' ]
// Tweet
const text = '3rd TIME watching That70sShow:D @Netflix http://tiny.cc/fijqkz';
const doc = nlp.readDoc( text );
console.log( doc.sentences().out() );
// -> [ '3rd TIME watching That70sShow:D @Netflix http://tiny.cc/fijqkz' ]
// Single sentence
const text = 'Mr. Z owns AI Inc. and he climbed Mt. Everest.';
const doc = nlp.readDoc( text );
console.log( doc.sentences().out() );
// -> [ 'Mr. Z owns AI Inc. and he climbed Mt. Everest.' ]