com.hankcs.hanlp.collection.AhoCorasick
类 AhoCorasickDoubleArrayTrie<V>

java.lang.Object
  继承者 com.hankcs.hanlp.collection.AhoCorasick.AhoCorasickDoubleArrayTrie<V>

public class AhoCorasickDoubleArrayTrie<V>
extends Object

基于双数组Trie树的AhoCorasick自动机

作者:
hankcs

嵌套类摘要
 class AhoCorasickDoubleArrayTrie.Hit<V>
          一个命中结果
static interface AhoCorasickDoubleArrayTrie.IHit<V>
          命中一个模式串的处理方法
static interface AhoCorasickDoubleArrayTrie.IHitFull<V>
           
 
字段摘要
protected  int[] base
          双数组之base
protected  int[] check
          双数组值check
protected  int[] l
          每个key的长度
protected  int size
          base 和 check 的大小
protected  V[] v
          保存value
 
构造方法摘要
AhoCorasickDoubleArrayTrie()
           
 
方法摘要
 void build(TreeMap<String,V> map)
          由一个排序好的map创建
 int exactMatchSearch(String key)
          精确匹配
 V get(int index)
          从值数组中提取下标为index的值
注意为了效率,此处不进行参数校验
 V get(String key)
          获取值
 boolean load(ByteArray byteArray, V[] value)
          载入
 void load(ObjectInputStream in, V[] value)
          载入
 void parseText(char[] text, AhoCorasickDoubleArrayTrie.IHit<V> processor)
          处理文本
 void parseText(char[] text, AhoCorasickDoubleArrayTrie.IHitFull<V> processor)
          处理文本
 List<AhoCorasickDoubleArrayTrie.Hit<V>> parseText(String text)
          匹配母文本
 void parseText(String text, AhoCorasickDoubleArrayTrie.IHit<V> processor)
          处理文本
 void save(DataOutputStream out)
          持久化
 void save(ObjectOutputStream out)
          持久化
 boolean set(String key, V value)
          更新某个键对应的值
 int size()
          大小,即包含多少个模式串
protected  int transition(int current, char c)
          转移状态
protected  int transitionWithRoot(int nodePos, char c)
          c转移,如果是根节点则返回自己
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

check

protected int[] check
双数组值check


base

protected int[] base
双数组之base


v

protected V[] v
保存value


l

protected int[] l
每个key的长度


size

protected int size
base 和 check 的大小

构造方法详细信息

AhoCorasickDoubleArrayTrie

public AhoCorasickDoubleArrayTrie()
方法详细信息

parseText

public List<AhoCorasickDoubleArrayTrie.Hit<V>> parseText(String text)
匹配母文本

参数:
text - 一些文本
返回:
一个pair列表

parseText

public void parseText(String text,
                      AhoCorasickDoubleArrayTrie.IHit<V> processor)
处理文本

参数:
text - 文本
processor - 处理器

parseText

public void parseText(char[] text,
                      AhoCorasickDoubleArrayTrie.IHit<V> processor)
处理文本

参数:
text -
processor -

parseText

public void parseText(char[] text,
                      AhoCorasickDoubleArrayTrie.IHitFull<V> processor)
处理文本

参数:
text -
processor -

save

public void save(DataOutputStream out)
          throws Exception
持久化

参数:
out - 一个DataOutputStream
抛出:
Exception - 可能的IO异常等

save

public void save(ObjectOutputStream out)
          throws IOException
持久化

参数:
out - 一个ObjectOutputStream
抛出:
IOException - 可能的IO异常

load

public void load(ObjectInputStream in,
                 V[] value)
          throws IOException,
                 ClassNotFoundException
载入

参数:
in - 一个ObjectInputStream
value - 值(持久化的时候并没有持久化值,现在需要额外提供)
抛出:
IOException
ClassNotFoundException

load

public boolean load(ByteArray byteArray,
                    V[] value)
载入

参数:
byteArray - 一个字节数组
value - 值数组
返回:
成功与否

get

public V get(String key)
获取值

参数:
key - 键
返回:

set

public boolean set(String key,
                   V value)
更新某个键对应的值

参数:
key - 键
value - 值
返回:
是否成功(失败的原因是没有这个键)

get

public V get(int index)
从值数组中提取下标为index的值
注意为了效率,此处不进行参数校验

参数:
index - 下标
返回:

transition

protected int transition(int current,
                         char c)
转移状态

参数:
current -
c -
返回:

transitionWithRoot

protected int transitionWithRoot(int nodePos,
                                 char c)
c转移,如果是根节点则返回自己

参数:
nodePos -
c -
返回:

build

public void build(TreeMap<String,V> map)
由一个排序好的map创建


exactMatchSearch

public int exactMatchSearch(String key)
精确匹配

参数:
key - 键
返回:
值的下标

size

public int size()
大小,即包含多少个模式串

返回:


Copyright © 2014–2015 码农场. All rights reserved.