小曹谈技术之索引&词典结构

来源:互联网 发布:mac 读取exe 编辑:程序博客网 时间:2024/04/30 09:42

基于散列表的索引结构,全匹配

速度快,实现简单,但是不支持部分匹配。

基于前缀树,后缀树的索引结构,部分匹配


一个前缀树(Prefix tree)的实现

http://whiteboxcomputing.com/java/prefix_tree/

In addition to the efficiency, triealso provides flexibility in searching for the closest path in case that thekey is misspelled. For example, by skipping a certain character in the keywhile walking, we can fix the insertion kind of typo. By walking toward all theimmediate children of one node without consuming a character from the key, wecan fix the deletion typo, or even substitution typo if we just drop the keycharacter that has no branch to go and descend to all the immediate children ofthe current node.

一个双Trie树的实现,datrie

http://linux.thai.net/~thep/datrie/datrie.html

Static Double Array Trie (DASTrie):Windows平台可用!

http://www.chokkan.org/software/dastrie/

 

后缀树

http://www.allisons.org/ll/AlgDS/Tree/Suffix/

可以用来高效地解决求多个字串的最大公共字串,一个字串的最大重复字串等问题。

与前缀树不同,前缀树是预先对待匹配的模式进行处理,建立前缀树。而后缀树是对待处理的文本进行处理!对待处理的文本建立后缀树。

后缀树快速构建算法

http://www.blogjava.net/Files/zellux/SuffixT1withFigs.rar

后缀树的实现:

http://sfxdisk.dead-inside.org/

http://mila.cs.technion.ac.il/~yona/suffix_tree/

 

倒排索引(Inverted Index)

倒排索引是支持快速找到词(一个词或者多个词)在哪些文件出现过的一种索引结构。Lucene实现的就是倒排索引。

http://lucene.apache.org/

 

索引的压缩(Compression)

当索引太大了时,需要进行索引的压缩。

常用的压缩方法:

文本压缩: Huffman编码

前缀压缩:Prefix compression,将没有分支的一条路径上的所有顺序节点合并为一个节点。

Suffix Compression

[Aoe1989] alsosuggested a storage compression strategy, by splitting non-branching suffixesinto single string storages, calledtail, so that the restnon-branching steps are reduced into mere string comparison.

With the two separate data structures,double-array branches and suffix-spool tail, key insertion and deletionalgorithms must be modified accordingly.

倒排索引的压缩:

相关论文

Inverted Index Algorithm and Compression Inverted Index

 Inverted Index Compression Using Word-Aligned Binary Codes

InvertedIndex Compression and Query Processing with Optimized Document Ordering

 

索引的清理(Prune)

在大规模数据检索时,当索引太大时,内存中放不下,有必要对索引中的内容进行清理,去掉无用的或者不重要的部分。例如,有些文档,不管怎么检索,都不会被检索结果列出来。

另外,还有一些垃圾网页、作弊网页等,为了提高索引的质量,提升索引检索的性能,提高检索结果的质量,都有必要对建立的索引进行清理工作。

静态索引清理Static Index Pruning

Static Index Pruning for Information Retrieval Systems

http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=C64771EDA9815C9C34D59DBD5358D32E?doi=10.1.1.58.8759&rep=rep1&type=pdf

Entropy-BasedStatic Index Pruning

 http://www.springerlink.com/index/20519nq3141n4x33.pdf

 

动态索引清理 Dynamic Index Pruning

Dynamic indexpruning for effective caching

http://portal.acm.org/citation.cfm?id=1321592

 

vs.数组

在前面介绍了前缀树和后缀树,实际在实现中,前缀数组和后缀数组会更加实用。而且相比于树,数组会占用的空间更小一些。编程实现更简单一些。用数组的话,查找指定的子节点很快,只要 O(1);但是比较费空间。用链表的话,省空间,但是查找子节点比较慢,只能线性地查找。

用倍增算法构造后缀数组,O(n log n)

http://imlazy.ycool.com/post.2011825.html

后缀树和后缀数组

http://imlazy.ycool.com/post.2011818.html

实际上,后缀树就是这种形式:

 


后缀数组是这种形式:

T11 = i

T8 = ippi

T5 = issippi

T2 = ississippi

T1 = mississippi

T10 = pi

T9 = ppi

T7 = sippi

T4 = sissippi

T6 = ssippi

T3 = ssissippi

 


多模式匹配

AC算法

http://www.cppblog.com/mythit/archive/2009/04/21/80633.html

自动机理论建立一个Trie数,然后加入类似于KMP的前进数组,这里是fail状态转移,加快多模式匹配的速度。

 

 


下面转载一篇百度技术blog上写的多模式匹配的文章:

(一下没找到,等找到后再帖上来-_-!)

 


to be continued

 

原创粉丝点击