public class AhoCorasickDoubleArrayTrie<V> extends Object implements Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
AhoCorasickDoubleArrayTrie.Hit<V>
A result output
|
static interface |
AhoCorasickDoubleArrayTrie.IHit<V>
Processor handles the output when hit a keyword
|
static interface |
AhoCorasickDoubleArrayTrie.IHitCancellable<V>
Callback that allows to cancel the search process.
|
static interface |
AhoCorasickDoubleArrayTrie.IHitFull<V>
Processor handles the output when hit a keyword, with more detail
|
| Modifier and Type | Field and Description |
|---|---|
protected int[] |
base
base array of the Double Array Trie structure
|
protected int[] |
check
check array of the Double Array Trie structure
|
protected int[] |
fail
fail table of the Aho Corasick automata
|
protected int[] |
l
the length of every key
|
protected int[][] |
output
output table of the Aho Corasick automata
|
protected int |
size
the size of base and check array
|
protected V[] |
v
outer value array
|
| Constructor and Description |
|---|
AhoCorasickDoubleArrayTrie() |
| Modifier and Type | Method and Description |
|---|---|
void |
build(Map<String,V> map)
Build a AhoCorasickDoubleArrayTrie from a map
|
int |
exactMatchSearch(String key)
match exactly by a key
|
AhoCorasickDoubleArrayTrie.Hit<V> |
findFirst(String text)
Search first match in string
|
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 |
V |
get(String key)
Get value by a String key, just like a map.get() method
|
void |
load(ObjectInputStream in)
Load data from [ObjectInputStream]
|
boolean |
matches(String text)
Checks that string contains at least one substring
|
void |
parseText(char[] text,
AhoCorasickDoubleArrayTrie.IHit<V> processor)
Parse text
|
void |
parseText(char[] text,
AhoCorasickDoubleArrayTrie.IHitFull<V> processor)
Parse text
|
List<AhoCorasickDoubleArrayTrie.Hit<V>> |
parseText(CharSequence text)
Parse text
|
void |
parseText(CharSequence text,
AhoCorasickDoubleArrayTrie.IHit<V> processor)
Parse text
|
void |
parseText(CharSequence text,
AhoCorasickDoubleArrayTrie.IHitCancellable<V> processor)
Parse text
|
void |
save(ObjectOutputStream out)
Save
|
boolean |
set(String key,
V value)
Update a value corresponding to a key
|
int |
size() |
protected int |
transition(int current,
char c)
transition of a state
|
protected int |
transitionWithRoot(int nodePos,
char c)
transition of a state, if the state is root and it failed, then returns the root
|
protected int[] check
protected int[] base
protected int[] fail
protected int[][] output
protected V[] v
protected int[] l
protected int size
public List<AhoCorasickDoubleArrayTrie.Hit<V>> parseText(CharSequence text)
text - The textpublic void parseText(CharSequence text, AhoCorasickDoubleArrayTrie.IHit<V> processor)
text - The textprocessor - A processor which handles the outputpublic void parseText(CharSequence text, AhoCorasickDoubleArrayTrie.IHitCancellable<V> processor)
text - The textprocessor - A processor which handles the outputpublic void parseText(char[] text,
AhoCorasickDoubleArrayTrie.IHit<V> processor)
text - The textprocessor - A processor which handles the outputpublic void parseText(char[] text,
AhoCorasickDoubleArrayTrie.IHitFull<V> processor)
text - The textprocessor - A processor which handles the outputpublic boolean matches(String text)
text - source text to checktrue if string contains at least one substringpublic AhoCorasickDoubleArrayTrie.Hit<V> findFirst(String text)
text - source text to checknull if there are no matchespublic void save(ObjectOutputStream out) throws IOException
out - An ObjectOutputStream objectIOException - Some IOExceptionpublic void load(ObjectInputStream in) throws IOException, ClassNotFoundException
in - An ObjectInputStream objectIOException - If can't read the file from pathClassNotFoundException - If the class doesn't exist or matchedpublic V get(String key)
key - The keypublic boolean set(String key, V value)
key - the keyvalue - the valuepublic V get(int index)
index - The indexprotected int transition(int current,
char c)
current - c - protected int transitionWithRoot(int nodePos,
char c)
nodePos - c - public void build(Map<String,V> map)
map - a map containing key-value pairspublic int exactMatchSearch(String key)
key - the keypublic int size()
Copyright © 2014–2021 码农场. All rights reserved.