kwic学习,摘自网络
来源:互联网 发布:门户网站怎么优化 编辑:程序博客网 时间:2024/06/05 01:10
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class mykwic {
private static BufferedReader input_file;
private ArrayList<String> kwicList;
public mykwic (String filename) //construct the index of file fname
{
kwicList = new ArrayList<String>();
String line="";
fileopen(filename);
while (line!= null)
{
line= readline();
if (line !=null)
{
parseLine(line, kwicList);
}
}
//Collections.sort(kwicList);
display ( kwicList );
}
public static void fileopen(String InputFilename) {
try {
input_file = new BufferedReader(new FileReader(InputFilename));
} catch (IOException e) {
System.err.println(("File not open" + e.toString()));
System.exit(1);
}
}
public static String readline() {
String line ="";
try {
line = input_file.readLine();
} catch (Exception e) {
e.getStackTrace();
}
return line;
}
public void parseLine(String line,ArrayList<String> list) {
StringTokenizer tokener = new StringTokenizer(line);
String token = new String();
int index;
ArrayList<String> tokens = new ArrayList<String>();
int count = tokener.countTokens();
for (int j = 0; j < count; j++) {//将一行解析,并且将解析的word加入ArrayList中
token = tokener.nextToken();
tokens.add(token);
}
//对ArrayList中的字进行循环移位,得出最后结果
for (int i = 0; i < count; i++) {
index=i;
StringBuffer linebuffer = new StringBuffer();
for (int j = 0; j < count; j++) {
if (index >= count)
index = 0;
linebuffer.append ( tokens.get(index) );
linebuffer.append (" ");
index++;
}
line = linebuffer.toString();
kwicList.add(line);
}
}
public static void display(ArrayList<String> List) {
System.out.println("Output is");
for (int count = 0; count < List.size(); count++) {
System.out.println (List.get (count) );
}
}
public static void main(String[] args) {
new mykwic("test.txt");
}
}
作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
- kwic学习,摘自网络
- KWIC
- kwic
- Eclipse快捷键--摘自网络
- SPRING RESORCE --摘自网络
- JDBC连接数据库摘自网络
- ospf协议(摘自网络)
- 开发环境(摘自网络)
- linux 防火墙设置(摘自网络)
- Java学习网站 [摘自互联网]
- Java学习网站 [摘自互联网]
- 控件学习---UILabel--摘自培训资料
- 控件学习---UIButton--摘自培训资料
- 控件学习---UITextField---摘自培训资料
- 控件学习---UISlider---摘自培训资料
- 控件学习---UISegmentedControl---摘自培训资料
- 控件学习---UIActivityIndicatorView---摘自培训资料
- 控件学习---UIPageControl---摘自培训资料
- 第十三周项目三——是否二叉排序树?
- C语言指针入门(一)
- python基本数值类型简介
- Java 总结 1125/1126
- JDK不同操作系统的FileSystem(Windows)下篇
- kwic学习,摘自网络
- Nodejs —— HTTP请求方法:get,head,put,delete,post
- cuda编程指南
- Matlab中利用findpeaks找波峰和波谷
- Leetcode 27. Remove Element
- 面试
- cpp: 利息与复利的追赶
- GoogleMap离线API绘制折线问题
- 利用C语言内存管理模拟实验