/** * @param args * @throws SQLException */ public static void main(String[] args) throws SQLException { // TODO Auto-generated method stub final DBConnection db = new DBConnection(); String minPostNum = "80"; db.getConn(); String sql = ""; String userIDFile = PathConfig.originalDataPath + "USER" + minPostNum + "/user.IDs"; String postFolder = PathConfig.originalDataPath + "USER" + minPostNum + "/posts/"; String askerFolder = PathConfig.originalDataPath + "USER" + minPostNum + "/askers/"; String graphDataFile = PathConfig.originalDataPath + "USER" + minPostNum + "/userVoteWeighted.QAgraph"; ArrayList<String> postLines = new ArrayList<String>(); ArrayList<String> userIDs = new ArrayList<String>(); FileUtil.readLines(userIDFile, userIDs); buildIndexUserID(userIDs); QAGraph = new int[userNum][userNum]; ArrayList<String> askerLines = new ArrayList<String>(); for (int i = 0; i < userNum; i++) { System.out.println("i = " + i); String postFile = postFolder + userIDs.get(i) + ".posts"; // String askerFile = askerFolder + userIDs.get(i) + ".askers"; // if(new File(askerFile).exists()){ // System.out.println(askerFile + "is exists!"); // continue; // } postLines.clear(); FileUtil.readLines(postFile, postLines); askerLines.clear(); // System.out.println("after clear, askerLines size: " + askerLines.size()); for (String postLine : postLines) { String[] postTokens = postLine.split("\t"); if (postTokens[1].equals("2")) { String parentID = postTokens[2]; String askerID = getAuthorIDbyPostID(parentID, db); String vote = postTokens[5]; // System.out.println("vote " + vote); // askerLines.add(askerID); // System.out.println("add, askerLines size: " + askerLines.size()); // Answer count weighted graph if (userIDToIndexMap.containsKey(askerID)) { QAGraph[Integer.valueOf(userIDToIndexMap.get(askerID))][ Integer.valueOf(userIDToIndexMap.get(userIDs.get(i)))] += Integer.valueOf(vote); } } else { // askerLines.add("self"); } } // FileUtil.writeLines(askerFile, askerLines); // System.out.println("before clear, askerLines size: " + askerLines.size()); // System.out.println("after clear, askerLines size: " + askerLines.size()); } printQAGraph(graphDataFile); db.close(); }
private static void printQAGraph(String graphDataFile) { // TODO Auto-generated method stub ArrayList<String> QAGLines = new ArrayList<String>(); for (int i = 0; i < QAGraph.length; i++) { String line = ""; for (int j = 0; j < QAGraph[i].length; j++) { line += QAGraph[i][j] + "\t"; } QAGLines.add(line); } FileUtil.writeLines(graphDataFile, QAGLines); }