一、实验目的
1.理解不同体系结构风格的具体内涵。
2.学习体系结构风格的具体实践。
二、实验环境
硬件: (依据具体情况填写)
软件:Java或任何一种自己熟悉的语言
三、实验内容
“上下文关键字”KWIC(Key Word in Context,文本中的关键字)检索系统接受有序的行集合:每一行是单词的有序集合;每一个单词又是字母的有序集合。通过重复地删除航中第一个单词,并把它插入行尾,每一行可以被“循环地移动”。KWIC检索系统以字母表的顺序输出一个所有行循环移动的列表。
尝试用不同的策略实现这个系统。选择2-3种体系结构风格来实现。
四、实验步骤:
采用管道过滤器风格
1、体系结构图:

2、简述体系结构各部件的主要功能,实现思想。
上述的主程序/子程序的方法,将问题分解为输入(input)、排序(shifter)、循环移动和按字母表排序输出(pcOutput)、输出(output)。
3、写出主要的代码:
//变量
char data = [];
char all = [];
int index = 0;
temp = null;
//输入函数
public String input()
{
String data;
while(1){
string = trim(fgets(STDIN));
//按ctrl+p 结束输入
if(16 === ord(string)){
break;
}
array_push(data,string);
}
return;
}
//迭代函数
function void shifter()
{
String data;
int index;
while(index<count(data)){
tempArr = explode(' ',data[index]);
count = count(tempArr);
temp implode(' ',tempArr)."\n";
for(i=0;i<count-1;++i){
shift = array_shift(tempArr);
array_push(tempArr,shift);
temp implode(' ',tempArr)."\n";
}
index+=1;
}
}
//循环输出
function pcOutput()
{
String emp;
collector = [];
foreach(temp as k=>v){
array_push(collector,v);
echo v;
}
return collector;
}
//排序
function alphabetizer()
{
//使用全局变量
String all;
//排序
return natcasesort(all);
}
/**
* 排序输出
**/
function void output()
{
String all;
foreach(all as v)
{
print(v);
}
}
/**
*
* 主函数
*
**/
function main()
{
String temp;
String all;
print("----------input---------\n");
input();
temp = shifter();
print("\n---------process--------\n");
all = pcOutput();
alphabetizer();
//输出
print("\n----------output---------\n");
output();
}
main();
显示结果:

浙公网安备 33010602011771号