|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.hankcs.hanlp.collection.trie.DoubleArrayTrie<V>
public class DoubleArrayTrie<V>
双数组Trie树
| 嵌套类摘要 | |
|---|---|
class |
DoubleArrayTrie.Searcher
一个搜索工具(注意,当调用next()返回false后不应该继续调用next(),除非reset状态) |
| 字段摘要 | |
|---|---|
protected int[] |
base
|
protected int[] |
check
|
protected int |
size
base 和 check 的大小 |
protected V[] |
v
|
| 构造方法摘要 | |
|---|---|
DoubleArrayTrie()
|
|
| 方法摘要 | ||
|---|---|---|
int |
build(List<String> _key,
int[] _length,
int[] _value,
int _keySize)
唯一的构建方法 |
|
int |
build(List<String> key,
List<V> value)
|
|
int |
build(List<String> key,
V[] value)
|
|
int |
build(Set<Map.Entry<String,V>> entrySet)
构建DAT |
|
int |
build(TreeMap<String,V> keyValueMap)
方便地构造一个双数组trie树 |
|
List<Integer> |
commonPrefixSearch(String key)
|
|
List<Integer> |
commonPrefixSearch(String key,
int pos,
int len,
int nodePos)
前缀查询 |
|
LinkedList<Map.Entry<String,V>> |
commonPrefixSearchWithValue(char[] keyChars,
int begin)
优化的前缀查询,可以复用字符数组 |
|
LinkedList<Map.Entry<String,V>> |
commonPrefixSearchWithValue(String key)
已过时。 最好用优化版的 |
|
boolean |
containsKey(String key)
|
|
int |
exactMatchSearch(char[] keyChars,
int pos,
int len,
int nodePos)
精确查询 |
|
int |
exactMatchSearch(String key)
精确匹配 |
|
int |
exactMatchSearch(String key,
int pos,
int len,
int nodePos)
|
|
V |
get(char[] key)
|
|
V |
get(int index)
从值数组中提取下标为index的值 注意为了效率,此处不进行参数校验 |
|
V |
get(String key)
精确查询 |
|
int[] |
getBase()
获取base数组引用,不要修改base |
|
int[] |
getCheck()
获取check数组引用,不要修改check |
|
int |
getNonzeroSize()
|
|
DoubleArrayTrie.Searcher |
getSearcher(char[] text,
int offset)
|
|
DoubleArrayTrie.Searcher |
getSearcher(String text,
int offset)
|
|
int |
getSize()
|
|
int |
getTotalSize()
|
|
int |
getUnitSize()
|
|
V[] |
getValueArray(V[] a)
|
|
V |
getValueAt(int index)
获取index对应的值 |
|
boolean |
load(ByteArray byteArray,
V[] value)
|
|
boolean |
load(String path)
载入双数组,但是不提供值,此时本trie相当于一个set |
|
boolean |
load(String path,
List<V> value)
从磁盘加载,需要额外提供值 |
|
boolean |
load(String path,
V[] value)
从磁盘加载,需要额外提供值 |
|
void |
open(String fileName)
|
|
V |
output(int state)
检查状态是否对应输出 |
|
boolean |
save(DataOutputStream out)
将base和check保存下来 |
|
void |
save(ObjectOutputStream out)
|
|
boolean |
save(String fileName)
|
|
boolean |
serializeTo(String path)
将自己序列化到 |
|
boolean |
set(String key,
V value)
更新某个键对应的值 |
|
int |
size()
树叶子节点个数 |
|
String |
toString()
|
|
protected int |
transition(char[] path)
沿着节点转移状态 |
|
int |
transition(char c,
int from)
转移状态 |
|
protected int |
transition(int current,
char c)
转移状态 |
|
protected int |
transition(String path)
沿着路径转移状态 |
|
int |
transition(String path,
int from)
沿着路径转移状态 |
|
static
|
unSerialize(String path)
|
|
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 字段详细信息 |
|---|
protected int[] check
protected int[] base
protected int size
protected V[] v
| 构造方法详细信息 |
|---|
public DoubleArrayTrie()
| 方法详细信息 |
|---|
public int getUnitSize()
public int getSize()
public int getTotalSize()
public int getNonzeroSize()
public int build(List<String> key,
List<V> value)
public int build(List<String> key,
V[] value)
public int build(Set<Map.Entry<String,V>> entrySet)
entrySet - 注意此entrySet一定要是字典序的!否则会失败
public int build(TreeMap<String,V> keyValueMap)
ITrie<V> 中的 buildkeyValueMap - 升序键值对map
public int build(List<String> _key,
int[] _length,
int[] _value,
int _keySize)
_key - 值set,必须字典序_length - 对应每个key的长度,留空动态获取_value - 每个key对应的值,留空使用key的下标作为值_keySize - key的长度,应该设为_key.size
public void open(String fileName)
throws IOException
IOExceptionpublic boolean save(String fileName)
public boolean save(DataOutputStream out)
ITrie<V> 中的 saveout -
public void save(ObjectOutputStream out)
throws IOException
IOException
public boolean load(String path,
List<V> value)
path - value -
public boolean load(String path,
V[] value)
path - value -
public boolean load(ByteArray byteArray,
V[] value)
ITrie<V> 中的 loadpublic boolean load(String path)
path -
public boolean serializeTo(String path)
path -
public static <T> DoubleArrayTrie<T> unSerialize(String path)
public int exactMatchSearch(String key)
key - 键
public int exactMatchSearch(String key,
int pos,
int len,
int nodePos)
public int exactMatchSearch(char[] keyChars,
int pos,
int len,
int nodePos)
keyChars - 键的char数组pos - char数组的起始位置len - 键的长度nodePos - 开始查找的位置(本参数允许从非根节点查询)
public List<Integer> commonPrefixSearch(String key)
public List<Integer> commonPrefixSearch(String key,
int pos,
int len,
int nodePos)
key - 查询字串pos - 字串的开始位置len - 字串长度nodePos - base中的开始位置
public LinkedList<Map.Entry<String,V>> commonPrefixSearchWithValue(String key)
key - 键
public LinkedList<Map.Entry<String,V>> commonPrefixSearchWithValue(char[] keyChars,
int begin)
keyChars - begin -
public String toString()
Object 中的 toStringpublic int size()
ITrie<V> 中的 sizepublic int[] getCheck()
public int[] getBase()
public V getValueAt(int index)
index -
public V get(String key)
ITrie<V> 中的 getkey - 键
public V get(char[] key)
ITrie<V> 中的 getpublic V[] getValueArray(V[] a)
ITrie<V> 中的 getValueArraypublic boolean containsKey(String key)
ITrie<V> 中的 containsKeyprotected int transition(String path)
path -
protected int transition(char[] path)
path -
public int transition(String path,
int from)
path - 路径from - 起点(根起点为base[0]=1)
public int transition(char c,
int from)
c - from -
public V output(int state)
state - 双数组下标
public DoubleArrayTrie.Searcher getSearcher(String text,
int offset)
public DoubleArrayTrie.Searcher getSearcher(char[] text,
int offset)
protected int transition(int current,
char c)
current - c -
public boolean set(String key,
V value)
key - 键value - 值
public V get(int index)
index - 下标
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||