コード例 #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
  public void generateWekaFile(ArrayList<MyTerm> myTerms, int maxDocNum, String wekaFilePath)
      throws IOException {

    String text = "@relation interest\n";
    text += "@attribute text string\n";
    for (int i = 0; i < maxDocNum; i++) {
      text += "@attribute doc" + i + "\treal\n";
    }
    text += "@data\n";
    for (int j = 0; j < myTerms.size(); j++) {
      MyTerm term = myTerms.get(j);
      String line = "";
      line += term.originTrem.text();
      for (int i = 0; i < term.vector.length; i++) {
        line += "," + term.vector[i];
      }
      line += "\n";
      text += line;
    }
    // System.out.println(text);
    PrintWriter Pout = new PrintWriter(new FileWriter(wekaFilePath));
    Pout.println(text);
    Pout.close();
  }