软件体系结构的第3次实验(软件体系结构风格之应用)
一、实验目的
1.理解不同体系结构风格的具体内涵。
2.学习体系结构风格的具体实践。
二、实验环境
硬件: (依据具体情况填写)
软件:Java或任何一种自己熟悉的语言
三、实验内容
“上下文关键字”KWIC(Key Word in Context,文本中的关键字)检索系统接受有序的行集合:每一行是单词的有序集合;每一个单词又是字母的有序集合。通过重复地删除航中第一个单词,并把它插入行尾,每一行可以被“循环地移动”。KWIC检索系统以字母表的顺序输出一个所有行循环移动的列表。
四、实验步骤:
1、体系结构图:
2、简述体系结构各部件的主要功能,实现思想。
上述的主程序/子程序的方法,将问题分解为输入(Input)、移动(Shifter)、按字母表排序(Alphabetizer)、输出(Output)。
Input : 主函数调用该方法,读取数据,输出到控制台。
Shifter : 主函数调用该方法,实现移位。
Alphabetizer : 主函数调用该方法,对行数据进行按字母顺序排序
Output : 主函数调用该方法,输出到控制台
3、写出主要的代码
package com.newland.bomc.zy;
/**
* Created by hasee on 2017/11/19.
*/
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 KWIC {
private static BufferedReader input_file;
private ArrayList<String> kwicList;
public static void main(String[] args) {
new KWIC("E://kwic.txt");
}
public KWIC (String filename)
{
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) );
}
}
}