顶会热词统计

Posted nyar

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了顶会热词统计相关的知识,希望对你有一定的参考价值。

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();

}

}

}

 

}

 

以上是关于顶会热词统计的主要内容,如果未能解决你的问题,请参考以下文章

6月20日 顶会热词统计

08顶会热词统计-补

原型设计(顶会热词统计)

顶会热词分析

cvpr顶会热词爬取

Lucene热词统计