新增自动分段关键词处理
parent
fa09517f5b
commit
d5f5403d0c
@ -0,0 +1,62 @@
|
||||
package com.docus.server.controller;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class KeyWordStrategy {
|
||||
|
||||
private String id;
|
||||
|
||||
//用包含的逻辑。
|
||||
//包含占比。 按照占比排序
|
||||
//从什么开始,然后从什么跳出。
|
||||
|
||||
|
||||
// 分段id,包含占比,关键词列表
|
||||
|
||||
private List<String> keys;
|
||||
private Double score;
|
||||
private String segmentId;
|
||||
|
||||
private String segmentName;
|
||||
|
||||
private List<KeyWordStrategy> keyWordStrategyHashMap;
|
||||
|
||||
|
||||
public KeyWordStrategy(String id, List<String> keys, Double score, String segmentId, List<KeyWordStrategy> keyWordStrategyHashMap) {
|
||||
this.id = id;
|
||||
this.keys = keys;
|
||||
this.score = score;
|
||||
this.segmentId = segmentId;
|
||||
this.keyWordStrategyHashMap = keyWordStrategyHashMap;
|
||||
}
|
||||
|
||||
public SegmentResult isContain(String keyWord) {
|
||||
for (String key : keys) {
|
||||
if (keyWord.contains(key)) {
|
||||
if (key.length() / keyWord.length() >= this.score) {
|
||||
|
||||
if (keyWordStrategyHashMap != null) {
|
||||
//没有二级分类,直接返回当前分段
|
||||
return new SegmentResult(id, this.segmentId, key, this.score);
|
||||
} else {
|
||||
//有二级分类,如果有找到,则返回二级分类。
|
||||
for (KeyWordStrategy secSegment : keyWordStrategyHashMap) {
|
||||
SegmentResult contain = secSegment.isContain(key);
|
||||
return contain;
|
||||
}
|
||||
//没有找到,则返回当前分类。
|
||||
return new SegmentResult(id, this.segmentId, key, this.score);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果都没有找到,返回空。
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.docus.server.controller;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class SegmentResult {
|
||||
|
||||
private String id;
|
||||
private String segmentId;
|
||||
private String keyWord;
|
||||
private Double score;
|
||||
|
||||
}
|
Loading…
Reference in New Issue