Compare commits
No commits in common. "master" and "v8.5.0" have entirely different histories.
@ -6,6 +6,7 @@ ik-analyzer for solr 7.x-8.x
|
||||
[](https://github.com/magese/ik-analyzer-solr/releases)
|
||||
[](./LICENSE)
|
||||
[](https://travis-ci.org/magese/ik-analyzer-solr)
|
||||
[](http://hits.dwyl.io/magese/ik-analyzer-solr)
|
||||
|
||||
[](https://github.com/magese/ik-analyzer-solr/network/members)
|
||||
[](https://github.com/magese/ik-analyzer-solr/stargazers)
|
||||
|
@ -76,7 +76,7 @@ public interface Configuration {
|
||||
*
|
||||
* @return String 量词词典路径
|
||||
*/
|
||||
String getQuantifierDictionary();
|
||||
String getQuantifierDicionary();
|
||||
|
||||
/**
|
||||
* 获取扩展字典配置路径
|
||||
|
@ -145,7 +145,7 @@ public class DefaultConfig implements Configuration {
|
||||
*
|
||||
* @return String 量词词典路径
|
||||
*/
|
||||
public String getQuantifierDictionary() {
|
||||
public String getQuantifierDicionary() {
|
||||
return PATH_DIC_QUANTIFIER;
|
||||
}
|
||||
|
||||
|
@ -27,12 +27,12 @@
|
||||
*/
|
||||
package org.wltea.analyzer.core;
|
||||
|
||||
import org.wltea.analyzer.dic.Dictionary;
|
||||
import org.wltea.analyzer.dic.Hit;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.wltea.analyzer.dic.Dictionary;
|
||||
import org.wltea.analyzer.dic.Hit;
|
||||
|
||||
|
||||
/**
|
||||
* 中文-日韩文子分词器
|
||||
@ -42,7 +42,7 @@ class CJKSegmenter implements ISegmenter {
|
||||
//子分词器标签
|
||||
private static final String SEGMENTER_NAME = "CJK_SEGMENTER";
|
||||
//待处理的分词hit队列
|
||||
private final List<Hit> tmpHits;
|
||||
private List<Hit> tmpHits;
|
||||
|
||||
|
||||
CJKSegmenter(){
|
||||
@ -80,19 +80,20 @@ class CJKSegmenter implements ISegmenter {
|
||||
//*********************************
|
||||
//再对当前指针位置的字符进行单字匹配
|
||||
Hit singleCharHit = Dictionary.getSingleton().matchInMainDict(context.getSegmentBuff(), context.getCursor(), 1);
|
||||
|
||||
// 首字为词前缀
|
||||
if (singleCharHit.isMatch()) {
|
||||
if(singleCharHit.isMatch()){//首字成词
|
||||
//输出当前的词
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , context.getCursor() , 1 , Lexeme.TYPE_CNWORD);
|
||||
context.addLexeme(newLexeme);
|
||||
}
|
||||
|
||||
// 前缀匹配则放入hit列表
|
||||
//同时也是词前缀
|
||||
if(singleCharHit.isPrefix()){
|
||||
//前缀匹配则放入hit列表
|
||||
this.tmpHits.add(singleCharHit);
|
||||
}
|
||||
}else if(singleCharHit.isPrefix()){//首字为词前缀
|
||||
//前缀匹配则放入hit列表
|
||||
this.tmpHits.add(singleCharHit);
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
|
@ -36,6 +36,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* 中文数量词子分词器
|
||||
*/
|
||||
class CN_QuantifierSegmenter implements ISegmenter{
|
||||
@ -43,14 +44,14 @@ class CN_QuantifierSegmenter implements ISegmenter {
|
||||
//子分词器标签
|
||||
private static final String SEGMENTER_NAME = "QUAN_SEGMENTER";
|
||||
|
||||
private static final Set<Character> CHN_NUMBER_CHARS = new HashSet<>();
|
||||
|
||||
private static Set<Character> ChnNumberChars = new HashSet<>();
|
||||
static{
|
||||
//中文数词
|
||||
//Cnum
|
||||
String chn_Num = "一二两三四五六七八九十零壹贰叁肆伍陆柒捌玖拾百千万亿拾佰仟萬億兆卅廿";
|
||||
char[] ca = chn_Num.toCharArray();
|
||||
for(char nChar : ca){
|
||||
CHN_NUMBER_CHARS.add(nChar);
|
||||
ChnNumberChars.add(nChar);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +68,7 @@ class CN_QuantifierSegmenter implements ISegmenter {
|
||||
private int nEnd;
|
||||
|
||||
//待处理的量词hit队列
|
||||
private final List<Hit> countHits;
|
||||
private List<Hit> countHits;
|
||||
|
||||
|
||||
CN_QuantifierSegmenter(){
|
||||
@ -110,14 +111,14 @@ class CN_QuantifierSegmenter implements ISegmenter {
|
||||
private void processCNumber(AnalyzeContext context){
|
||||
if(nStart == -1 && nEnd == -1){//初始状态
|
||||
if(CharacterUtil.CHAR_CHINESE == context.getCurrentCharType()
|
||||
&& CHN_NUMBER_CHARS.contains(context.getCurrentChar())) {
|
||||
&& ChnNumberChars.contains(context.getCurrentChar())){
|
||||
//记录数词的起始、结束位置
|
||||
nStart = context.getCursor();
|
||||
nEnd = context.getCursor();
|
||||
}
|
||||
}else{//正在处理状态
|
||||
if(CharacterUtil.CHAR_CHINESE == context.getCurrentCharType()
|
||||
&& CHN_NUMBER_CHARS.contains(context.getCurrentChar())) {
|
||||
&& ChnNumberChars.contains(context.getCurrentChar())){
|
||||
//记录数词的结束位置
|
||||
nEnd = context.getCursor();
|
||||
}else{
|
||||
@ -143,7 +144,6 @@ class CN_QuantifierSegmenter implements ISegmenter {
|
||||
|
||||
/**
|
||||
* 处理中文量词
|
||||
*
|
||||
* @param context 需要处理的内容
|
||||
*/
|
||||
private void processCount(AnalyzeContext context){
|
||||
@ -179,19 +179,21 @@ class CN_QuantifierSegmenter implements ISegmenter {
|
||||
//*********************************
|
||||
//对当前指针位置的字符进行单字匹配
|
||||
Hit singleCharHit = Dictionary.getSingleton().matchInQuantifierDict(context.getSegmentBuff(), context.getCursor(), 1);
|
||||
|
||||
// 首字为量词前缀
|
||||
if (singleCharHit.isMatch()) {
|
||||
if(singleCharHit.isMatch()){//首字成量词词
|
||||
//输出当前的词
|
||||
Lexeme newLexeme = new Lexeme(context.getBufferOffset() , context.getCursor() , 1 , Lexeme.TYPE_COUNT);
|
||||
context.addLexeme(newLexeme);
|
||||
}
|
||||
|
||||
// 前缀匹配则放入hit列表
|
||||
//同时也是词前缀
|
||||
if(singleCharHit.isPrefix()){
|
||||
//前缀匹配则放入hit列表
|
||||
this.countHits.add(singleCharHit);
|
||||
}
|
||||
}else if(singleCharHit.isPrefix()){//首字为量词前缀
|
||||
//前缀匹配则放入hit列表
|
||||
this.countHits.add(singleCharHit);
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
//输入的不是中文字符
|
||||
@ -227,7 +229,6 @@ class CN_QuantifierSegmenter implements ISegmenter {
|
||||
|
||||
/**
|
||||
* 添加数词词元到结果集
|
||||
*
|
||||
* @param context 需要添加的词元
|
||||
*/
|
||||
private void outputNumLexeme(AnalyzeContext context){
|
||||
|
@ -28,6 +28,7 @@
|
||||
package org.wltea.analyzer.core;
|
||||
|
||||
/**
|
||||
*
|
||||
* 字符集识别工具类
|
||||
*/
|
||||
class CharacterUtil {
|
||||
@ -45,7 +46,6 @@ class CharacterUtil {
|
||||
|
||||
/**
|
||||
* 识别字符类型
|
||||
*
|
||||
* @param input 需要识别的字符
|
||||
* @return int CharacterUtil定义的字符类型常量
|
||||
*/
|
||||
@ -85,7 +85,6 @@ class CharacterUtil {
|
||||
|
||||
/**
|
||||
* 进行字符规格化(全角转半角,大写转小写处理)
|
||||
*
|
||||
* @param input 需要转换的字符
|
||||
* @return char
|
||||
*/
|
||||
|
@ -35,7 +35,9 @@ import java.util.TreeSet;
|
||||
*/
|
||||
class IKArbitrator {
|
||||
|
||||
IKArbitrator() {}
|
||||
IKArbitrator() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分词歧义处理
|
||||
|
@ -41,25 +41,15 @@ import java.util.List;
|
||||
*/
|
||||
public final class IKSegmenter {
|
||||
|
||||
/**
|
||||
* 字符窜reader
|
||||
*/
|
||||
//字符窜reader
|
||||
private Reader input;
|
||||
/**
|
||||
* 分词器配置项
|
||||
*/
|
||||
private final Configuration cfg;
|
||||
/**
|
||||
* 分词器上下文
|
||||
*/
|
||||
//分词器配置项
|
||||
private Configuration cfg;
|
||||
//分词器上下文
|
||||
private AnalyzeContext context;
|
||||
/**
|
||||
* 分词处理器列表
|
||||
*/
|
||||
//分词处理器列表
|
||||
private List<ISegmenter> segmenters;
|
||||
/**
|
||||
* 分词歧义裁决器
|
||||
*/
|
||||
//分词歧义裁决器
|
||||
private IKArbitrator arbitrator;
|
||||
|
||||
|
||||
|
@ -29,13 +29,13 @@ package org.wltea.analyzer.core;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 子分词器接口
|
||||
*/
|
||||
interface ISegmenter {
|
||||
|
||||
/**
|
||||
* 从分析器读取下一个可能分解的词元对象
|
||||
*
|
||||
* @param context 分词算法上下文
|
||||
*/
|
||||
void analyze(AnalyzeContext context);
|
||||
|
@ -34,18 +34,14 @@ import java.util.Arrays;
|
||||
*/
|
||||
class LetterSegmenter implements ISegmenter {
|
||||
|
||||
/**
|
||||
* 子分词器标签
|
||||
*/
|
||||
//子分词器标签
|
||||
private static final String SEGMENTER_NAME = "LETTER_SEGMENTER";
|
||||
/**
|
||||
* 链接符号
|
||||
*/
|
||||
//链接符号
|
||||
private static final char[] Letter_Connector = new char[]{'#', '&', '+', '-', '.', '@', '_'};
|
||||
/**
|
||||
* 数字符号
|
||||
*/
|
||||
|
||||
//数字符号
|
||||
private static final char[] Num_Connector = new char[]{',', '.'};
|
||||
|
||||
/*
|
||||
* 词元的开始位置,
|
||||
* 同时作为子分词器状态标识
|
||||
@ -57,18 +53,22 @@ class LetterSegmenter implements ISegmenter {
|
||||
* end记录的是在词元中最后一个出现的Letter但非Sign_Connector的字符的位置
|
||||
*/
|
||||
private int end;
|
||||
|
||||
/*
|
||||
* 字母起始位置
|
||||
*/
|
||||
private int englishStart;
|
||||
|
||||
/*
|
||||
* 字母结束位置
|
||||
*/
|
||||
private int englishEnd;
|
||||
|
||||
/*
|
||||
* 阿拉伯数字起始位置
|
||||
*/
|
||||
private int arabicStart;
|
||||
|
||||
/*
|
||||
* 阿拉伯数字结束位置
|
||||
*/
|
||||
|
@ -32,61 +32,34 @@ package org.wltea.analyzer.core;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Lexeme implements Comparable<Lexeme>{
|
||||
/**
|
||||
* 英文
|
||||
*/
|
||||
//英文
|
||||
static final int TYPE_ENGLISH = 1;
|
||||
/**
|
||||
* 数字
|
||||
*/
|
||||
//数字
|
||||
static final int TYPE_ARABIC = 2;
|
||||
/**
|
||||
* 英文数字混合
|
||||
*/
|
||||
//英文数字混合
|
||||
static final int TYPE_LETTER = 3;
|
||||
/**
|
||||
* 中文词元
|
||||
*/
|
||||
//中文词元
|
||||
static final int TYPE_CNWORD = 4;
|
||||
/**
|
||||
* 中文单字
|
||||
*/
|
||||
//中文单字
|
||||
static final int TYPE_CNCHAR = 64;
|
||||
/**
|
||||
* 日韩文字
|
||||
*/
|
||||
//日韩文字
|
||||
static final int TYPE_OTHER_CJK = 8;
|
||||
/**
|
||||
* 中文数词
|
||||
*/
|
||||
//中文数词
|
||||
static final int TYPE_CNUM = 16;
|
||||
/**
|
||||
* 中文量词
|
||||
*/
|
||||
//中文量词
|
||||
static final int TYPE_COUNT = 32;
|
||||
/**
|
||||
* 中文数量词
|
||||
*/
|
||||
//中文数量词
|
||||
static final int TYPE_CQUAN = 48;
|
||||
/**
|
||||
* 词元的起始位移
|
||||
*/
|
||||
|
||||
//词元的起始位移
|
||||
private int offset;
|
||||
/**
|
||||
* 词元的相对起始位置
|
||||
*/
|
||||
//词元的相对起始位置
|
||||
private int begin;
|
||||
/**
|
||||
* 词元的长度
|
||||
*/
|
||||
//词元的长度
|
||||
private int length;
|
||||
/**
|
||||
* 词元文本
|
||||
*/
|
||||
//词元文本
|
||||
private String lexemeText;
|
||||
/**
|
||||
* 词元类型
|
||||
*/
|
||||
//词元类型
|
||||
private int lexemeType;
|
||||
|
||||
|
||||
@ -147,7 +120,7 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
//this.length < other.getLength()
|
||||
return Integer.compare(other.getLength(), this.length);
|
||||
|
||||
} else {
|
||||
}else{//this.begin > other.getBegin()
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -163,10 +136,8 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
int getBegin() {
|
||||
return begin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取词元在文本中的起始位置
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getBeginPosition(){
|
||||
@ -179,7 +150,6 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
|
||||
/**
|
||||
* 获取词元在文本中的结束位置
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getEndPosition(){
|
||||
@ -188,7 +158,6 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
|
||||
/**
|
||||
* 获取词元的字符长度
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getLength(){
|
||||
@ -204,7 +173,6 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
|
||||
/**
|
||||
* 获取词元的文本内容
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getLexemeText() {
|
||||
@ -226,7 +194,6 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
|
||||
/**
|
||||
* 获取词元类型
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int getLexemeType() {
|
||||
@ -235,7 +202,6 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
|
||||
/**
|
||||
* 获取词元类型标示字符串
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getLexemeTypeString(){
|
||||
@ -269,7 +235,7 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
return "TYPE_CQUAN";
|
||||
|
||||
default :
|
||||
return "UNKNOWN";
|
||||
return "UNKONW";
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +246,6 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
|
||||
/**
|
||||
* 合并两个相邻的词元
|
||||
*
|
||||
* @return boolean 词元是否成功合并
|
||||
*/
|
||||
boolean append(Lexeme l, int lexemeType){
|
||||
@ -293,10 +258,9 @@ public class Lexeme implements Comparable<Lexeme> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ToString 方法
|
||||
*
|
||||
* @return 字符串输出
|
||||
*/
|
||||
public String toString(){
|
||||
return this.getBeginPosition() + "-" + this.getEndPosition() +
|
||||
|
@ -34,17 +34,11 @@ package org.wltea.analyzer.core;
|
||||
@SuppressWarnings("unused")
|
||||
class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
|
||||
/**
|
||||
* 起始位置
|
||||
*/
|
||||
//起始位置
|
||||
private int pathBegin;
|
||||
/**
|
||||
* 结束
|
||||
*/
|
||||
//结束
|
||||
private int pathEnd;
|
||||
/**
|
||||
* 词元链的有效字符长度
|
||||
*/
|
||||
//词元链的有效字符长度
|
||||
private int payloadLength;
|
||||
|
||||
LexemePath() {
|
||||
@ -106,6 +100,7 @@ class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
|
||||
/**
|
||||
* 移除尾部的Lexeme
|
||||
*
|
||||
*/
|
||||
void removeTail() {
|
||||
Lexeme tail = this.pollLast();
|
||||
@ -122,6 +117,7 @@ class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
|
||||
/**
|
||||
* 检测词元位置交叉(有歧义的切分)
|
||||
*
|
||||
*/
|
||||
boolean checkCross(Lexeme lexeme) {
|
||||
return (lexeme.getBegin() >= this.pathBegin && lexeme.getBegin() < this.pathEnd)
|
||||
@ -145,6 +141,7 @@ class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
|
||||
/**
|
||||
* 获取LexemePath的路径长度
|
||||
*
|
||||
*/
|
||||
private int getPathLength() {
|
||||
return this.pathEnd - this.pathBegin;
|
||||
@ -153,6 +150,7 @@ class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
|
||||
/**
|
||||
* X权重(词元长度积)
|
||||
*
|
||||
*/
|
||||
private int getXWeight() {
|
||||
int product = 1;
|
||||
@ -198,36 +196,31 @@ class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
return -1;
|
||||
} else if (this.payloadLength < o.payloadLength) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
//比较词元个数,越少越好
|
||||
if (this.size() < o.size()) {
|
||||
return -1;
|
||||
} else if (this.size() > o.size()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
//路径跨度越大越好
|
||||
if (this.getPathLength() > o.getPathLength()) {
|
||||
return -1;
|
||||
} else if (this.getPathLength() < o.getPathLength()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
//根据统计学结论,逆向切分概率高于正向切分,因此位置越靠后的优先
|
||||
if (this.pathEnd > o.pathEnd) {
|
||||
return -1;
|
||||
} else if (pathEnd < o.pathEnd) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
//词长越平均越好
|
||||
if (this.getXWeight() > o.getXWeight()) {
|
||||
return -1;
|
||||
} else if (this.getXWeight() < o.getXWeight()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
} else {
|
||||
//词元位置权重比较
|
||||
if (this.getPWeight() > o.getPWeight()) {
|
||||
return -1;
|
||||
@ -235,6 +228,11 @@ class LexemePath extends QuickSortSet implements Comparable<LexemePath> {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -28,20 +28,14 @@
|
||||
package org.wltea.analyzer.core;
|
||||
|
||||
/**
|
||||
* IK分词器专用的Lexeme快速排序集合
|
||||
* IK分词器专用的Lexem快速排序集合
|
||||
*/
|
||||
class QuickSortSet {
|
||||
/**
|
||||
* 链表头
|
||||
*/
|
||||
//链表头
|
||||
private Cell head;
|
||||
/**
|
||||
* 链表尾
|
||||
*/
|
||||
//链表尾
|
||||
private Cell tail;
|
||||
/**
|
||||
* 链表的实际大小
|
||||
*/
|
||||
//链表的实际大小
|
||||
private int size;
|
||||
|
||||
QuickSortSet() {
|
||||
@ -59,15 +53,16 @@ class QuickSortSet {
|
||||
this.size++;
|
||||
|
||||
} else {
|
||||
if (this.tail.compareTo(newCell) < 0) {
|
||||
// 词元接入链表尾部
|
||||
/*if(this.tail.compareTo(newCell) == 0){//词元与尾部词元相同,不放入集合
|
||||
|
||||
}else */
|
||||
if (this.tail.compareTo(newCell) < 0) {//词元接入链表尾部
|
||||
this.tail.next = newCell;
|
||||
newCell.prev = this.tail;
|
||||
this.tail = newCell;
|
||||
this.size++;
|
||||
|
||||
} else if (this.head.compareTo(newCell) > 0) {
|
||||
// 词元接入链表头部
|
||||
} else if (this.head.compareTo(newCell) > 0) {//词元接入链表头部
|
||||
this.head.prev = newCell;
|
||||
newCell.next = this.head;
|
||||
this.head = newCell;
|
||||
@ -79,9 +74,10 @@ class QuickSortSet {
|
||||
while (index != null && index.compareTo(newCell) > 0) {
|
||||
index = index.prev;
|
||||
}
|
||||
/*if(index.compareTo(newCell) == 0){//词元与集合中的词元重复,不放入集合
|
||||
|
||||
// 词元插入链表中的某个位置
|
||||
if ((index != null ? index.compareTo(newCell) : 1) < 0) {
|
||||
}else */
|
||||
if ((index != null ? index.compareTo(newCell) : 1) < 0) {//词元插入链表中的某个位置
|
||||
newCell.prev = index;
|
||||
newCell.next = index.next;
|
||||
index.next.prev = newCell;
|
||||
|
@ -37,38 +37,24 @@ import java.util.Map;
|
||||
@SuppressWarnings("unused")
|
||||
class DictSegment implements Comparable<DictSegment> {
|
||||
|
||||
/**
|
||||
* 公用字典表,存储汉字
|
||||
*/
|
||||
//公用字典表,存储汉字
|
||||
private static final Map<Character, Character> charMap = new HashMap<>(16, 0.95f);
|
||||
/**
|
||||
* 数组大小上限
|
||||
*/
|
||||
//数组大小上限
|
||||
private static final int ARRAY_LENGTH_LIMIT = 3;
|
||||
|
||||
|
||||
/**
|
||||
* Map存储结构
|
||||
*/
|
||||
private volatile Map<Character, DictSegment> childrenMap;
|
||||
/**
|
||||
* 数组方式存储结构
|
||||
*/
|
||||
private volatile DictSegment[] childrenArray;
|
||||
//Map存储结构
|
||||
private Map<Character, DictSegment> childrenMap;
|
||||
//数组方式存储结构
|
||||
private DictSegment[] childrenArray;
|
||||
|
||||
|
||||
/**
|
||||
* 当前节点上存储的字符
|
||||
*/
|
||||
private final Character nodeChar;
|
||||
/**
|
||||
* 当前节点存储的Segment数目
|
||||
* storeSize <=ARRAY_LENGTH_LIMIT ,使用数组存储, storeSize >ARRAY_LENGTH_LIMIT ,则使用Map存储
|
||||
*/
|
||||
//当前节点上存储的字符
|
||||
private Character nodeChar;
|
||||
//当前节点存储的Segment数目
|
||||
//storeSize <=ARRAY_LENGTH_LIMIT ,使用数组存储, storeSize >ARRAY_LENGTH_LIMIT ,则使用Map存储
|
||||
private int storeSize = 0;
|
||||
/**
|
||||
* 当前DictSegment状态 ,默认 0 , 1表示从根节点到当前节点的路径表示一个词
|
||||
*/
|
||||
//当前DictSegment状态 ,默认 0 , 1表示从根节点到当前节点的路径表示一个词
|
||||
private int nodeState = 0;
|
||||
|
||||
|
||||
|
@ -27,14 +27,14 @@
|
||||
*/
|
||||
package org.wltea.analyzer.dic;
|
||||
|
||||
import org.wltea.analyzer.cfg.Configuration;
|
||||
import org.wltea.analyzer.cfg.DefaultConfig;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.wltea.analyzer.cfg.Configuration;
|
||||
import org.wltea.analyzer.cfg.DefaultConfig;
|
||||
|
||||
/**
|
||||
* 词典管理类,单例模式
|
||||
*/
|
||||
@ -44,7 +44,7 @@ public class Dictionary {
|
||||
/*
|
||||
* 词典单子实例
|
||||
*/
|
||||
private static volatile Dictionary singleton;
|
||||
private static Dictionary singleton;
|
||||
|
||||
/*
|
||||
* 主词典对象
|
||||
@ -63,7 +63,7 @@ public class Dictionary {
|
||||
/**
|
||||
* 配置对象
|
||||
*/
|
||||
private final Configuration cfg;
|
||||
private Configuration cfg;
|
||||
|
||||
/**
|
||||
* 私有构造方法,阻止外部直接实例化本类
|
||||
@ -326,7 +326,7 @@ public class Dictionary {
|
||||
// 建立一个量词典实例
|
||||
_QuantifierDict = new DictSegment((char) 0);
|
||||
// 读取量词词典文件
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getQuantifierDictionary());
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getQuantifierDicionary());
|
||||
if (is == null) {
|
||||
throw new RuntimeException("Quantifier Dictionary not found!!!");
|
||||
}
|
||||
|
@ -32,33 +32,24 @@ package org.wltea.analyzer.dic;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Hit {
|
||||
/**
|
||||
* Hit不匹配
|
||||
*/
|
||||
//Hit不匹配
|
||||
private static final int UNMATCH = 0x00000000;
|
||||
/**
|
||||
* Hit完全匹配
|
||||
*/
|
||||
//Hit完全匹配
|
||||
private static final int MATCH = 0x00000001;
|
||||
/**
|
||||
* Hit前缀匹配
|
||||
*/
|
||||
//Hit前缀匹配
|
||||
private static final int PREFIX = 0x00000010;
|
||||
|
||||
|
||||
/**
|
||||
* 该HIT当前状态,默认未匹配
|
||||
*/
|
||||
//该HIT当前状态,默认未匹配
|
||||
private int hitState = UNMATCH;
|
||||
/**
|
||||
* 记录词典匹配过程中,当前匹配到的词典分支节点
|
||||
*/
|
||||
|
||||
//记录词典匹配过程中,当前匹配到的词典分支节点
|
||||
private DictSegment matchedDictSegment;
|
||||
/**
|
||||
/*
|
||||
* 词段开始位置
|
||||
*/
|
||||
private int begin;
|
||||
/**
|
||||
/*
|
||||
* 词段的结束位置
|
||||
*/
|
||||
private int end;
|
||||
@ -95,7 +86,9 @@ public class Hit {
|
||||
public boolean isUnmatch() {
|
||||
return this.hitState == UNMATCH ;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void setUnmatch() {
|
||||
this.hitState = UNMATCH;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import org.apache.lucene.analysis.Tokenizer;
|
||||
@SuppressWarnings("unused")
|
||||
public final class IKAnalyzer extends Analyzer {
|
||||
|
||||
private final boolean useSmart;
|
||||
private boolean useSmart;
|
||||
|
||||
private boolean useSmart() {
|
||||
return useSmart;
|
||||
|
@ -39,30 +39,21 @@ import java.io.IOException;
|
||||
|
||||
/**
|
||||
* IK分词器 Lucene Tokenizer适配器类
|
||||
* 兼容Lucene 4.0版本
|
||||
*/
|
||||
@SuppressWarnings({"unused", "FinalMethodInFinalClass"})
|
||||
@SuppressWarnings("unused")
|
||||
public final class IKTokenizer extends Tokenizer {
|
||||
|
||||
/**
|
||||
* IK分词器实现
|
||||
*/
|
||||
//IK分词器实现
|
||||
private IKSegmenter _IKImplement;
|
||||
|
||||
/**
|
||||
* 词元文本属性
|
||||
*/
|
||||
//词元文本属性
|
||||
private CharTermAttribute termAtt;
|
||||
/**
|
||||
* 词元位移属性
|
||||
*/
|
||||
//词元位移属性
|
||||
private OffsetAttribute offsetAtt;
|
||||
/**
|
||||
* 词元分类属性(该属性分类参考org.wltea.analyzer.core.Lexeme中的分类常量)
|
||||
*/
|
||||
//词元分类属性(该属性分类参考org.wltea.analyzer.core.Lexeme中的分类常量)
|
||||
private TypeAttribute typeAtt;
|
||||
/**
|
||||
* 记录最后一个词元的结束位置
|
||||
*/
|
||||
//记录最后一个词元的结束位置
|
||||
private int endPosition;
|
||||
|
||||
/**
|
||||
@ -93,8 +84,7 @@ public final class IKTokenizer extends Tokenizer {
|
||||
_IKImplement = new IKSegmenter(input, useSmart);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.lucene.analysis.TokenStream#incrementToken()
|
||||
*/
|
||||
@Override
|
||||
|
@ -21,8 +21,8 @@
|
||||
* 版权声明 2012,乌龙茶工作室
|
||||
* provided by Linliangyi and copyright 2012 by Oolong studio
|
||||
*
|
||||
* 8.5.0版本 由 Magese (magese@live.cn) 更新
|
||||
* release 8.5.0 update by Magese(magese@live.cn)
|
||||
* 8.3.1版本 由 Magese (magese@live.cn) 更新
|
||||
* release 8.3.1 update by Magese(magese@live.cn)
|
||||
*
|
||||
*/
|
||||
package org.wltea.analyzer.lucene;
|
||||
@ -44,8 +44,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 分词器工厂类
|
||||
*
|
||||
* @author <a href="magese@live.cn">Magese</a>
|
||||
*/
|
||||
public class IKTokenizerFactory extends TokenizerFactory implements ResourceLoaderAware, UpdateThread.UpdateJob {
|
||||
|
@ -46,11 +46,11 @@ import java.util.Stack;
|
||||
public class IKQueryExpressionParser {
|
||||
|
||||
|
||||
private final List<Element> elements = new ArrayList<>();
|
||||
private List<Element> elements = new ArrayList<>();
|
||||
|
||||
private final Stack<Query> querys = new Stack<>();
|
||||
private Stack<Query> querys = new Stack<>();
|
||||
|
||||
private final Stack<Element> operates = new Stack<>();
|
||||
private Stack<Element> operates = new Stack<>();
|
||||
|
||||
/**
|
||||
* 解析查询表达式,生成Lucene Query对象
|
||||
@ -87,263 +87,263 @@ public class IKQueryExpressionParser {
|
||||
if (expression == null) {
|
||||
return;
|
||||
}
|
||||
Element currentElement = null;
|
||||
Element curretElement = null;
|
||||
|
||||
char[] expChars = expression.toCharArray();
|
||||
for (char expChar : expChars) {
|
||||
switch (expChar) {
|
||||
case '&':
|
||||
if (currentElement == null) {
|
||||
currentElement = new Element();
|
||||
currentElement.type = '&';
|
||||
currentElement.append(expChar);
|
||||
} else if (currentElement.type == '&') {
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
} else if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement == null) {
|
||||
curretElement = new Element();
|
||||
curretElement.type = '&';
|
||||
curretElement.append(expChar);
|
||||
} else if (curretElement.type == '&') {
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
} else if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
currentElement = new Element();
|
||||
currentElement.type = '&';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = new Element();
|
||||
curretElement.type = '&';
|
||||
curretElement.append(expChar);
|
||||
}
|
||||
break;
|
||||
|
||||
case '|':
|
||||
if (currentElement == null) {
|
||||
currentElement = new Element();
|
||||
currentElement.type = '|';
|
||||
currentElement.append(expChar);
|
||||
} else if (currentElement.type == '|') {
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
} else if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement == null) {
|
||||
curretElement = new Element();
|
||||
curretElement.type = '|';
|
||||
curretElement.append(expChar);
|
||||
} else if (curretElement.type == '|') {
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
} else if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
currentElement = new Element();
|
||||
currentElement.type = '|';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = new Element();
|
||||
curretElement.type = '|';
|
||||
curretElement.append(expChar);
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = '-';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = '-';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case '(':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = '(';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = '(';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = ')';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = ')';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case ':':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = ':';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = ':';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case '=':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = '=';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = '=';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case '\'':
|
||||
if (currentElement == null) {
|
||||
currentElement = new Element();
|
||||
currentElement.type = '\'';
|
||||
if (curretElement == null) {
|
||||
curretElement = new Element();
|
||||
curretElement.type = '\'';
|
||||
|
||||
} else if (currentElement.type == '\'') {
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
} else if (curretElement.type == '\'') {
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
currentElement = new Element();
|
||||
currentElement.type = '\'';
|
||||
this.elements.add(curretElement);
|
||||
curretElement = new Element();
|
||||
curretElement.type = '\'';
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case '[':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = '[';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = '[';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case ']':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = ']';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = ']';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
|
||||
break;
|
||||
|
||||
case '{':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = '{';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = '{';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = '}';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = '}';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
|
||||
break;
|
||||
case ',':
|
||||
if (currentElement != null) {
|
||||
if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
if (curretElement != null) {
|
||||
if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
continue;
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
currentElement = new Element();
|
||||
currentElement.type = ',';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(currentElement);
|
||||
currentElement = null;
|
||||
curretElement = new Element();
|
||||
curretElement.type = ',';
|
||||
curretElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = null;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if (currentElement == null) {
|
||||
currentElement = new Element();
|
||||
currentElement.type = 'F';
|
||||
currentElement.append(expChar);
|
||||
if (curretElement == null) {
|
||||
curretElement = new Element();
|
||||
curretElement.type = 'F';
|
||||
curretElement.append(expChar);
|
||||
|
||||
} else if (currentElement.type == 'F') {
|
||||
currentElement.append(expChar);
|
||||
} else if (curretElement.type == 'F') {
|
||||
curretElement.append(expChar);
|
||||
|
||||
} else if (currentElement.type == '\'') {
|
||||
currentElement.append(expChar);
|
||||
} else if (curretElement.type == '\'') {
|
||||
curretElement.append(expChar);
|
||||
|
||||
} else {
|
||||
this.elements.add(currentElement);
|
||||
currentElement = new Element();
|
||||
currentElement.type = 'F';
|
||||
currentElement.append(expChar);
|
||||
this.elements.add(curretElement);
|
||||
curretElement = new Element();
|
||||
curretElement.type = 'F';
|
||||
curretElement.append(expChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentElement != null) {
|
||||
this.elements.add(currentElement);
|
||||
if (curretElement != null) {
|
||||
this.elements.add(curretElement);
|
||||
}
|
||||
}
|
||||
|
||||
@ -673,7 +673,7 @@ public class IKQueryExpressionParser {
|
||||
* @author linliangyi
|
||||
* May 20, 2010
|
||||
*/
|
||||
private static class Element {
|
||||
private class Element {
|
||||
char type = 0;
|
||||
StringBuffer eleTextBuff;
|
||||
|
||||
@ -692,9 +692,11 @@ public class IKQueryExpressionParser {
|
||||
|
||||
public static void main(String[] args) {
|
||||
IKQueryExpressionParser parser = new IKQueryExpressionParser();
|
||||
//String ikQueryExp = "newsTitle:'的两款《魔兽世界》插件Bigfoot和月光宝盒'";
|
||||
String ikQueryExp = "(id='ABcdRf' && date:{'20010101','20110101'} && keyword:'魔兽中国') || (content:'KSHT-KSH-A001-18' || ulr='www.ik.com') - name:'林良益'";
|
||||
Query result = parser.parseExp(ikQueryExp);
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,6 @@ import java.util.List;
|
||||
*
|
||||
* @author linliangyi
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
class SWMCQueryBuilder {
|
||||
|
||||
/**
|
||||
@ -119,8 +118,8 @@ class SWMCQueryBuilder {
|
||||
|
||||
//借助lucene queryparser 生成SWMC Query
|
||||
QueryParser qp = new QueryParser(fieldName, new StandardAnalyzer());
|
||||
qp.setAutoGeneratePhraseQueries(false);
|
||||
qp.setDefaultOperator(QueryParser.AND_OPERATOR);
|
||||
qp.setAutoGeneratePhraseQueries(true);
|
||||
|
||||
if ((shortCount * 1.0f / totalCount) > 0.5f) {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user