How can I split sentences in paragraphs based on the period(.)? I want to use a Stanford Parser(Java).
For instance, I have a paragraphs.
Your skills of writing Paragraph will make you a perfect man. If you look at any printed prose book, you will see that each chapter is divided up into sections, the first line of each being indented slightly to the right. These sections are called Paragraph. Chapters, essays and other prose compositions are broken up into paragraphs, to make the reading of them easier.
After splitting,
Your skills of writing Paragraph will make you a perfect man.
If you look at any printed prose book, you will see that each chapter is divided up into sections, the first line of each being indented slightly to the right.
These sections are called Paragraph.
Chapters, essays and other prose compositions are broken up into paragraphs, to make the reading of them easier.
I hope to get this result. How can I get this result by using Stanford Parser?
You don't need to bring in a special parser to do this when you already have the String.split() method. You just need to utilize the proper Regular Expression (RegEx) to carry out the task.
Sentences within a paragraph may not just contain a period at the end of it. There could be a Question Mark (?) or perhaps an Exclamation Mark (!) at the end of the sentence. To truly pull out all sentences from a paragraph you will need to consider this. Another thing to consider, What if there is a numerical value which happens to go to a specific decimal point within the sentence like:
Now looking at the small paragraph above you can clearly see some things within it that need to be obviously considered when splitting it into individual sentences. We can't just base everything from a period (.). We don't really want to split monetary values and web domains, and, we don't what question or exclamation sentences included into other sentences.
To break down this example paragraph into individual sentences without damaging content with the String.split() method we can use this Regular Expression:
Did you notice that we used the String.trim() method here as well? Some paragraphs can start with a Tab or spaces so we just get rid of those right off the start before the split is carried out (just in case). The Regular Expression used (which utilizes Positive Look-Behind) within the String.split() method isn't really all that complicated and you can test it here. Here is what it's about:
If you were to now iterate through the String Array variable named sentences like this:
your console output should look something like: