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.

public class DataScienceToolkit {
  private static final HttpRequestFactory REQ_FACTORY = new NetHttpTransport().createRequestFactory();
  private final String home = "";

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

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

text free form text including information about a desired location, e.g. city name, zip code, etc.
the matching coordinate data from the Data Science Toolkit, or null if no match.
  public Coord streetToCoord(String text) {
    GenericUrl url = new GenericUrl( + "street2coordinates/");
    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 {
New to GrepCode? Check out our FAQ X