0

このクラスを使いたい

https://code.google.com/p/ext-c/source/browse/trunk/src/nz/ac/vuw/ecs/kcassell/similarity/GoogleDistanceCalculator.java

これは私のコードです (私の目的は、すべてのタグ間のペアごとの Google 距離を計算することです)

public static void main(String args[]) throws FileNotFoundException {
   Scanner s = new java.util.Scanner(new File (yyy));
   try {
      GoogleDistanceCalculator googleDistanceCalculator =
         new GoogleDistanceCalculator();
      ArrayList<String>  Alltags = new ArrayList<String>();
      while (s.hasNext()) {
         Alltags.add(s.next());
      }
      ArrayList<Double>  arraysNGD = new ArrayList<Double>();
      for (int i = 0; i < Alltags.size(); i++) {
         for (int j = 0; j < Alltags.size(); j++) {
            if (j!=i)
               arraysNGD.add(
                  googleDistanceCalculator.calculateDistance(
                     Alltags.get(i).trim(), Alltags.get(j).trim()));
         }
      }
   } catch (NumberFormatException e) {
      e.printStackTrace();
   } catch (IOException e) {
      e.printStackTrace();
   }
}

エラー

org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
  at org.json.JSONObject.getJSONObject(JSONObject.java:508)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
  at test.Zssai.main(Zssai.java:55)

注意

たとえば試してみると

googleDistanceCalculator.calculateDistance("forest","plant");

エラーなく正常に動作します

編集

nature  sky
  org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
  at org.json.JSONObject.getJSONObject(JSONObject.java:508)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
  at test.Zssai.main(Zssai.java:51)

nature  blue
  org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
  at org.json.JSONObject.getJSONObject(JSONObject.java:508)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
  at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
at test.Zssai.main(Zssai.java:51)
    nature  water
    org.json.JSONException: JSONObject["responseData"] is not a JSONObject.
at org.json.JSONObject.getJSONObject(JSONObject.java:508)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromGoogleQuery(GoogleDistanceCalculator.java:196)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.getCountFromQuery(GoogleDistanceCalculator.java:173)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.numResultsFromWeb(GoogleDistanceCalculator.java:150)
at nz.ac.vuw.ecs.kcassell.similarity.GoogleDistanceCalculator.calculateDistance(GoogleDistanceCalculator.java:262)
at test.Zssai.main(Zssai.java:51)
    nature  clouds
4

1 に答える 1

0

問題はそれです

ヤフーボスはタダじゃない

Google 検索 API は推奨されていないため、この数を超えると制限数のクエリしか許可されず、エラーが発生します

    org.json.JSONException: JSONObject["responseData"] is not a JSONObject.

この問題を解決するには、他の検索エンジン API を使用する必要があります

この API は役に立つかもしれません

   http://www.sindice.com/
于 2013-04-20T16:18:20.573 に答える