有一个9M多行的语料库,文件大小4G。现在需要匹配指定动词,符合句子条件的输出。
但是文件过大。每次读取一行。匹配下来要好久。请问有没有什么方法可以加快处理速度。
BufferedReader cpreader = new BufferedReader(new InputStreamReader(new FileInputStream(this.getCorpusPath())));
tring line = cpreader.readLine();
while(line != null)
{
ArrayList<String> verbList = new ArrayList();
matcher_line = Pattern.compile("(.*\\%\\&\\$cook\\%\\&\\$VB.*)").matcher(line);
if(matcher_line.find())
{
System.out.println(line);
}
line = cpreader.readLine();
}
读文件的话应该是没有问题的,不过你可以尝试改为缓冲式读取,因为一行的大小 可能是不确定的,会对效率造成影响吧。。
匹配的话如果是单个单词的话,可以改用更好的匹配方法,正则的话就不晓得了