2024年6月11日发(作者:)

文本索引的建立

在实际的信息检索过程中,如何对所需要的文档建立索引是一个很重要的问

题,一个好的索引建立可以很方便的定位到需要的文档,快速的缩短了索引文件

所需要的时间。

如下图所示:

为记事本中的每条图书信息建立索引,通过关键词来作为索引项,书号作为

索引的内容,算法流程如下;

提提提提提提提提提提提提提提提提

提提提提提提

提提提

提提提提提

提提提提提

提提提提

最后的程序输入如下图所示:

源程序

/**

* created by Jimmy

* all right reserved

* @date Marth 9th,2012

*/

package ;

import .*;

import .*;

/**

* The class used to index a file

* @author Jimmy

*

*/

public class IndexToFile {

/*

* used to indicate which file need to indexed

*/

private File file=new

File(perty("")+"/src/edu/zhang/index/

t");

/*

* show which word is defined to be stop word

*/

private String stopWord="to The and of";

/*

* used to store the information of the file

*/

private LinkedListlist_readFromFile=new

LinkedList();

/*

* used to store the meta keyword in the file

*/

private TreeSet treeset=new TreeSet();

/*

* construct method

*/

public IndexToFile()throws Exception{

}

/*

* create index and write the index to the given file

*/

public void createIndexToFile()throws Exception{

//索引内容写入文件

BufferedWriter bufferWriter=new BufferedWriter(new

/*

* read the context from the file

*/

BufferedReader bufferReader=new BufferedReader(new

String string="";

while((string=ne())!=null){

list_(string);

//将句子拆分成短语

String []string_buffer=("s");

//第一个短语是标识,所以不用存储

for(int i=1;i

if(!ns(string_buffer[i])){

(string_buffer[i]);

}//if

FileReader(file));

}//for

}//while

();

FileWriter(perty("")+"/src/edu/zhang/index/BookI

"));

for(String string:treeset){

//存储索引的书页号

StringBuilder stringBuilder=new StringBuilder();

for(int i=0;i

if(list_(i).contains(string)){

//第一个位置存储的是书页号

(list_(i).split("s")[0]+"t

");

}

(rCase()+"t"+stringBuilder);

}

public static void main(String[] args)throws Exception {

}

IndexToFile indexForFile=new IndexToFile();

IndexToFile();

n("Index for a file has succeed!");

}

//刷新缓冲区

();

e();

}

}