我是用Java编程的新手。我想将一个文件中的段落拆分成句子并将它们写入不同的文件中。此外,还应该有一种机制来确定哪个句子来自哪一段。到目前为止,我使用的代码如下所述。但是这个代码打破:将段落分解成句子 - 一个特例
Former Secretary of Finance Dr. P.B. Jayasundera is being questioned by the police Financial Crime Investigation Division.
到
Former Secretary of Finance Dr.
P.B.
Jayasundera is being questioned by the police Financial Crime Investigation Division.
我怎样才能纠正呢?提前致谢。
import java.io.*;
class trial4{
public static void main(String args[]) throws IOException
{
FileReader fr = new FileReader("input.txt");
BufferedReader br = new BufferedReader(fr);
String s;
OutputStream out = new FileOutputStream("output10.txt");
String token[];
while((s = br.readLine()) != null)
{
token = s.split("(?<=[.!?])\\s* ");
for(int i=0;i<token.length;i++)
{
byte buf[]=token[i].getBytes();
for(int j=0;j<buf.length;j=j+1)
{
out.write(buf[j]);
if(j==buf.length-1)
out.write('\n');
}
}
}
fr.close();
}
}
我引用的所有贴在StackOverflow上的类似的问题。但是这些答案无法帮助我解决这个问题。
这将是合理很难做到,除非你能正式的“这一时期标志着一个缩写” VS“这个时期标志着一个句子的末尾”的一些概念。 –