我试图将一个段落分解成句子.到目前为止,这是我的代码:
import java.util.*;
public class StringSplit {
public static void main(String args[]) throws Exception{
String testString = "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.";
String[] sentences = testString.split("[\\.\\!\\?]");
for (int i=0;i<sentences.length;i++){
System.out.println(i);
System.out.println(sentences[i]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
发现了两个问题:
Fav*_*ius 14
你提到的问题是NLP(自然语言处理)问题.编写原始规则引擎很好,但它可能无法扩展以支持完整的英文文本.
要获得更深入的见解和java库,请查看此链接http://nlp.stanford.edu/software/lex-parser.shtml,http://nlp.stanford.edu:8080/parser/index.jsp和类似ruby语言问题如何将一段文本解析成句子?(在Ruby中)
例如:文本 -
谈判的结果至关重要,因为乔治·W·布什总统签署的现行税收水平将于12月31日到期.除非国会采取行动,几乎所有缴纳所得税的美国人的税率将在1月1日上升.可能会影响经济增长甚至假日销售.
标记后变为:
/ DT协议/ NNS的/ DT结果/ NN是/ VBZ至//JJ,/,因为/ IN/DT当前/ JJ税/ NN级别/ NNS签署/ VBN进/ IN法/ NN/IN President/NNP George/NNP W./NNP Bush/NNP expire/VBP on/RP Dec./NNP 31/CD ./.除非/ IN国会/ NNP行动/ VBZ,/,税/ NN率/ NNS/IN// RB所有/ RB美国人/ NNPS谁/ WP支付/ VBP收入/ NN税/ NNS将/ MD上升/ VB上/ 1月/ NNP 1/CD ././ DT可能/ MD影响/ VB经济/ JJ增长/ NN和/ CC甚至/ RB假期/ NN销售/ NNS ./.解析
检查它如何区分句号(.)和12月31日之后的句号......