《软件工程》结对作业2----顶会热词统计
1.要求:
小樱是一名大三的学生,一直痴迷于吃鸡类游戏,某日听闻同宿舍的小狼刚和导师去参加了CVPR会议,内心羡慕不已,便下定决心痛改前非、努力钻研,希望能在毕业前完成一篇站在时代前沿的优秀论文。但令人苦恼的是,她不知道近几年顶会的热门领域和研究方向,根据论文列表去一篇一篇查找总结效率又着实太低。 她于是求助于“软工实践互助爱心组织”,希望我们能帮助他设计一个解决方案。 满足她现阶段的需求。 这个解决方案可以是网页/APP/桌面程序/... 由你来设计最合适的形态。
用户可给定论文列表 ◦通过论文列表,爬取论文的题目、摘要、关键词、原文链接;
可对论文列表进行增删改操作(今年、近两年、近三年);
•对爬取的信息进行结构化处理,分析top10个热门领域或热门研究方向;可进行论文检索,当用户输入论文编号、题目、关键词等基本信息,分析返回相关的paper、source code、homepage等信息
形成如关键词图谱之类直观的查看方式;
•可对多年间、不同顶会的热词呈现热度走势对比(这里将范畴限定在计算机视觉的三大顶会CVPR、ICCV、ECCV内)。
2.截图:
3.代码
paper.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>CVPR-2019词云</title> <link href="./css/bootstrap.css" rel="stylesheet"> <script src="./js/jquery-1.8.3.min.js"></script> <script src="./js/bootstrap.js"></script> <script type="text/javascript" src="./js/echarts.min.js"></script> <script type="text/javascript" src="./js/echarts-wordcloud.js"></script> </head> <style> html, body, #main { width: 100%; height: 100%; margin: 0; } </style> <body> <div id="main"></div> <div> <table class="table" style="font-size:20px"> <tr> <td>原文链接</td> </tr> <c:forEach items="${list}" var="info"> <tr> <td><a href="${info.paper_url}">${info.paper_title}</a></td> </tr> </c:forEach> </table> </div> </body> <script type="text/javascript"> window.onload = function(){ $.ajax({ url:"PaperServlet?method=Paper", async : true , type : "POST", dataType : "json", success : function(data){ var dt; var mydata = new Array(); dt = data; for(var i=0;i<dt.length;i++){ var d = {}; d['name'] = dt[i].name; d['value'] = dt[i].value; mydata.push(d); } var option = { title:{ text:'CVPR-2019词云', x:'center', textStyle:{ fontSize:20 } }, backgroundColor:'#F7F7F7', tooltip:{ show:true }, series: [{ type: 'wordCloud', gridSize:2, sizeRange: [20, 50],//画布范围,如果设置太大会出现少词(溢出屏幕) rotationRange: [-90, 90],//数据翻转范围 shape: 'circle', drawOutOfBound:false, 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: mydata }] }; var chart = echarts.init(document.getElementById('main')); chart.setOption(option); chart.on('click',function(params){ var url = "PaperServlet?method=Search&name="+params.name; window.location.href = url; }); }, error : function(){ alert("请求失败"); }, }); } </script> </html> PaperServlet.java package Servlet; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.ArrayUtils; import com.google.gson.Gson; import Bean.Paper; import Bean.Word; import Dao.Select; /** * Servlet implementation class PaperServlet */ @WebServlet("/PaperServlet") public class PaperServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public PaperServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String method = request.getParameter("method"); if(method.equals("Paper")) { Paper(request, response); }else if(method.equals("Search")){ Search(request, response); } } private void Search(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // TODO Auto-generated method stub String name=request.getParameter("name"); Select s = new Select(); List<Paper> list = s.listAllWord(name); request.setAttribute("list",list); request.getRequestDispatcher("paper.jsp").forward(request, response); } private void Paper(HttpServletRequest request, HttpServletResponse response) throws IOException { // TODO Auto-generated method stub response.setCharacterEncoding("UTF-8"); Select s = new Select(); List<Paper> paperlist = s.GetPaper(); List<Word> wordlist = new ArrayList<Word>(); String[] names = new String[100000]; for(Paper paper:paperlist) { String name = paper.getPaper_title(); String[] namestemp = name.split(" "); names = (String[]) ArrayUtils.addAll(namestemp,names); } HashMap<String,Integer> name_value = new HashMap<>(); for(String name:names) { name_value.put(name,!name_value.containsKey(name)?1:name_value.get(name)+1); } for(String name:name_value.keySet()) { Word word = new Word(); if(name!=null&&(name_value.get(name)>1)&&(name.length()>4)) { word.setName(name); word.setValue(name_value.get(name)); wordlist.add(word); } } Gson gson = new Gson(); String json = gson.toJson(wordlist); response.getWriter().write(json); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } } Select.java package Dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import Bean.Paper; import utils.DBUtil; public class Select { public List<Paper> GetPaper() { // TODO Auto-generated method stub ArrayList<Paper> list = new ArrayList<>(); Connection conn=DBUtil.getConn(); Statement state = null; String sql="select * from cvpr_2019"; System.out.println(sql); try { state = conn.createStatement(); ResultSet rs = state.executeQuery(sql); while (rs.next()) { Paper p = new Paper(); p.setId(rs.getInt(1)); p.setPaper_title(rs.getString(2)); p.setPaper_abstract(rs.getString(3)); p.setPaper_url(rs.getString(4)); list.add(p); } } catch (Exception e) { e.printStackTrace(); } finally { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } return list; } public List<Paper> listAllWord(String name) { // TODO Auto-generated method stub // TODO Auto-generated method stub ArrayList<Paper> list = new ArrayList<>(); Connection conn=DBUtil.getConn(); Statement state = null; String sql="select * from cvpr_2019 where title like "+"'%"+name+"%'"; System.out.println(sql); try { state = conn.createStatement(); ResultSet rs = state.executeQuery(sql); while (rs.next()) { Paper p = new Paper(); p.setId(rs.getInt(1)); p.setPaper_title(rs.getString(2)); p.setPaper_abstract(rs.getString(3)); p.setPaper_url(rs.getString(4)); list.add(p); } } catch (Exception e) { e.printStackTrace(); } finally { try { conn.close(); } catch (Exception e) { e.printStackTrace(); } } return list; } } paper.java package Bean; public class Paper { private int id; private String paper_title; private String paper_abstract; private String paper_url; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getPaper_title() { return paper_title; } public void setPaper_title(String paper_title) { this.paper_title = paper_title; } public String getPaper_abstract() { return paper_abstract; } public void setPaper_abstract(String paper_abstract) { this.paper_abstract = paper_abstract; } public String getPaper_url() { return paper_url; } public void setPaper_url(String paper_url) { this.paper_url = paper_url; } } word.java package Bean; public class Word { private String name; private int value; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } } DBUtil.java package utils; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DBUtil { public static String db_url = "jdbc:mysql://localhost:3306/paper?useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT"; public static String db_user = "root"; public static String db_pass = "root"; public static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); conn = DriverManager.getConnection(db_url, db_user, db_pass); } catch (Exception e) { e.printStackTrace(); } return conn; } public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }