How to parse text into sentences

后端 未结 7 1381
星月不相逢
星月不相逢 2020-12-06 07:31

I\'m trying to break up a paragraph into sentences. Here is my code so far:

import java.util.*;

public class StringSplit {
 public static void main(String a         


        
相关标签:
7条回答
  • 2020-12-06 08:06

    The first one is a pretty hard problem to do properly, since you'd have to implement sentence detection. I suggest you don't do that, and just separate sentences with two blank lines after a punctuation mark. For example:

    "The outcome of the negotiations is vital, because the current tax levels signed into law by President George W. Bush expire on Dec. 31.  Unless Congress acts, tax rates on virtually all Americans who pay income taxes will rise on Jan. 1.  That could affect economic growth and even holiday sales."
    

    The second one can be solved using String.trim().

    Example:

    String one = "   and now...    ";
    String two = one.trim();
    System.out.println(two);          // output: "and now..."
    
    0 讨论(0)
提交回复
热议问题