protected void transform() throws IOException { String templine = \ //读数据
while((templine = input.readerLine()) != null){ //将数据拆分为不同单词
this.lineSplitWord(templine); //将单词重组为句子
this.recombination(); //输出重组结果
for(int i = 0; i < linelist.size(); i++){ output.writerLine(linelist.get(i)); }
//清空wordlist、linelist和templine wordlist.clear(); linelist.clear(); templine = \ }
input.closeReader(); output.closeWriter(); }
//从一行中提取单词存入单词表中
private void lineSplitWord(String line){ String word = \i = 0; while(i <
line.length()){ if(line.charAt(i) != '
'){ word += line.charAt(i);
}
else{ wordlist.add(word);
} i++;
} }
private void recombination(){
for(int j = 0; j < wordlist.size(); j++){ String templine = \
wordlist.size(); k++){ templine += wordlist.get(k) + \ } for (int m = 0; m < wordlist.size() - 1 - j; m++){ if(m != wordlist.size() - j - 2){ templine += wordlist.get(m) + \ }
else{ templine += wordlist.get(m); } }
linelist.add(templine); } } }
Input类 package kwic_pipe;
import java.io.File; import java.io.IOException; import java.util.Scanner;
public class Input extends Filter{
//输入文件的文件名
private File infile; Input(File file, Pipe
output){ super(null, output); this.infile = file; }
@Override //读取数据
protected void transform() throws IOException { Scanner sc = new Scanner(infile); String templine = \sc.nextLine()) !=
null){ output.writerLine(templine); }
output.closeWriter(); sc.close(); } }
Output类 package kwic_pipe; import java.io.File; import java.io.IOException; import java.io.PrintWriter;
public class Output extends Filter{
//输出文件的文件名
private File file; Output(Pipe input, File
file){ super(input, null); this.file = file; }
//输出数据
protected void transform() throws IOException { PrintWriter pw = new PrintWriter(file); String templine = \
while((templine = input.readerLine()) != null){ pw.write(templine); pw.write(\ } pw.flush(); pw.close(); input.closeReader(); } }