类 AhoCorasickDoubleArrayTrie<V>
- java.lang.Object
-
- com.github.myibu.algorithm.filter.doublearray.AhoCorasickDoubleArrayTrie<V>
-
- 所有已实现的接口:
java.io.Serializable
public class AhoCorasickDoubleArrayTrie<V> extends java.lang.Object implements java.io.SerializableAn implementation of Aho Corasick algorithm based on Double Array Trie- 另请参阅:
- 序列化表格
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classAhoCorasickDoubleArrayTrie.Hit<V>A result outputstatic interfaceAhoCorasickDoubleArrayTrie.IHit<V>Processor handles the output when hit a keywordstatic interfaceAhoCorasickDoubleArrayTrie.IHitCancellable<V>Callback that allows to cancel the search process.static interfaceAhoCorasickDoubleArrayTrie.IHitFull<V>Processor handles the output when hit a keyword, with more detail
-
字段概要
字段 修饰符和类型 字段 说明 protected int[]basebase array of the Double Array Trie structureprotected int[]checkcheck array of the Double Array Trie structureprotected int[]failfail table of the Aho Corasick automataprotected int[]lthe length of every keyprotected int[][]outputoutput table of the Aho Corasick automataprotected intsizethe size of base and check arrayprotected V[]vouter value array
-
构造器概要
构造器 构造器 说明 AhoCorasickDoubleArrayTrie()
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidbuild(java.util.Map<java.lang.String,V> map)Build a AhoCorasickDoubleArrayTrie from a mapintexactMatchSearch(java.lang.String key)match exactly by a keyAhoCorasickDoubleArrayTrie.Hit<V>findFirst(java.lang.String text)Search first match in stringVget(int index)Pick the value by index in value array
Notice that to be more efficiently, this method DO NOT check the parameterVget(java.lang.String key)Get value by a String key, just like a map.get() methodvoidload(java.io.ObjectInputStream in)Load data from [ObjectInputStream]booleanmatches(java.lang.String text)Checks that string contains at least one substringvoidparseText(char[] text, AhoCorasickDoubleArrayTrie.IHit<V> processor)Parse textvoidparseText(char[] text, AhoCorasickDoubleArrayTrie.IHitFull<V> processor)Parse textjava.util.List<AhoCorasickDoubleArrayTrie.Hit<V>>parseText(java.lang.CharSequence text)Parse textvoidparseText(java.lang.CharSequence text, AhoCorasickDoubleArrayTrie.IHit<V> processor)Parse textvoidparseText(java.lang.CharSequence text, AhoCorasickDoubleArrayTrie.IHitCancellable<V> processor)Parse textvoidsave(java.io.ObjectOutputStream out)Savebooleanset(java.lang.String key, V value)Update a value corresponding to a keyintsize()protected inttransition(int current, char c)transition of a stateprotected inttransitionWithRoot(int nodePos, char c)transition of a state, if the state is root and it failed, then returns the root
-
-
-
字段详细资料
-
check
protected int[] check
check array of the Double Array Trie structure
-
base
protected int[] base
base array of the Double Array Trie structure
-
fail
protected int[] fail
fail table of the Aho Corasick automata
-
output
protected int[][] output
output table of the Aho Corasick automata
-
v
protected V[] v
outer value array
-
l
protected int[] l
the length of every key
-
size
protected int size
the size of base and check array
-
-
方法详细资料
-
parseText
public java.util.List<AhoCorasickDoubleArrayTrie.Hit<V>> parseText(java.lang.CharSequence text)
Parse text- 参数:
text- The text- 返回:
- a list of outputs
-
parseText
public void parseText(java.lang.CharSequence text, AhoCorasickDoubleArrayTrie.IHit<V> processor)Parse text- 参数:
text- The textprocessor- A processor which handles the output
-
parseText
public void parseText(java.lang.CharSequence text, AhoCorasickDoubleArrayTrie.IHitCancellable<V> processor)Parse text- 参数:
text- The textprocessor- A processor which handles the output
-
parseText
public void parseText(char[] text, AhoCorasickDoubleArrayTrie.IHit<V> processor)Parse text- 参数:
text- The textprocessor- A processor which handles the output
-
parseText
public void parseText(char[] text, AhoCorasickDoubleArrayTrie.IHitFull<V> processor)Parse text- 参数:
text- The textprocessor- A processor which handles the output
-
matches
public boolean matches(java.lang.String text)
Checks that string contains at least one substring- 参数:
text- source text to check- 返回:
trueif string contains at least one substring
-
findFirst
public AhoCorasickDoubleArrayTrie.Hit<V> findFirst(java.lang.String text)
Search first match in string- 参数:
text- source text to check- 返回:
- first match or
nullif there are no matches
-
save
public void save(java.io.ObjectOutputStream out) throws java.io.IOExceptionSave- 参数:
out- An ObjectOutputStream object- 抛出:
java.io.IOException- Some IOException
-
load
public void load(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundExceptionLoad data from [ObjectInputStream]- 参数:
in- An ObjectInputStream object- 抛出:
java.io.IOException- If can't read the file from pathjava.lang.ClassNotFoundException- If the class doesn't exist or matched
-
get
public V get(java.lang.String key)
Get value by a String key, just like a map.get() method- 参数:
key- The key- 返回:
- value if exist otherwise it return null
-
set
public boolean set(java.lang.String key, V value)Update a value corresponding to a key- 参数:
key- the keyvalue- the value- 返回:
- successful or not(failure if there is no key)
-
get
public V get(int index)
Pick the value by index in value array
Notice that to be more efficiently, this method DO NOT check the parameter- 参数:
index- The index- 返回:
- The value
-
transition
protected int transition(int current, char c)transition of a state- 参数:
current- currentc- c- 返回:
- int
-
transitionWithRoot
protected int transitionWithRoot(int nodePos, char c)transition of a state, if the state is root and it failed, then returns the root- 参数:
nodePos- nodePosc- c- 返回:
- int
-
build
public void build(java.util.Map<java.lang.String,V> map)
Build a AhoCorasickDoubleArrayTrie from a map- 参数:
map- a map containing key-value pairs
-
exactMatchSearch
public int exactMatchSearch(java.lang.String key)
match exactly by a key- 参数:
key- the key- 返回:
- the index of the key, you can use it as a perfect hash function
-
size
public int size()
- 返回:
- the size of the keywords
-
-