Exemplo n.º 1
0
 public static void setTotal() {
   try {
     String sql =
         "select count(*) count from "
             + "(SELECT ra.fileId, ra.reviewId, ra.reviewType from "
             + "ReviewFeatureAnalysis ra group by ra.fileId, ra.reviewId)  r "
             + "where r.reviewType = 1 or r.reviewType = 2";
     System.out.println(sql);
     intTotal = Database.getInteger(sql);
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Exemplo n.º 2
0
  public NaiveBayes(int leaveOutFileId) {
    // initiate counters
    Parameters parameters = new Parameters();
    Database.setInitialParameters(leaveOutFileId, parameters);
    intTotal = parameters.getTotal();
    intDislikes = parameters.getDislikes();
    intLikes = parameters.getLikes();

    //	   setTotal(leaveOutFileId);
    //	   setLikes(leaveOutFileId);
    //	   setDislikes(leaveOutFileId);
    countLikes = getMap(leaveOutFileId, 1);
    countDislikes = getMap(leaveOutFileId, 2);

    dPrioLike = (double) intLikes / (double) intTotal;
    dPrioDislike = (double) intDislikes / (double) intTotal;
  }
Exemplo n.º 3
0
  // --------------------------------------------------
  private HashMap<String, Integer> getMap(int leaveOutFileId, int Type) {
    // ---------------------------------------------------
    // nb this not include leave one out
    String sql = "Select reviewType, featureId, value, count(*) count  from ReviewFeatureAnalysis ";
    if (leaveOutFileId != 0) sql = sql + " where fileId <> " + leaveOutFileId;

    sql = sql + " group by reviewType, featureId, value";
    // System.out.println("GetMap : Sql : " + sql);
    String key = "";
    Integer value;
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    Connection conn = Database.getDBConnection();

    java.sql.Statement st;

    try {
      st = conn.createStatement();
      ResultSet rs = st.executeQuery(sql);
      while (rs.next()) {
        int type = rs.getInt("reviewType");
        if (type == Type) {
          key = rs.getString("featureId") + "_" + rs.getString("value");
          value = rs.getInt("count");
          // System.out.println("Key " + key + " value : " + value);

          map.put(key, new Integer(value));
        }
      }

      st.close();
      return map;
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return map;
    }
  }