Package com.google.gson

Examples of com.google.gson.JsonObject


  return query_pairs;
    }

    public JsonObject extractTweet(String html)
  throws java.net.MalformedURLException, java.io.UnsupportedEncodingException {
  JsonObject status = new JsonObject();

  Document doc = Jsoup.parse(html);
  Element tweet_div = doc.select("div.permalink-tweet").first();

  String tweet_text = tweet_div.select("p.tweet-text").first().text();
  status.addProperty("text", tweet_text);

  String tweet_id = tweet_div.attr("data-tweet-id");
  status.addProperty("id_str", tweet_id);
  status.addProperty("id", Long.parseLong(tweet_id));

  String timestamp = doc.select("span.js-short-timestamp").first().attr("data-time");
  Date created_at = new Date();
  created_at.setTime(Long.parseLong(timestamp) * 1000);
  status.addProperty("created_at", date_fmt.format(created_at));

  Elements js_stats_retweets = doc.select("li.js-stat-retweets");
  if (!js_stats_retweets.isEmpty()) {
      status.addProperty("retweeted", true);
      String count = js_stats_retweets.select("strong").first().text();
      status.addProperty("retweet_count", Long.parseLong(count));
  } else {
      status.addProperty("retweeted", false);
      status.addProperty("retweet_count", 0);
  }
  Elements js_stats_favs = doc.select("li.js-stat-favorites");
  status.addProperty("favorited", !js_stats_favs.isEmpty());
     

  // User subfield
  JsonObject user = new JsonObject();
  String user_id = tweet_div.attr("data-user-id");
  user.addProperty("id_str", user_id);
  user.addProperty("id", Long.parseLong(user_id));
  String screen_name = tweet_div.attr("data-screen-name");
  user.addProperty("screen_name", screen_name);
  String user_name = tweet_div.attr("data-name");
  user.addProperty("name", user_name);
 
  status.add("user", user);
 
  // Geo information
  Elements tweet_loc = doc.select("a.tweet-geo-text");
  if (!tweet_loc.isEmpty()) {
      JsonObject location = new JsonObject();
      Element loc = tweet_loc.first();
      // Adding http to avoid malformed URL exception
      URL url = new URL("http:" + loc.attr("href"));
      Map<String, String> query_params = HTMLStatusExtractor.splitQuery(url);
      // Loop over possible query parameters
      // http://asnsblues.blogspot.ch/2011/11/google-maps-query-string-parameters.html
      String lat_and_long = null;
      if ((lat_and_long = query_params.get("ll")) != null
    || (lat_and_long = query_params.get("sll")) != null
    || (lat_and_long = query_params.get("cbll")) != null
    || (lat_and_long = query_params.get("q")) != null) {
    String[] coordinates = lat_and_long.split(",");
    double latitude = Double.parseDouble(coordinates[0]);
    double longitude = Double.parseDouble(coordinates[1]);
    location.addProperty("latitude", latitude);
    location.addProperty("longitude", longitude);
      }
      location.addProperty("location_text", loc.text());
      status.add("location", location);
  }

  return status;
    }
View Full Code Here


  } finally {
      html_file.close();
  }

  HTMLStatusExtractor hse = new HTMLStatusExtractor();
  JsonObject json = hse.extractTweet(buf.toString());
  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  System.out.println(gson.toJson(json));
    }
