示例#1
0
  public boolean savetomysql(int topicid, List<String[]> list) {

    boolean flag = false;
    JdbcUtils db = new JdbcUtils();
    db.getConnection();
    String del = "delete from emotion where topicid=?";
    List<Object> delparams = new ArrayList<Object>();
    delparams.add(topicid);
    try {
      db.updateBypreparedPreparedStatement(del, delparams);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    String sql =
        "insert into emotion(topicid ,content,emotionalcategory,confidence) values (?,?,?,?)";
    for (int i = 0; i < list.size(); i++) {
      List<Object> addparams = new ArrayList<Object>();
      addparams.add(topicid);
      addparams.add(list.get(i)[2]);
      addparams.add(list.get(i)[0]);
      addparams.add(list.get(i)[1]);
      try {
        flag = db.updateBypreparedPreparedStatement(sql, addparams);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return flag;
  }
示例#2
0
  @Override
  public void run() {
    // TODO Auto-generated method stub

    final String[] crawlerArgs = {
      searchwords, htmlpath, txtpath, xmlpath, ippath + "/plainIPs.txt", pagecount
    };

    int ifCrawlFlag = 0;

    if (ifCrawlFlag == 0) {
      try {
        Crawler c = new Crawler();
        c.excute(crawlerArgs, dir);
      } catch (IOException | URISyntaxException | InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    //
    System.out.println("now begin to classify the file:");
    emoClassifyUnity emo = new emoClassifyUnity();
    List<String[]> list2 = emo.emoClassify("./mycraw/" + dir + "/" + searchwords + ".xml");
    // save the  topic

    JdbcUtils db = new JdbcUtils();
    db.getConnection();
    String sql = "insert into topic(topic ,topicdescription,pdate) values (?,?,?)";
    String deltopicid = "delete from topic where topic=?";

    //
    List<Object> paramsdel = new ArrayList<Object>();
    paramsdel.add(topiclist[0]);
    try {
      db.updateBypreparedPreparedStatement(deltopicid, paramsdel);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //
    System.out.println(topiclist[0] + "---->>>" + topiclist[1]);
    List<Object> params = new ArrayList<Object>();
    params.add(topiclist[0]);
    params.add(topiclist[1]);
    java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
    params.add(currentDate);
    try {
      db.updateBypreparedPreparedStatement(sql, params);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    db.releasecon();
    //
    savetomysql(gettopicid(searchwords), list2);
    //
    String info = topiclist[0] + ":结束下载,分词,结果保存在数据库内";
    logwrite.write("./timerlog.txt", info);
  }