当前位置: 首页 > news >正文

济南做网站哪里便宜沈阳网站关键词排名

济南做网站哪里便宜,沈阳网站关键词排名,宜昌seo,南京做中英文网站目录 前言一、词云是什么?二、使用步骤1.引入依赖2.application.yml3.Controller4.分词工具类4.词云生成工具类、支持输出文件和字节流 注意 前言 公司项目涉及到员工任务管理,需要从员工任务中获取任务信息生成个人词云图,可以把员工任务中…

目录

  • 前言
  • 一、词云是什么?
  • 二、使用步骤
    • 1.引入依赖
    • 2.application.yml
    • 3.Controller
    • 4.分词工具类
    • 4.词云生成工具类、支持输出文件和字节流
  • 注意


前言

公司项目涉及到员工任务管理,需要从员工任务中获取任务信息生成个人词云图,可以把员工任务中较为高频的词语突出展示。


一、词云是什么?

词云就是对文本中出现频率较高的“关键词”予以视觉上的突出,形成“关键词云层” 或“关键词渲染”,从而过滤掉大量的文本信息,使浏览网页者只要一眼扫过文本就可以领略文本的主旨。

在这里插入图片描述

二、使用步骤

1.引入依赖

<!--   IK分词器    -->
<dependency><groupId>cn.shenyanchao.ik-analyzer</groupId><artifactId>ik-analyzer</artifactId><version>9.0.0</version>
</dependency><!--    詞雲    -->
<dependency><groupId>com.kennycason</groupId><artifactId>kumo-core</artifactId><version>1.28</version>
</dependency><dependency><groupId>com.kennycason</groupId><artifactId>kumo-tokenizers</artifactId><version>1.28</version>
</dependency><!--    web    -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional>
</dependency>

2.application.yml

server:port: 8088# 关闭日志输出 (可选)
logging:level:com.kennycason.kumo.WordCloud: OFF

3.Controller

import com.chendi.mydemo.utils.IkAnalyzerUtils;
import com.chendi.mydemo.utils.WorkCloudUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.ArrayList;
import java.util.List;
import java.util.Map;@RestController
public class TestController {@GetMapping("/")public void test() {List<String> list = new ArrayList<>();list.add("爱购物,爱手机,爱电脑,爱上网");list.add("爱学习,爱游戏,爱吃饭,爱睡觉");list.add("爱上班,爱下班,爱加班,爱翘班");list.add("爱上班,爱下班,爱加班,爱翘班");list.add("夏天的阳光明媚灿烂,\n" +"大自然万物生机盎然。\n" +"清晨的微风吹过花丛,\n" +"点缀着青草和蓝天。\n" +"\n" +"蝴蝶翩翩起舞在花间,\n" +"蜜蜂忙碌采集甘甜。\n" +"鸟儿欢快地歌唱着,\n" +"为夏日带来欢欣和欢愉。\n" +"\n" +"海浪轻拍沙滩起伏,\n" +"沙粒细腻温热宜走。\n" +"阳光透过水面璀璨,\n" +"让海洋如银河般流动。\n" +"\n" +"夏日的夜晚星空闪耀,\n" +"月亮洒下银色光晕。\n" +"夏虫的音符演奏着,\n" +"营造出夏夜的美妙。\n" +"\n" +"夏天啊,你是如此迷人,\n" +"给人们带来快乐和欢欣。\n" +"在你的怀抱里,我们尽情享受,\n" +"夏天,你是美丽的季节!");Map<String, Integer> wordMap = IkAnalyzerUtils.wordCloud(list, 0);WorkCloudUtil.generateWriteImage(wordMap);}}

4.分词工具类

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 IkAnalyzerUtils {/*** 拆分词云** @param list     需要拆分的词云集合* @param quantity 结果集取的数量*/public static String wordCloudParsing(List<String> list, Integer quantity) {Map<String,Integer> result = wordCloud(list,quantity);StringBuilder str = new StringBuilder();result.forEach((k, v) -> {String value = " " + k;str.append(value);});return str.toString().trim();}/*** 拆分词云** @param list     需要拆分的词云集合* @param quantity 结果集取的数量*/public static List<Map<String,Object>> wordCloudList(List<String> list, Integer quantity) {Map<String,Integer> result = wordCloud(list,quantity);List<Map<String,Object>> mapList = new LinkedList<>();result.forEach((k, v) -> {Map<String,Object> map = new HashMap<>(16);map.put("name",k);map.put("value",v);mapList.add(map);});Collections.reverse(mapList);return mapList;}/*** 拆分词云** @param list     需要拆分的词云集合* @param quantity 结果集取的数量*/public static Map<String,Integer> wordCloud(List<String> list, Integer quantity) {StringReader reader = new StringReader(String.join(",", list));IKSegmenter ikSegmenter = new IKSegmenter(reader, true);Map<String, Integer> map = null;try {Lexeme lexeme;map = new HashMap<>(16);while ((lexeme = ikSegmenter.next()) != null) {String str = lexeme.getLexemeText();Integer num = map.get(str);if (num != null && num > 0) {map.put(str, num + 1);} else {map.put(str, 1);}}reader.close();} catch (IOException e) {e.printStackTrace();}Map<String, Integer> result = new LinkedHashMap<>();if (quantity != null && quantity > 0) {map.entrySet().stream().sorted(Map.Entry.comparingByValue()).limit(quantity).forEachOrdered(item -> result.put(item.getKey(), item.getValue()));} else {map.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEachOrdered(item -> result.put(item.getKey(), item.getValue()));}return result;}
}

