示例#1
0
  /** @param args */
  public static void main(String[] args) {
    SingleUserAnalyse sua = new SingleUserAnalyse("胡新辰点点点", "usr.txt");
    LuceneAnalyser ts = new LuceneAnalyser();
    try {
      String semiFile = "C:\\Users\\Edward\\Desktop\\semi.txt";
      String resultFile = "C:\\Users\\Edward\\Desktop\\result.txt";
      // PrintWriter Pout = new PrintWriter(new FileWriter(semiFile));
      // JSONObject semiData = sua.getIndexData();
      // Pout.println(semiData.toString());
      // Pout.close();

      File input = new File(semiFile);
      JSONObject js = new JSONObject(new JSONTokener(new FileReader(input)));

      // js=sua.weightAdjust(js);
      JSONObject result = ts.getKeyWords(js);
      PrintWriter resultOut = new PrintWriter(new FileWriter(resultFile));
      resultOut.println(result.toString());
      resultOut.close();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // TODO Auto-generated method stub

  }
示例#2
0
  @SuppressWarnings("finally")
  public JSONObject getKeyWords(JSONObject semiData) {
    JSONObject keyWords = new JSONObject();

    try {
      this.buildIndex(semiData);
      this.getIndexInfo(this.indexDir, 4);
      this.generateWekaFile(this.termList, this.maxDocNum, this.wekaFile);
      JSONArray array = this.Cluster(this.wekaFile, 7);
      int totalNum = 0;
      for (int i = 0; i < array.length(); i++) {
        totalNum += array.getJSONArray(i).length();
      }
      keyWords.put("maxFreq", this.maxFreq);
      keyWords.put("totalNum", totalNum);
      keyWords.put("WordList", array);
    } catch (WeiboException e) {
      System.out.print("getKeyWords++++++weibo\n");
      System.out.print("error:" + e.getError() + "toString:" + e.toString());
      keyWords.put("error", e.getError());
      e.printStackTrace();
    } catch (Exception e) {
      System.out.print("getKeyWords++++++Exception");
      keyWords.put("error", e.toString());
      e.printStackTrace();
    } finally {
      try {
        this.myDelete(this.indexDir);
        this.myDelete(this.wekaFile);
      } catch (Exception e) {
        e.printStackTrace();
      }
      return keyWords;
    }
  }