基于管道过滤器的KWIC系统实现(1)
来源:互联网 发布:新星星知我心1998全集 编辑:程序博客网 时间:2024/05/17 00:17
基于管道过滤器的KWIC系统实现。
实现噪声单词过滤以及首单词大写功能。
package lws;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
* To construct the framework of the system
*/
public class KWIC{
public void execute(String file,String noisyFile){
try{
Pipe in_lt=new Pipe();
Pipe lt_cs = new Pipe();
Pipe cs_lt = new Pipe();
Pipe lt_al=new Pipe();
Pipe al_sf=new Pipe();
Pipe sf_ou=new Pipe();
FileInputStream in = new FileInputStream(file);
FileInputStream noise=new FileInputStream(noisyFile);
BufferedReader br=new BufferedReader(new InputStreamReader(noise));
String str;
ArrayList<String> noises=new ArrayList<String>();
while((str=br.readLine())!=null){
noises.add(str);
}
Input input = new Input(in, in_lt);
LineTransformer lineTransformer1 =new LineTransformer(in_lt,lt_cs);
CircularShifter shifter = new CircularShifter(lt_cs, cs_lt);
LineTransformer lineTransformer2 =new LineTransformer(cs_lt,lt_al);
Alphabetizer alpha = new Alphabetizer(lt_al, al_sf);
ShiftFilter shiftFilter=new ShiftFilter(al_sf,sf_ou,noises);
Output output = new Output(sf_ou);
input.start(); // run it !
lineTransformer1.start();
shifter.start();
lineTransformer2.start();
alpha.start();
shiftFilter.start();
output.start();
}catch(IOException exc){
exc.printStackTrace();
}
}
/*
* there would be two parameters to start the main thread,first if the file of input
* and the second if the file of noisy words
*/
public static void main(String[] args){
if(args.length != 2){
System.err.println("KWIC Usage: java kwic.ms.KWIC file_name noisy_file_name");
System.exit(1);
}
KWIC kwic = new KWIC();
kwic.execute(args[0],args[1]);
}
}
package lws;
import java.io.IOException;
import java.io.InputStream;
public class Input extends Filter{
private InputStream in_;
/*
* Read from InputStream in and write to Pipe output
* And transform the input stream to standard form:every words departed by a single
* space and every line ends with a '\n'
*/
public Input(InputStream in, Pipe output){
super(null, output);
in_ = in;
}
protected void transform(){
try{
boolean is_new_line = false;
boolean is_new_word = false;
boolean is_line_started = false;
int c = in_.read();
while(c != -1){
switch((byte) c){
case '\n':
is_new_line = true;
break;
case ' ':
is_new_word = true;
break;
case '\t':
is_new_word = true;
break;
case '\r':
break;
default:
if(is_new_line){
output_.write('\n');
is_new_line = false;
is_line_started = false;
}
if(is_new_word){
if(is_line_started)
output_.write(' ');
is_new_word = false;
}
output_.write(c);
is_line_started = true;
break;
}
c = in_.read();
}
output_.write('\n');
output_.closeWriter();
}catch(IOException exc){
exc.printStackTrace();
System.err.println("KWIC Error: Could not read the input file.");
System.exit(1);
}
}
}
- 基于管道过滤器的KWIC系统实现(1)
- 基于管道过滤器的KWIC系统实现(2)
- 基于管道过滤器的KWIC系统实现(3)
- 基于管道过滤器的KWIC系统实现(4)
- 基于KWIC 的关键字匹配算法(管道+过滤器模式下实现)
- KWIC:管道-过滤器模式.
- KWIC:基于主程序/子程序风格的实现
- KWIC问题的实现
- KWIC系统之事件架构实现(主程序)
- 管道过滤器的实现---java语言
- 基于java过滤器实现web系统的IP访问控制
- 基于java过滤器实现web系统的IP访问控制
- KWIC系统之事件架构实现(排序模块,拆分模块,输入模块)
- KWIC系统之事件架构实现(输出模块,单词统计类,单词存储类)
- kwic系统模拟
- 软件体系结构上机实验 面向对象体系结构风格的 KWIC 关键词索引系统设计与实现 java
- KWIC-C/C++实现
- KWIC系统之事件架构实现(行存储类,行存储包装类,行存储改变事件)
- SurfaceView绘制触摸轨迹闪烁的解决方法二
- SurfaceView绘制触摸轨迹闪烁问题的最终解决方案
- 用View绘制触摸轨迹
- Java编写的多线程端口扫描器
- compile and execute cpp file in ubuntu
- 基于管道过滤器的KWIC系统实现(1)
- 基于管道过滤器的KWIC系统实现(2)
- 基于管道过滤器的KWIC系统实现(3)
- 基于管道过滤器的KWIC系统实现(4)
- poj1207-the 3n+1 problems
- poj1401 Factorial
- poj1405-Heritage
- 关于Java中的对象数组初始化
- 关于逻辑与与按位与