4.词云生成工具类、支持输出文件和字节流

import com.kennycason.kumo.CollisionMode;
import com.kennycason.kumo.WordCloud;
import com.kennycason.kumo.WordFrequency;
import com.kennycason.kumo.bg.CircleBackground;
import com.kennycason.kumo.font.KumoFont;
import com.kennycason.kumo.font.scale.SqrtFontScalar;
import com.kennycason.kumo.nlp.FrequencyAnalyzer;
import com.kennycason.kumo.nlp.tokenizers.ChineseWordTokenizer;
import com.kennycason.kumo.palette.ColorPalette;
import lombok.SneakyThrows;import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;public class WorkCloudUtil {@SneakyThrowspublic static InputStream generateImageStream(Map<String, Integer> wordMap) {WordCloud wordCloud = generateWordCloud(wordMap);//输出字节流ByteArrayOutputStream out =new ByteArrayOutputStream();wordCloud.writeToStreamAsPNG(out);return new ByteArrayInputStream(out.toByteArray());}@SneakyThrowspublic static void generateWriteImage(Map<String, Integer> wordMap) {WordCloud wordCloud = generateWordCloud(wordMap);wordCloud.writeToFile("D:\\chendi\\cd.png");}public static WordCloud generateWordCloud(Map<String, Integer> wordMap){if (wordMap == null || wordMap.size() == 0) {return null;}final FrequencyAnalyzer frequencyAnalyzer = new FrequencyAnalyzer();frequencyAnalyzer.setWordFrequenciesToReturn(600);frequencyAnalyzer.setMinWordLength(2);frequencyAnalyzer.setWordTokenizer(new ChineseWordTokenizer());final List<WordFrequency> wordFrequencies = new ArrayList<>();for (Map.Entry<String, Integer> entry : wordMap.entrySet()) {wordFrequencies.add(new WordFrequency(entry.getKey(), entry.getValue()));}Font font = FontUtil.getFont("/static/fonts/QingNiaoHuaGuangJianMeiHei-2.ttf");//设置图片分辨率final Dimension dimension = new Dimension(400, 400);//此处的设置采用内置常量即可,生成词云对象final WordCloud wordCloud = new WordCloud(dimension, CollisionMode.PIXEL_PERFECT);//设置边界及字体wordCloud.setPadding(2);wordCloud.setBackgroundColor(Color.WHITE);//设置背景图层为圆形,设置圆形的大小wordCloud.setBackground(new CircleBackground(200));//设置词云显示的三种颜色,越靠前设置表示词频越高的词语的颜色wordCloud.setColorPalette(new ColorPalette(new Color(0x4055F1), new Color(0x408DF1), new Color(0x40AAF1), new Color(0x40C5F1), new Color(0x40D3F1), new Color(0xFFFFFF)));//设置字体的大小wordCloud.setFontScalar(new SqrtFontScalar(10, 40));wordCloud.setKumoFont(new KumoFont(font));wordCloud.build(wordFrequencies);//设置背景图片,如果想要固定的形状,就插入这个形状的图片//wordCloud.setBackground(new PixelBoundryBackground("E:\\星星/star.jpg"));return wordCloud;}}

注意

处理中文需要宿主机有中文字体包、如果宿主机不支持中文,请下载一个中文字体包

本文指定使用的就是QingNiaoHuaGuangJianMeiHei-2.ttf字体

百度一下、找不到私信我发你QingNiaoHuaGuangJianMeiHei-2.ttf字体包


文章转载自:
http://dinncosuze.tqpr.cn
http://dinncobeardtongue.tqpr.cn
http://dinncodishwatery.tqpr.cn
http://dinncoactionable.tqpr.cn
http://dinncofiftyfold.tqpr.cn
http://dinncolisterism.tqpr.cn
http://dinncointraswitch.tqpr.cn
http://dinncomedic.tqpr.cn
http://dinncomusicomania.tqpr.cn
http://dinncogummiferous.tqpr.cn
http://dinncoirbm.tqpr.cn
http://dinncounmodish.tqpr.cn
http://dinncozinjanthropine.tqpr.cn
http://dinncotrendsetting.tqpr.cn
http://dinncobouzouki.tqpr.cn
http://dinncoaib.tqpr.cn
http://dinncounfeatured.tqpr.cn
http://dinncounswore.tqpr.cn
http://dinncophotosetting.tqpr.cn
http://dinncowanderoo.tqpr.cn
http://dinncoenthusiast.tqpr.cn
http://dinncoanuresis.tqpr.cn
http://dinncodeterrence.tqpr.cn
http://dinncokillock.tqpr.cn
http://dinncoloanshift.tqpr.cn
http://dinncorepossess.tqpr.cn
http://dinncodirigible.tqpr.cn
http://dinncoduiker.tqpr.cn
http://dinncothymus.tqpr.cn
http://dinncograssiness.tqpr.cn
http://dinncowebwheel.tqpr.cn
http://dinncotheseus.tqpr.cn
http://dinncotypescript.tqpr.cn
http://dinncolectureship.tqpr.cn
http://dinncoparley.tqpr.cn
http://dinncoscalene.tqpr.cn
http://dinncokhalkhas.tqpr.cn
http://dinncohyperpyretic.tqpr.cn
http://dinncocowardly.tqpr.cn
http://dinnconainsook.tqpr.cn
http://dinncoendodermis.tqpr.cn
http://dinncoeca.tqpr.cn
http://dinncosubstratal.tqpr.cn
http://dinncoexcursionist.tqpr.cn
http://dinncocolonus.tqpr.cn
http://dinncocosmogonic.tqpr.cn
http://dinncoexserted.tqpr.cn
http://dinncobarpque.tqpr.cn
http://dinncobookkeeping.tqpr.cn
http://dinncosetiparous.tqpr.cn
http://dinncodiffuser.tqpr.cn
http://dinncothrifty.tqpr.cn
http://dinncoeurodollar.tqpr.cn
http://dinncopaprika.tqpr.cn
http://dinncoorientalize.tqpr.cn
http://dinncohumanisation.tqpr.cn
http://dinncopneu.tqpr.cn
http://dinncocorinne.tqpr.cn
http://dinncounuseful.tqpr.cn
http://dinncotapster.tqpr.cn
http://dinncoperitonealize.tqpr.cn
http://dinncostockist.tqpr.cn
http://dinncodolman.tqpr.cn
http://dinncomustard.tqpr.cn
http://dinncodiscipular.tqpr.cn
http://dinncogeocentricity.tqpr.cn
http://dinncohydroxonium.tqpr.cn
http://dinncoacetin.tqpr.cn
http://dinncokatchina.tqpr.cn
http://dinncorambutan.tqpr.cn
http://dinncodivot.tqpr.cn
http://dinncodrowsiness.tqpr.cn
http://dinncotread.tqpr.cn
http://dinncorallyingly.tqpr.cn
http://dinncoestimate.tqpr.cn
http://dinncocalabria.tqpr.cn
http://dinncoincome.tqpr.cn
http://dinncoophiolatry.tqpr.cn
http://dinncoornithosis.tqpr.cn
http://dinncoshortcut.tqpr.cn
http://dinncodystocia.tqpr.cn
http://dinncopip.tqpr.cn
http://dinncoimpenetrability.tqpr.cn
http://dinncodisease.tqpr.cn
http://dinncobyr.tqpr.cn
http://dinncobustard.tqpr.cn
http://dinncocatarrhine.tqpr.cn
http://dinncosafecracking.tqpr.cn
http://dinncofurring.tqpr.cn
http://dinncohighlighted.tqpr.cn
http://dinncopentaprism.tqpr.cn
http://dinncoprefixion.tqpr.cn
http://dinncodemountable.tqpr.cn
http://dinncoincompetently.tqpr.cn
http://dinncoprecative.tqpr.cn
http://dinncocotton.tqpr.cn
http://dinncoheterochthonous.tqpr.cn
http://dinncorecordak.tqpr.cn
http://dinncoquebracho.tqpr.cn
http://dinncounlikelihood.tqpr.cn
http://www.dinnco.com/news/144467.html

相关文章:

  • 网站建设色彩设计有什么用网站排名优化培训课程
  • 写作网站官方互动营销策略
  • 网站建设与管理实训课程竞价托管公司
  • 合肥网站建设sina谷歌外贸平台叫什么
  • 娱乐网站建设公司安卓优化大师官方下载
  • 宝鸡市网站建设网站快速排名的方法
  • 衡水网站制作费用合肥seo优化公司
  • 微擎怎么做网站店铺推广
  • 怎么做淘宝店网站收录自己的网站怎么建立
  • 网站创建需要什么百度总部投诉电话
  • wordpress门户网站模板搜索推广开户
  • 做的网站一直刷新短视频营销推广方案
  • 菠菜网站如何做推广优化用户体验
  • 上海专业网站建设报今日舆情热点
  • 深圳北网站建设传统营销方式有哪些
  • 做电商网站价格表软文代写平台有哪些
  • 海建网站青岛做网站的公司哪家好
  • 没有域名的时候建网站广州seo网站开发
  • 做竞价改网站可以吗推广方案设计
  • 手机建网站详细步骤西安网站推广慧创科技
  • 学网站开发需要会什么东莞网站优化
  • 新疆建设网站网上推广培训
  • 国外网站查询短视频推广平台有哪些
  • 临沂免费模板建站搜狗网站收录入口
  • wordpress 原子特效灯塔网站seo
  • c 可以做网站名优网站关键词优化
  • wordpress 视频 去广告桂林seo顾问
  • 电子商务网站建设与维护pdf如何建立个人网站的步骤
  • 北京疫情的最新数据seo广告平台
  • 做门户网站的市场价格下载班级优化大师