mysql数据生成词云图_CVPR2018关键字分析生成词云图与查找
今日目标:爬取CVPR2018论文,进行分析总结出提到最多的关键字,生成wordCloud词云图展示,并且设置点击后出现对应的论文以及链接
对任务进行分解:
①爬取CVPR2018的标题,简介,关键字,论文链接
②将爬取的信息生成wordCloud词云图展示
③设置点击事件,展示对应关键字的论文以及链接
一、爬虫实现
由于文章中并没有找到关键字,于是将标题进行拆分成关键字,用逗号隔开
import requests
from bs4 import BeautifulSoup
import demjson
import pymysql
import os
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'}#创建头部信息
url='http://openaccess.thecvf.com/CVPR2018.py'
r=requests.get(url,headers=headers)
content=r.content.decode('utf-8')
soup = BeautifulSoup(content, 'html.parser')
dts=soup.find_all('dt',class_='ptitle')
hts='http://openaccess.thecvf.com/'
#数据爬取
alllist=[]
for i in range(len(dts)):
print('这是第'+str(i)+'个')
title=dts[i].a.text.strip()
href=hts+dts[i].a['href']
r = requests.get(href, headers=headers)
content = r.content.decode('utf-8')
soup = BeautifulSoup(content, 'html.parser')
#print(title,href)
divabstract=soup.find(name='div',attrs={"id":"abstract"})
abstract=divabstract.text.strip()
#print('第'+str(i)+'个:',abstract)
alllink=soup.select('a')
link=hts+alllink[4]['href'][6:]
keyword=str(title).split(' ')
keywords=''
for k in range(len(keyword)):
if(k==0):
keywords+=keyword[k]
else:
keywords+=','+keyword[k]
value=(title,abstract,link,keywords)
alllist.append(value)
print(alllist)
tuplist=tuple(alllist)
#数据保存
db = pymysql.connect("localhost", "root", "fengge666", "yiqing", charset='utf8')
cursor = db.cursor()
sql_cvpr = "INSERT INTO cvpr values (%s,%s,%s,%s)"
try:
cursor.executemany(sql_cvpr,tuplist)
db.commit()
except:
print('执行失败,进入回调3')
db.rollback()
二、将数据进行wordCloud展示
首先找到对应的包,来展示词云图
然后通过异步加载,将后台的json数据进行展示。
由于第一步我们获得的数据并没有对其进行分析,因此我们在dao层会对其进行数据分析,找出所有的关键字的次数并对其进行降序排序(用Map存储是最好的方式)
public Mapgetallmax()
{
String sql="select * from cvpr";
Mapmap=new HashMap();
Mapsorted=new HashMap();
Connection con=null;
Statement state=null;
ResultSet rs=null;
con=DBUtil.getConn();try{
state=con.createStatement();
rs=state.executeQuery(sql);while(rs.next())
{
String keywords=rs.getString("keywords");
String[] split= keywords.split(",");for(int i=0;i
{if(map.get(split[i])==null)
{
map.put(split[i],0);
}else{
map.replace(split[i], map.get(split[i])+1);
}
}
}
}catch(SQLException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
DBUtil.close(rs, state, con);
sorted=map
.entrySet()
.stream()
.sorted(Collections.reverseOrder(comparingByValue()))
.collect(
toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2)->e2,
LinkedHashMap::new));returnsorted;
}
到servlet层后,我们还需对数据进行一定的筛选(介词,a,等词语应该去除掉,要不然会干扰我们分析关键字),取前30名关键字,在前台进行展示
aracterEncoding("utf-8");
MapsortMap=dao.getallmax();
JSONArray json=newJSONArray();int k=0;for (Map.Entryentry : sortMap.entrySet())
{
JSONObject ob=newJSONObject();
ob.put("name", entry.getKey());
ob.put("value", entry.getValue());if(!(entry.getKey().equals("for")||entry.getKey().equals("and")||entry.getKey().equals("With")||entry.getKey().equals("of")||entry.getKey().equals("in")||entry.getKey().equals("From")||entry.getKey().equals("A")||entry.getKey().equals("to")||entry.getKey().equals("a")||entry.getKey().equals("the")||entry.getKey().equals("by")))
{
json.add(ob);
k++;
}if(k==30)break;
}
System.out.println(json.toString());
response.getWriter().write(json.toString());
三、设置点击事件,展示对应关键字的论文以及链接
//设置点击效果 var ecConfig = echarts.config; myChart.on('click', eConsole);
用函数来实现点击事件的内容:通过点击的关键字,后台进行模糊查询,找到对应的论文题目以及链接,返回到前端页面
function eConsole(param) {if (typeof param.seriesIndex == 'undefined') {return;
}if (param.type == 'click') {var word=param.name;var htmltext="
$.post('findkeytitle',
{'word':word},
function(result)
{
json=JSON.parse(result);for(i=0;i
{
htmltext+="
"+json[i].Title+"";
}
htmltext+="
"$("#show").html(htmltext);
}
)
}
}
成果展示:
前台页面代码:
background-color: black;
}
#main {
width:70%;
height:100%;
margin:0;float:right;
background: black;
}
#show{
overflow-x: auto;
overflow-y: auto;
width:30%;
height:100%;float:left;
margin-top:100dp;
padding-top:100dp;
background: pink;
}
echartsCloud();
});//点击事件
function eConsole(param) {if (typeof param.seriesIndex == 'undefined') {return;
}if (param.type == 'click') {var word=param.name;var htmltext="
$.post('findkeytitle',
{'word':word},
function(result)
{
json=JSON.parse(result);for(i=0;i
{
htmltext+="
"+json[i].Title+"";
}
htmltext+="
"$("#show").html(htmltext);
}
)
}
}
function echartsCloud(){
$.ajax({
url:"getmax",
type:"POST",
dataType:"JSON",async:true,
success:function(data)
{var mydata = new Array(0);for(var i=0;i
{var d ={
};
d["name"] = data[i].name;//.substring(0, 2);
d["value"] =data[i].value;
mydata.push(d);
}var myChart = echarts.init(document.getElementById('main'));//设置点击效果
var ecConfig =echarts.config;
myChart.on('click', eConsole);
myChart.setOption({
title: {
text:''},
tooltip: {},
series: [{
type :'wordCloud', //类型为字符云
shape:'smooth', //平滑
gridSize : 8, //网格尺寸
size : ['50%','50%'],//sizeRange : [ 50, 100 ],
rotationRange : [-45, 0, 45, 90], //旋转范围
textStyle : {
normal : {
fontFamily:'微软雅黑',
color: function() {return 'rgb(' +Math.round(Math.random()* 255) +
',' + Math.round(Math.random() * 255) +
',' + Math.round(Math.random() * 255) + ')'}
},
emphasis : {
shadowBlur :5, //阴影距离
shadowColor : '#333' //阴影颜色
}
},
left:'center',
top:'center',
right:null,
bottom:null,
width:'100%',
height:'100%',
data:mydata
}]
});
}
});
}
mysql数据生成词云图_CVPR2018关键字分析生成词云图与查找相关推荐
- 3、mysql索引优化一:Explain关键字分析
作为一个Java开发,在我们日常工作中,对于mysql的使用中涉及最多的恐怕就是写SQL了,一定遇到过sql执行慢的问题,那么SQL优化工作就显得格外重要.有了对mysql执行过程以及索引实现原理了解 ...
- MongoDB 实战(一)基于PyMongo的电影影评分析 | 对数据结果进行可视化展示以及分析 | 评论词云 | 分时间段分析
文章目录 一.运行环境 二.实战介绍 三.获取数据 四.PyMongo 实战 4.1 连接MongoDB.创建集合 4.2 向 MongoDB 插入文档 4.3 查询MongoDB的数据 4.4 同样 ...
- php实现关键字搜索mysql数据_php搜索并显示关键字的例子
代码如下: 复制代码 代码示例: /** * 搜索并显示关键字,红色字体 * edit by www.jbxue.com */ require_once 'db.class.php';//封装类,可执 ...
- python文本聚类 词云图_数据思维实践 | TASK 12 文本分析
原标题:数据思维实践 | TASK 12 文本分析 文本分析可以干什么 生活中文本无处不在,网页上的新闻.证券分析师的研究报告.政府工作报告等等,这些都是文本.如何从文本中挖掘价值是文本分析需要回答的 ...
- mysql 数据展示装置_实时生成数据宽表的方法和装置与流程
本发明涉及计算机技术领域,尤其涉及一种实时生成数据宽表的方法和装置. 背景技术: 数据仓库是面向主题的.集成的.相对稳定的.随时间不短变化得数据集合,用以支持经营管理中的决策制定.数据仓库中的数据面向 ...
- 基于图数据的研报词关联之聚合分析
基于图数据的研报词关联之聚合分析 基于图数据的研报关键词聚合分析 一.算法介绍 二.数据模型 三.计算关键词上下文聚合相似性 四.关键词上下文聚合性能测试 五.计算聚合相似性[CYPHER优化] 六. ...
- Mysql(软件安装、Mysql基本语法、Mysql数据操作、Mysql关键字、约束、多表查询、Mysql多表查询、数据备份、数据导入、视图)
1.MySQL介绍 1.1数据库介绍 数据库概念 数据库就是用于存储数据的一个空间 数据存储方式的发展史 甲骨文(材料太昂贵) 竹简(太沉了,运输不方便) 纸(易损坏) 计算机(办公软件,传输不方便) ...
- mysql数据表数据丢失6_MYSQL数据表损坏的原因分析和修复方法小结
MYSQL数据表损坏的原因分析和修复方法小结 1.表损坏的原因分析 以下原因是导致mysql 表毁坏的常见原因: 1. 服务器突然断电导致数据文件损坏. 2. 强制关机,没有先关闭mysql 服务. ...
- 【R语言文本挖掘】:情感分析与词云图绘制
[R语言文本挖掘]:情感分析与词云图绘制
最新文章
- 【踩坑之旅】-webpack (v4.8.1) + vue-cli (v2.5.3)升级准备
- Ubuntu16安装CUDA9.0+Anaconda+Tensorflow1.8GPU(2018.08.20最新)
- mysql 2进制 安装_mysql二进制安装
- 中国存储器行业应用趋势与投资机遇研究报告2022版
- 多语言报表的改动方法
- Linux学习第五篇之文件处理命令touch、cat、tac、more、less、head、tail
- android menuitem 字体颜色,安卓更改Menu的字体颜色(使用actionLayout,适用于多个fragment)...
- rpc:call/4函数解析
- 37. 错误与异常处理(1)
- 学习Cocos2d的博客 --推荐
- ATP-EMTP电缆LCC模型中相数与电缆数的设置
- Shel编程之条件语句 条件 if ,case语句
- 7款浏览器新标签页扩展让你的Chrome耳目一新
- micropython移植stm32f746_STM32L476和STM32F746的外部Flash复制文件速度对比
- 常用ADB命令模拟手机按键
- linux insert最后一行,insert基础用法及进阶
- ThreadLocal实战之数据库执行器线程同步
- [论文阅读1]Re-identification with RGB-D sensors
- python作业:学生成绩表数据包括:学号、姓名,高数、英语和计算机3门课成绩
- Unity 在Mac上打包,执行python报Win32Exception的解决方案
热门文章
- 2017.10.29 软件安装 思考记录
- 2017.10.10 狼和羊的故事 思考记录
- 【英语学习】【English L06】U04 Adventure L3 The city playground and some famous museums
- 【英语学习】【Daily English】U05 Places L01 How can I get to the city museum?
- Azkaban 进程和任务监控(任务状态从MySQL同步到SqlServer)
- python fortran混合编程输入矩阵_如何将动态数组从Python传递到Fortran动态链接库
- anywhere执行时端口被占用Address already in use:8080解决方法
- SpringMVC系列(九)自定义视图、重定向、转发
- Oracle11g 统计信息——统计信息自动收集任务
- 接口(interface)和抽象(abstract)类的区别