mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
e67bbdec19
commit
26b99c7b08
@ -12,9 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.extra.pinyin;
|
||||
|
||||
import org.dromara.hutool.core.exception.ExceptionUtil;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* 模板异常
|
||||
|
@ -12,38 +12,74 @@
|
||||
|
||||
package org.dromara.hutool.extra.qrcode;
|
||||
|
||||
import org.dromara.hutool.core.exception.ExceptionUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
|
||||
/**
|
||||
* Qrcode异常
|
||||
*
|
||||
* @author xiaoleilu
|
||||
* @author Looly
|
||||
*/
|
||||
public class QrCodeException extends RuntimeException {
|
||||
public class QrCodeException extends HutoolException {
|
||||
private static final long serialVersionUID = 8247610319171014183L;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param e 异常
|
||||
*/
|
||||
public QrCodeException(final Throwable e) {
|
||||
super(ExceptionUtil.getMessage(e), e);
|
||||
super(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
public QrCodeException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param messageTemplate 消息模板
|
||||
* @param params 参数
|
||||
*/
|
||||
public QrCodeException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
super(messageTemplate, params);
|
||||
}
|
||||
|
||||
public QrCodeException(final String message, final Throwable throwable) {
|
||||
super(message, throwable);
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param message 消息
|
||||
* @param cause 被包装的子异常
|
||||
*/
|
||||
public QrCodeException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public QrCodeException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, throwable, enableSuppression, writableStackTrace);
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param message 消息
|
||||
* @param cause 被包装的子异常
|
||||
* @param enableSuppression 是否启用抑制
|
||||
* @param writableStackTrace 堆栈跟踪是否应该是可写的
|
||||
*/
|
||||
public QrCodeException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public QrCodeException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param cause 被包装的子异常
|
||||
* @param messageTemplate 消息模板
|
||||
* @param params 参数
|
||||
*/
|
||||
public QrCodeException(final Throwable cause, final String messageTemplate, final Object... params) {
|
||||
super(cause, messageTemplate, params);
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ public class QrConfig {
|
||||
* @param shapeHint DATA_MATRIX的符号形状
|
||||
* @return this
|
||||
*/
|
||||
public QrConfig setShapeHint(SymbolShapeHint shapeHint) {
|
||||
public QrConfig setShapeHint(final SymbolShapeHint shapeHint) {
|
||||
this.shapeHint = shapeHint;
|
||||
return this;
|
||||
}
|
||||
@ -393,7 +393,7 @@ public class QrConfig {
|
||||
* @param format 码格式
|
||||
* @return this
|
||||
*/
|
||||
public QrConfig setFormat(BarcodeFormat format) {
|
||||
public QrConfig setFormat(final BarcodeFormat format) {
|
||||
this.format = format;
|
||||
return this;
|
||||
}
|
||||
|
@ -12,38 +12,74 @@
|
||||
|
||||
package org.dromara.hutool.extra.tokenizer;
|
||||
|
||||
import org.dromara.hutool.core.exception.ExceptionUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
|
||||
/**
|
||||
* 分词异常
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class TokenizerException extends RuntimeException {
|
||||
public class TokenizerException extends HutoolException {
|
||||
private static final long serialVersionUID = 8074865854534335463L;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param e 异常
|
||||
*/
|
||||
public TokenizerException(final Throwable e) {
|
||||
super(ExceptionUtil.getMessage(e), e);
|
||||
super(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
public TokenizerException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param messageTemplate 消息模板
|
||||
* @param params 参数
|
||||
*/
|
||||
public TokenizerException(final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params));
|
||||
super(messageTemplate, params);
|
||||
}
|
||||
|
||||
public TokenizerException(final String message, final Throwable throwable) {
|
||||
super(message, throwable);
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param message 消息
|
||||
* @param cause 被包装的子异常
|
||||
*/
|
||||
public TokenizerException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public TokenizerException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, throwable, enableSuppression, writableStackTrace);
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param message 消息
|
||||
* @param cause 被包装的子异常
|
||||
* @param enableSuppression 是否启用抑制
|
||||
* @param writableStackTrace 堆栈跟踪是否应该是可写的
|
||||
*/
|
||||
public TokenizerException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public TokenizerException(final Throwable throwable, final String messageTemplate, final Object... params) {
|
||||
super(StrUtil.format(messageTemplate, params), throwable);
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param cause 被包装的子异常
|
||||
* @param messageTemplate 消息模板
|
||||
* @param params 参数
|
||||
*/
|
||||
public TokenizerException(final Throwable cause, final String messageTemplate, final Object... params) {
|
||||
super(cause, messageTemplate, params);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,8 @@
|
||||
|
||||
package org.dromara.hutool.extra.tokenizer;
|
||||
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerFactory;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngineFactory;
|
||||
|
||||
/**
|
||||
* 分词工具类
|
||||
@ -22,12 +23,22 @@ import org.dromara.hutool.extra.tokenizer.engine.TokenizerFactory;
|
||||
*/
|
||||
public class TokenizerUtil {
|
||||
|
||||
/**
|
||||
* 分词处理
|
||||
*
|
||||
* @param text 文本
|
||||
* @return 分词结果
|
||||
*/
|
||||
public static Result parse(final String text) {
|
||||
return getEngine().parse(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户引入的分词引擎jar,自动创建对应的分词引擎对象
|
||||
*
|
||||
* @return {@link TokenizerEngine}
|
||||
*/
|
||||
public static TokenizerEngine createEngine() {
|
||||
return TokenizerFactory.of();
|
||||
public static TokenizerEngine getEngine() {
|
||||
return TokenizerEngineFactory.getEngine();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,9 @@
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.extra.tokenizer;
|
||||
package org.dromara.hutool.extra.tokenizer.engine;
|
||||
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
|
||||
/**
|
||||
* 分词引擎接口定义,用户通过实现此接口完成特定分词引擎的适配
|
@ -15,7 +15,6 @@ package org.dromara.hutool.extra.tokenizer.engine;
|
||||
import org.dromara.hutool.core.lang.Singleton;
|
||||
import org.dromara.hutool.core.spi.SpiUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerException;
|
||||
import org.dromara.hutool.log.StaticLog;
|
||||
|
||||
@ -23,19 +22,17 @@ import org.dromara.hutool.log.StaticLog;
|
||||
* 简单分词引擎工厂,用于根据用户引入的分词引擎jar,自动创建对应的引擎
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class TokenizerFactory {
|
||||
public class TokenizerEngineFactory {
|
||||
|
||||
/**
|
||||
* 根据用户引入的模板引擎jar,自动创建对应的分词引擎对象<br>
|
||||
* 获得的是单例的TokenizerEngine
|
||||
*
|
||||
* @return 单例的TokenizerEngine
|
||||
* @since 5.3.3
|
||||
*/
|
||||
public static TokenizerEngine get(){
|
||||
return Singleton.get(TokenizerEngine.class.getName(), TokenizerFactory::of);
|
||||
public static TokenizerEngine getEngine(){
|
||||
return Singleton.get(TokenizerEngine.class.getName(), TokenizerEngineFactory::createEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,8 +40,8 @@ public class TokenizerFactory {
|
||||
*
|
||||
* @return {@link TokenizerEngine}
|
||||
*/
|
||||
public static TokenizerEngine of() {
|
||||
final TokenizerEngine engine = doCreate();
|
||||
public static TokenizerEngine createEngine() {
|
||||
final TokenizerEngine engine = doCreateEngine();
|
||||
StaticLog.debug("Use [{}] Tokenizer Engine As Default.", StrUtil.removeSuffix(engine.getClass().getSimpleName(), "Engine"));
|
||||
return engine;
|
||||
}
|
||||
@ -54,7 +51,7 @@ public class TokenizerFactory {
|
||||
*
|
||||
* @return {@link TokenizerEngine}
|
||||
*/
|
||||
private static TokenizerEngine doCreate() {
|
||||
private static TokenizerEngine doCreateEngine() {
|
||||
final TokenizerEngine engine = SpiUtil.loadFirstAvailable(TokenizerEngine.class);
|
||||
if(null != engine){
|
||||
return engine;
|
@ -19,7 +19,7 @@ import org.apache.lucene.analysis.TokenStream;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerException;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ import org.ansj.splitWord.analysis.ToAnalysis;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
|
||||
/**
|
||||
* Ansj分词引擎实现<br>
|
||||
|
@ -16,7 +16,7 @@ import com.hankcs.hanlp.HanLP;
|
||||
import com.hankcs.hanlp.seg.Segment;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ package org.dromara.hutool.extra.tokenizer.engine.ikanalyzer;
|
||||
import org.wltea.analyzer.core.IKSegmenter;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.extra.tokenizer.engine.jcseg;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerException;
|
||||
import org.lionsoul.jcseg.ISegment;
|
||||
import org.lionsoul.jcseg.dic.ADictionary;
|
||||
|
@ -16,7 +16,7 @@ import com.huaban.analysis.jieba.JiebaSegmenter;
|
||||
import com.huaban.analysis.jieba.JiebaSegmenter.SegMode;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ package org.dromara.hutool.extra.tokenizer.engine.mmseg;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import com.chenlb.mmseg4j.ComplexSeg;
|
||||
import com.chenlb.mmseg4j.Dictionary;
|
||||
import com.chenlb.mmseg4j.MMSeg;
|
||||
|
@ -17,7 +17,7 @@ import com.mayabot.nlp.segment.Lexer;
|
||||
import com.mayabot.nlp.segment.Sentence;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
|
||||
/**
|
||||
* MYNLP 中文NLP工具包分词实现<br>
|
||||
|
@ -18,7 +18,7 @@ import org.apdplat.word.segmentation.SegmentationFactory;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.Result;
|
||||
import org.dromara.hutool.extra.tokenizer.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
|
||||
/**
|
||||
* Word分词引擎实现<br>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.dromara.hutool.extra.tokenizer;
|
||||
|
||||
import org.dromara.hutool.core.collection.iter.IterUtil;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.TokenizerEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.analysis.SmartcnEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.hanlp.HanLPEngine;
|
||||
import org.dromara.hutool.extra.tokenizer.engine.ikanalyzer.IKAnalyzerEngine;
|
||||
@ -22,10 +23,16 @@ public class TokenizerUtilTest {
|
||||
|
||||
String text = "这两个方法的区别在于返回值";
|
||||
|
||||
@Test
|
||||
void parseTest() {
|
||||
final Result result = TokenizerUtil.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEngineTest() {
|
||||
// 默认分词引擎,此处为Ansj
|
||||
final TokenizerEngine engine = TokenizerUtil.createEngine();
|
||||
final TokenizerEngine engine = TokenizerUtil.getEngine();
|
||||
final Result result = engine.parse(text);
|
||||
checkResult(result);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user