08顶会热词统计
要求:
对爬取的信息进行结构化处理,分析top10个热门领域或热门研究方向;可进行论文检索,当用户输入论文编号、题目、关键词等基本信息,分析返回相关的paper、source code、homepage等信息
形成如关键词图谱之类直观的查看方式;
可对多年间、不同顶会的热词呈现热度走势对比(这里将范畴限定在计算机视觉的三大顶会CVPR、ICCV、ECCV内)。
代码:
import pymysql
import query as query
from flask import Flask, jsonify, render_template, request, url_for, redirect
app = Flask(__name__)
def get_conn():
conn = pymysql.Connect(
host='localhost',
port=3306,
user='root',
passwd='123456',
db='reci',
charset='utf8'
)
cursor = conn.cursor()
return conn, cursor
def close_conn(conn, cursor):
cursor.close
conn.close
def query(sql, *args):
conn, cursor = get_conn()
cursor.execute(sql, args)
res = cursor.fetchall()
close_conn(conn, cursor)
return res
@app.route('/bbb')
def hello_world2():
return render_template("yun.html")
@app.route('/kkk')
def hello_world3():
sql = "select * from reci2 order by id asc limit 20"
res = query(sql)
l1 = len(res)
d = []
for i in range(0, l1):
d.append({"name": res[i][0], "value": res[i][2]})
return jsonify({"ksw": d})
@app.route('/display')
def display():
print ("aaaaaaaaaaaa")
params = request.values.get("paper")
params = params.capitalize()
sql = "SELECT * FROM reci WHERE title LIKE '%%%%%s%%%%'" % params
print (sql)
res = query(sql)
l1 = len(res)
print(l1)
d = []
for i in range(0, l1):
d.append([res[i][2], res[i][3], res[i][4], res[i][1]])
return jsonify({"paper": d})
if __name__ == '__main__':
app.run()
<html>
<head>
<meta charset="utf-8">
<script src='https://cdn.bootcss.com/echarts/3.7.0/echarts.simple.js'></script>
<script src='../static/js/echarts-wordcloud.min.js'></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<style>
html, body, #main {
width: 100%;
height: 100%;
margin: 0;
}
</style>
<div id='main'></div>
<div id="display"></div>
<script>
function take(){
$.ajax({
url:"/kkk",
success:function (data) {
option.series[0].data=data["ksw"]
chart.setOption(option);
window.onresize = chart.resize;
}
})
}
take()
chart = echarts.init(document.getElementById('main'));
option = {
tooltip: {},
series: [{
type: 'wordCloud',
gridSize: 2,
sizeRange: [12, 50],
rotationRange: [-90, 90],
shape: 'pentagon',
width: 600,
height: 400,
drawOutOfBound: true,
textStyle: {
normal: {
color: function () {
return 'rgb(' + [
Math.round(Math.random() * 160),
Math.round(Math.random() * 160),
Math.round(Math.random() * 160)
].join(',') + ')';
}
},
emphasis: {
shadowBlur: 10,
shadowColor: '#333'
}
},
data: []
}]
}
chart.on('click', function (params) {
$.get("/display",{paper:params["name"]},function(data){
var loveStr = "";
for (let i = 0; i < data["paper"].length; i++) {
loveStr += `<div><div> 标题:${data["paper"][i][0]} </div><br/>`+
`<div> 摘要:${data["paper"][i][1]} </div><br/>`+
`<div> 作者:${data["paper"][i][2]} </div><br/>`+
`<a href="${data["paper"][i][3]}"> 链接 </a></div><br/><br/>`
};
//拼接完字符串数组后用innerHTML把它渲染到页面中
document.getElementById("display").innerHTML = loveStr;
})
});
</script>
</body>
</html>
运行截图展示: