1.词典树分段,表示词典树的一个分枝?啥是词典树?
package com.huaban.analysis.jieba;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
上面是引用!
class DictSegment implements Comparable<DictSegment>
这个类实现了一个接口:Comparable
讲解:https://www.cnblogs.com/walter371/p/5197511.html
讲解:https://blog.csdn.net/weixin_43505709/article/details/87908756
不知道这个接口是干啥的!
// 公用字典表,存储汉字
private static final Map<Character, Character> charMap = new HashMap<Character, Character>(16, 0.95f);
// 数组大小上限
private static final int ARRAY_LENGTH_LIMIT = 3;
// Map存储结构
private Map<Character, DictSegment> childrenMap;
// 数组方式存储结构
private DictSegment[] childrenArray;
// 当前节点上存储的字符
private Character nodeChar;
// 当前节点存储的Segment数目storeSize <=ARRAY_LENGTH_LIMIT ,使用数组存储, storeSize >ARRAY_LENGTH_LIMIT,则使用Map存储
private int storeSize = 0;
// 当前DictSegment状态 ,默认 0 , 1表示从根节点到当前节点的路径表示一个词
private int nodeState = 0;
上面都是提前定义好的参数!这个java基础要很好才行!我步行!!
DictSegment(Character nodeChar) {
if (nodeChar == null) {
throw new IllegalArgumentException("参数为空异常,字符不能为空");
}
this.nodeChar = nodeChar;
}
Character getNodeChar() {
return nodeChar;
}
这个首先要提取nodeChar!
boolean hasNextNode() {
return this.storeSize > 0;
}
判断是否有下一个节点!
Hit match(char[] charArray) {
return this.match(charArray, 0, charArray.length, null);
}
Hit match(char[] charArray, int begin, int length) {