软件体系结构上机实验 面向对象体系结构风格的 KWIC 关键词索引系统设计与实现 java
来源:互联网 发布:室内设计 知乎 编辑:程序博客网 时间:2024/04/29 20:52
java 源代码
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class KWIC
{
private static BufferedReader input_file;//输入缓冲对象
private static BufferedWriter output_file;//输出缓冲对象
private ArrayList<String> kwicList;
public KWIC (String filename)
{
kwicList = new ArrayList<String>();
String line="";
fileopen(filename);//打开文件
while (line!= null)
{
line=readline();//每行读取文件
if (line !=null)//每行不空
{
parseLine(line, kwicList);//每行移位
}
}
sort(kwicList);//排序
writeToFile(kwicList,"output.txt");//结果写入文件
}
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 void sort(ArrayList<String> List)//排序函数
{
for(int i=List.size()-1;i>0;i--)
{
for(int j=0;j<i;j++)
{
char a=List.get(j).charAt(0);
char b=List.get(j+1).charAt(0);
if(a>b)
{
String temp=List.get(j);
List.remove(j);
List.add(j+1,temp);
}
}
}
}
/*public static void display(ArrayList<String> List)//输出结果函数
{
for (int count=0; count< List.size();count++) {
System.out.println (List.get(count) );//每行输出
}
}
*/
public void writeToFile(ArrayList<String> List,String filename) {
try {
output_file= new BufferedWriter(new FileWriter(filename));
for (int count=0; count< List.size();count++)
{
output_file.write(List.get(count) );//每行写入文件
output_file.newLine();//读取下一行
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
try {
if (output_file != null)
{
output_file.flush();
output_file.close();//关闭文件
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}
public static void main(String[] args) //主程序
{
new KWIC("input.txt");
}
}
- 软件体系结构上机实验 面向对象体系结构风格的 KWIC 关键词索引系统设计与实现 java
- 软件系统设计与体系结构
- 软件体系结构设计|描述与架构风格
- 软件体系结构的风格
- 软件体系结构的风格
- 谈论软件体系结构的风格
- 软件体系结构的设计与实现鱼骨图
- 全面面向对象体系结构设计
- 面向对象设计——系统体系结构建模
- 软件体系结构风格
- 软件体系结构风格
- 软件体系结构风格
- 软件体系结构风格
- 软件体系结构风格
- 面向模式的软件体系结构+卷1_4(设计模式与惯用法)
- 面向模式的软件体系结构卷1模式系统
- 体系结构设计风格
- java软件体系结构设计模式-------对象缓存器
- Handoff
- Eclipse DDMS中无法查看/data目录
- 攻略个人门户,正在崛起的聚合门户
- Android之bitmap的镜像3D翻转(绕x轴 Y轴)
- POJ水题1007DNA Sorting
- 软件体系结构上机实验 面向对象体系结构风格的 KWIC 关键词索引系统设计与实现 java
- Linux Firewall (firewalld, firewall-cmd, firewall-config)(Fedora19及以后版本用的防火墙)
- Test
- Git学习笔记与IntelliJ IDEA整合 - MrJun
- HTML5与CSS3权威指南(未完待整理)
- 杭电2523(桶排序)
- WKWebView(同事遇到的坑mark下)
- android ant多渠道混淆打包
- 2015年人力资源管理十大新趋势