1. 导入相关依赖
<!--JFoolNLTK分词-->
<dependency>
<groupId>me.midday</groupId>
<artifactId>JFoolNLTK</artifactId>
<version>1.0</version>
</dependency>
2. 相关类DataIntegerMap.java
import lombok.Data;
@Data
public class DataIntegerMap {
private String name;
private Integer value;
}
3. 相关类CommonUtil.java
public class CommonUtil {
public static String listToString(List<?> list, String exp) {
StringBuffer resourceIdsSB = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
resourceIdsSB.append(list.get(i));
if (i < list.size() - 1) {
resourceIdsSB.append(exp);
}
}
return resourceIdsSB.toString();
}
public static Map get_str_count_index(String[] str){
Map<String,Map<Integer,ArrayList>> map = new HashMap<String ,Map<Integer,ArrayList>>();
int i = 0;
for (String s:str ){
if (map.get(s)==null){
Map<Integer,ArrayList> count_where = new HashMap<Integer ,ArrayList>();
int count = 1;
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(i);
count_where.put(count,list);
map.put(s,count_where);
i++;
}else {
for (int c:map.get(s).keySet()){
ArrayList index = map.get(s).get(c);
index.add(i);
c++;
map.get(s).put(c,index);
map.get(s).remove(--c);
}
i++;
}
}
return map;
}
}
3.分词工具类IKUtil.java
import com.rongyun.common.utils.CommonUtil;
import com.rongyun.system.api.zhxy.map.DataIntegerMap;
import me.midday.FoolNLTK;
import me.midday.lexical.LexicalAnalyzer;
import me.midday.lexical.Word;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
public class IKUtil {
public static final String regEx = "[\n\r\t`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?^p]";
public static List<String> splitKeyWordByFoolNLTK(String keyword) throws IOException {
keyword = keyword.replaceAll(regEx, "").replaceAll(" ", "").replaceAll(" ", "");
LexicalAnalyzer lexicalAnalyzer = FoolNLTK.getLSTMLexicalAnalyzer();
ArrayList<String> result = new ArrayList<>();
List<List<Word>> words = lexicalAnalyzer.cut(keyword);
for(List<Word> ws: words){
for (Word word: ws){
if (word.toString().length() > 1 ){
result.add(word.toString());
}
}
}
return result;
}
public static List<String> splitKeyWordByFoolNLTK(List<String> keyword) throws IOException {
String content = CommonUtil.listToString(keyword,",");
List<String> contentList = IKUtil.splitKeyWordByFoolNLTK(content);
return contentList;
}
public static List<DataIntegerMap> splitKeyWordByFoolNLTKToMap(String keyword) throws Exception {
List<String> contentList = IKUtil.splitKeyWordByFoolNLTK(keyword);
List<DataIntegerMap> mapList = getMapByArray(CommonUtil.listToString(contentList,",").split(","));
return mapList;
}
public static List<DataIntegerMap> splitKeyWordByFoolNLTKToMap(List<String> keyword) throws Exception {
String content = CommonUtil.listToString(keyword,",");
List<String> contentList = IKUtil.splitKeyWordByFoolNLTK(content);
List<DataIntegerMap> mapList = getMapByArray(CommonUtil.listToString(contentList,",").split(","));
return mapList;
}
public static List<DataIntegerMap> getMapByArray(String[] arry) throws Exception{
if (arry.length == 0 ){
return new ArrayList<>();
}
List<DataIntegerMap> list = new ArrayList<>();
Map<String, HashMap<Integer,ArrayList>> map = CommonUtil.get_str_count_index(arry);
for (String key :map.keySet()){
for (int num:map.get(key).keySet()){
if (num > 1 ){
DataIntegerMap dataIntegerMap = new DataIntegerMap();
dataIntegerMap.setName(key);
dataIntegerMap.setValue(num);
list.add(dataIntegerMap);
}
}
}
Collections.sort(list, Comparator.comparing(DataIntegerMap::getValue).reversed());
return list;
}
public static void main(String[] args) throws Exception {
String content ="来源:新闻坊、第一财经等版权归原作者所有,如有侵权请及时联系创立于1993年的克莉丝汀颠峰时期在上海拥有543家门店但就在去年7月这一知名烘培连锁品牌疑似经营异常最近新消息传来:克莉丝汀总部被曝已经人去楼空。克莉丝汀国际控股有限公司于3月10日发布公告称截至2023年2月28日,集团共拖欠金额人民币5700万元;银行账户已被冻结;已暂时关闭旗下所有零售门店。目前克莉丝汀已经通过贷款变卖资产等方式补充现金流3月18日,第一财经记者来到位于金沙江路33号的克莉丝汀上海总部,目前仅剩一位保安在一楼留守。记者在现场看见偌大而昏暗的门店内没有一个员工玻璃柜台里仍陈列着一些已经积灰的盒装糕点据保安介绍,3楼和4楼以前是克莉丝汀的办公点,现在也没有人了。而这位保安现在的工作任务就是看守门店内仍有的物品。门外的墙上贴了一张徐汇区人民法院的公告公告显示,作为被告的上海克莉丝汀食品有限公司已经拖欠了半年左右的房租,金额为12.16万元。金沙江路的克莉丝汀旗舰店只是公司目前情况的一个缩影克莉丝汀旗下所有门店自2022年12月起均已暂停营业一位克莉丝汀十几年的消费者表示:“大概半年前耀华路的克莉丝汀就关门了,不过克莉丝汀没有什么创新产品,一直是那几样东西。”来源:第一财经今年3月,克莉丝汀(01210.HK)在公告中提及,公司在支付店铺租金、供应商货款、员工薪酬方面出现延误,截至2023年2月28日,拖欠金额约为人民币5700万元。由于拖欠货款,若干供应商已展开法律程序,冻结了本集团的银行账户,被冻结金额约人民币350万元至人民币400万元。克莉丝汀目前已经通过贷款、变卖资产等方式补充现金流。克莉丝汀的经营状况一直不佳官网资料显示,克莉丝汀自1993年起生产及销售烘焙产品,主要在长三角地区的黄金地段及主要城市进行营运。2012年2月,克莉丝汀登陆香港联交所。财报显示,2013年至2021年,克莉丝汀已连续9年亏损。其中2019年、2020年、2021年、2022年上半年归母净利润分别为-2.24亿元、-1.1亿元、-1.7亿元和-0.73万元。而且,克莉丝汀的门店数目一直在减少。年报显示,2021年,克莉丝汀关闭了55家门店,2020年关闭了99家门店,2019年,共关闭了117家门店。中国食品产业分析师朱丹蓬认为,对于中国的烘焙行业来说,创新、升级、迭代一定是整个行业发展的主旋律。一些老品牌的倒闭,一方面与疫情有关,一方面也和自身缺乏创新机制的僵化、团队的老化有关。烘焙行业的竞争较为激烈,近些年新消费品牌不断涌现,它们也在该赛道分了一杯羹。艾媒咨询数据显示,2021年中国烘焙食品市场规模约为2600.8亿元,同比增长19.9%,并预计2023年中国烘焙食品市场规模将进一步增长至3069.9亿元。商业竞争不进则退↓↓↓";
List<DataIntegerMap> contentList = splitKeyWordByFoolNLTKToMap(content);
for (DataIntegerMap map : contentList){
System.out.println(map);
}
}
}
4.运行效果
