Last active
August 29, 2015 13:56
-
-
Save yauhen-info/8997669 to your computer and use it in GitHub Desktop.
Heuristic to detect paragraphs in a raw text with new lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package info.yauhen; | |
| public class BoundariesEditor { | |
| public static void main(String[] args) { | |
| //Substitute | |
| String testString = "Sun Life Financial Inc,\n" + | |
| "Canada's No. 3 life insurer, said on Wednesday its\n" + | |
| "fourth-quarter profit rose 39 percent, helped by a C$290 million\n" + | |
| "gain related to the restructuring of internal reinsurance\n" + | |
| "arrangements. \n" + | |
| "Net profit was C$550 million ($500.52 million), or 90\n" + | |
| "Canadian cents a share, during the quarter, up from C$395\n" + | |
| "million, or 65 Canadian cents a share, in the year-before\n" + | |
| "period. "; | |
| /* | |
| $1 = group (\\.) - just a point; | |
| $2 = group ([\s]*\n) - spaces(optional) and new line; | |
| $3 = group ([A-Z]) - capitalized character (the first letter in a first word in a sentence); | |
| */ | |
| testString = testString | |
| .replaceAll("(\\.)([\\s]*\\n)([A-Z])", "$1</p><p>$3"); | |
| System.out.println(testString); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input:
Sun Life Financial Inc,
Canada's No. 3 life insurer, said on Wednesday its
fourth-quarter profit rose 39 percent, helped by a C$290 million
gain related to the restructuring of internal reinsurance
arrangements.
Net profit was C$550 million ($500.52 million), or 90
Canadian cents a share, during the quarter, up from C$395
million, or 65 Canadian cents a share, in the year-before
period.
Output:
Sun Life Financial Inc,
Canada's No. 3 life insurer, said on Wednesday its
fourth-quarter profit rose 39 percent, helped by a C$290 million
gain related to the restructuring of internal reinsurance
arrangements.
Net profit was C$550 million ($500.52 million), or 90
Canadian cents a share, during the quarter, up from C$395
million, or 65 Canadian cents a share, in the year-before
period.