View Full Code Here

   *
   * @param pathToJson
   */
  public ParameterBroker(String pathToJson) {
    params = new HashMap<String,String>();
    JsonObject json = null;
    try {
      json = (JsonObject) JSON_PARSER.parse(new BufferedReader(new FileReader(pathToJson)));
    } catch (Exception e) {
      System.err.println("died trying to parse json file: " + pathToJson);
      System.exit(-1);
    }

    Set<Entry<String, JsonElement>> jsonEntries = json.entrySet();
    Iterator<Entry<String, JsonElement>> entryIterator = jsonEntries.iterator();
    while(entryIterator.hasNext()) {
      Entry<String, JsonElement> entry = entryIterator.next();
      params.put(entry.getKey(), entry.getValue().getAsString());
      System.setProperty(entry.getKey(), entry.getValue().getAsString());
View Full Code Here

  private JsonObject outputObjects = null;
  private String pathToTrecTopics;
 
  public ExtractGqueriesFromTrecFormat(String pathToTrecTopics) {
    this.pathToTrecTopics = pathToTrecTopics;
    outputObjects = new JsonObject();
  }
View Full Code Here

   
    JsonArray outputJsonArray = new JsonArray();
    for(edu.illinois.lis.query.TrecTemporalTopic query : topicsFile) {
     

      JsonObject outputQueryObject = new JsonObject();
      outputQueryObject.addProperty("title", query.getId());
      outputQueryObject.addProperty("text", query.getQuery());
      outputQueryObject.addProperty("epoch", Double.toString(query.getEpoch()));
      outputQueryObject.addProperty("querytweettime", Long.toString(query.getQueryTweetTime()));
     
      String text = query.getQuery();
      String[] toks = text.split(" ");
     
      JsonArray modelArray = new JsonArray();
      for(String tok : toks) {
        JsonObject tupleObject = new JsonObject();
        tupleObject.addProperty("weight", 1.0);
        tupleObject.addProperty("feature", tok);
        modelArray.add(tupleObject);
      }
      outputQueryObject.add("model", modelArray);

View Full Code Here

  private static final JsonParser JSON_PARSER = new JsonParser();
  private List<GQuery> queryList;
  private Map<String,Integer> nameToIndex;

  public void read(String pathToQueries) {
    JsonObject obj = null;
    try {
      obj = (JsonObject) JSON_PARSER.parse(new BufferedReader(new FileReader(pathToQueries)));
    } catch (Exception e) {
      LOG.fatal("died reading queries from json file", e);
      System.exit(-1);
    }

   
    JsonArray queryObjectArray = obj.getAsJsonArray("queries");
    queryList = new ArrayList<GQuery>(queryObjectArray.size());
    nameToIndex = new HashMap<String,Integer>(queryList.size());
    Iterator<JsonElement> queryObjectIterator = queryObjectArray.iterator();
    int k=0;
    while(queryObjectIterator.hasNext()) {
      JsonObject queryObject = (JsonObject) queryObjectIterator.next();
      String title = queryObject.get("title").getAsString();
      String text  = queryObject.get("text").getAsString();
      double epoch = queryObject.get("epoch").getAsDouble();
      long querytweettime = queryObject.get("querytweettime").getAsLong();
      nameToIndex.put(title, k++);
      FeatureVector featureVector = new FeatureVector(null);
      JsonArray modelObjectArray = queryObject.getAsJsonArray("model");
      Iterator<JsonElement> featureIterator = modelObjectArray.iterator();
      while(featureIterator.hasNext()) {
        JsonObject featureObject = (JsonObject)featureIterator.next();
        double weight  = featureObject.get("weight").getAsDouble();
        String feature = featureObject.get("feature").getAsString();
        featureVector.addTerm(feature, weight);
      }
     
     
      GQuery gQuery = new GQuery();
View Full Code Here

public class OldPropertyMapSerializer implements JsonSerializer<PropertyMap> {

    @Override
    public JsonElement serialize (PropertyMap src, Type typeOfSrc, JsonSerializationContext context) {
        JsonObject out = new JsonObject();
        for (String key : src.keySet()) {
            JsonArray jsa = new JsonArray();
            for (Property p : src.get(key)) {
                jsa.add(new JsonPrimitive(p.getValue()));
            }
            out.add(key, jsa);
        }
        return out;
    }
View Full Code Here

                    // Fetch the percentage json first
                    String json = IOUtils.toString(new URL(Locations.masterRepo + "/FTB2/static/balance.json"));
                    JsonElement element = new JsonParser().parse(json);

                    if (element != null && element.isJsonObject()) {
                        JsonObject jso = element.getAsJsonObject();
                        if (jso != null && jso.get("minUsableLauncherVersion") != null) {
                            LaunchFrame.getInstance().minUsable = jso.get("minUsableLauncherVersion").getAsInt();
                        }
                        if (jso != null && jso.get("chEnabled") != null) {
                            Locations.chEnabled = jso.get("chEnabled").getAsBoolean();
                        }
                        if (jso != null && jso.get("repoSplitCurse") != null) {
                            JsonElement e = jso.get("repoSplitCurse");
                            Logger.logDebug("Balance Settings: " + e.getAsDouble() + " > " + choice);
                            if (e != null && e.getAsDouble() > choice) {
                                Logger.logInfo("Balance has selected Automatic:CurseCDN");
                            } else {
                                Logger.logInfo("Balance has selected Automatic:CreeperRepo");
View Full Code Here

        try {
            String json = IOUtils.toString(u);
            JsonElement element = new JsonParser().parse(json);
            int i = 10;
            if (element.isJsonObject()) {
                JsonObject jso = element.getAsJsonObject();
                for (Entry<String, JsonElement> e : jso.entrySet()) {
                    if (testEntries) {
                        try {
                            Logger.logInfo("Testing Server:" + e.getKey());
                            //test that the server will properly handle file DL's if it doesn't throw an error the web daemon should be functional
                            IOUtils.toString(new URL("http://" + e.getValue().getAsString() + "/" + location));
View Full Code Here

    @SuppressWarnings("unchecked")
    private static Map<String, Object> decode (String s) {
        try {
            Map<String, Object> ret;
            JsonObject jso = new JsonParser().parse(s).getAsJsonObject();
            ret = (Map<String, Object>) decodeElement(jso);
            return ret;
        } catch (Exception e) {
            Logger.logError("Error decoding Authlib JSON", e);
            return null;
View Full Code Here

TOP

Related Classes of com.google.gson.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.