Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.factual.data_science_toolkit;
 
 
 import  org.json.JSONException;
 import  org.json.JSONObject;
 
Provides a wrapper to Data Science Toolkit's public API.

Author(s):
aaron
public class DataScienceToolkit {
  private static final HttpRequestFactory REQ_FACTORY = new NetHttpTransport().createRequestFactory();
  private final String home = "http://www.datasciencetoolkit.org/";


  
Queries the Data Science Toolkit for the coordinates of a location specified with text.

text might be something like "12001 Chalon los angeles ca".

Parameters:
text free form text including information about a desired location, e.g. city name, zip code, etc.
Returns:
the matching coordinate data from the Data Science Toolkit, or null if no match.
  public Coord streetToCoord(String text) {
    GenericUrl url = new GenericUrl( + "street2coordinates/");
    url.appendRawPath(text);
    BufferedReader br = null;
    try {
      HttpRequest request = .buildGetRequest(url);
      br = new BufferedReader(new InputStreamReader(request.execute().getContent()));
      JSONObject rootJsonObj = new JSONObject(br.readLine());
      String key = rootJsonObj.keys().next().toString();
      Object hit = rootJsonObj.get(key);
      if(hit instanceof JSONObject) {
        return new Coord((JSONObject) hit);
      } else {
        return null;
      }
    } catch (IOException e) {
      throw new FactualApiException(e);
    } catch (JSONException e) {
      throw new FactualApiException(e);
    } finally {
      Closeables.closeQuietly(br);
    }
  }
New to GrepCode? Check out our FAQ X