java - Read Json file and Split the Tweet message and analyse -
public class tweets { private string name; private string username; private string time; private long followers; private long following; private int location; private string tweet; private double longitude; private double latitude; public tweets(string name, string username, string time, long followers, long following, int location, string tweet, double longitude, double latitude) { name = name; username = username; time = time; followers = followers; following = following; location = location; tweet = tweet; this.longitude = longitude; this.latitude = latitude; } public double getsentimentvalue() { return sentimentvalue; } public void setsentimentvalue(double sentimentvalue) { this.sentimentvalue = sentimentvalue; } public boolean ishaveisettheentimentvaluecalculateornot() { return haveisettheentimentvaluecalculateornot; } public void sethaveisettheentimentvaluecalculateornot( boolean haveisettheentimentvaluecalculateornot) { this.haveisettheentimentvaluecalculateornot = haveisettheentimentvaluecalculateornot; } public string getname() { return name; } public string getusername() { return username; } public string gettime() { return time; } public long getfollowers() { return followers; } public long getfollowing() { return following; } public int getlocation() { return location; } public string gettweet() { return tweet; } public double getlongitude() { return longitude; } public double getlatitude() { return latitude; } private double sentimentvalue; private boolean haveisettheentimentvaluecalculateornot; @override public string tostring(){ stringbuilder sb = new stringbuilder(); sb.append("***** employee details *****\n"); sb.append("name="+getname()+"\n"); sb.append("username="+getusername()+"\n"); sb.append("time="+gettime()+"\n"); sb.append("followers="+getfollowers()+"\n"); sb.append("following="+getfollowing()+"\n"); sb.append("location="+getlocation()); sb.append("\n*****************************"); return sb.tostring(); }
below json file have attached code used open file, opens file i'm stuck splitting tweets in single word.
private static final string filepath = "h:\\my documents\\oo2\\ass\\tweets.json"; public static void main(string[] args) { try { // read json file filereader reader = new filereader(filepath); jsonparser jsonparser = new jsonparser(); jsonobject jsonobject = (jsonobject) jsonparser.parse(reader); // string json object string username = (string) jsonobject.get("username"); system.out.println("the first name is: " + username); // number json object long name = (long) jsonobject.get("name"); system.out.println("the accouunt name is: " + name); // array json object jsonarray tweet= (jsonarray) jsonobject.get("tweet"); // take elements of json array for(int i=0; i<tweet.size(); i++){ system.out.println("the " + + " element of array: "+tweet.get(i)); } iterator = tweet.iterator(); // take each value json array separately while (i.hasnext()) { jsonobject innerobj = (jsonobject) i.next(); system.out.println("tweet "+ innerobj.get("tweet") + " level " + innerobj.get("knowledge")); } // handle structure json object jsonobject structure = (jsonobject) jsonobject.get("job"); system.out.println("into job structure, name: " + structure.get("name")); } catch (filenotfoundexception ex) { ex.printstacktrace(); } catch (ioexception ex) { ex.printstacktrace(); } catch (parseexception ex) { ex.printstacktrace(); } catch (nullpointerexception ex) { ex.printstacktrace(); } } }
i trying read json file , split tweets message single word , analysis tweets sentiment.
{ "user":"barackobama", "username":"barack obama", "tweet":"happening now: president obama holding press conference. tune in. ofa.bo/s1qx", "time":"wed nov 05 19:58:06 +0000 2014", "followers":49510304, "following":646777, "location":"washington, dc", "field8":"" }, { "user":"barackobama", "user name":"barack obama", "tweet":"\"i'm going squeeze every last bit of opportunity make world better place on these last 2 years.\" ?president obama", "time":"wed nov 05 21:33:27 +0000 2014", "followers":49510304, "following":646777, "location":"washington, dc", "field8":"" }, { "user":"barackobama", "user name":"barack obama", "tweet":"this undeniable progress on minimum wage. congrats @ofa volunteers fighting #raisethewage. pic.twitter.com/m4cluzyzqo", "time":"thu nov 06 18:14:22 +0000 2014", "followers":49510304, "following":646777, "location":"washington, dc", "field8":"" }, { "user":"barackobama", "user name":"barack obama", "tweet":"jackie robinson west stars: america's champions. pic.twitter.com/jamzbdgnub", "time":"thu nov 06 23:19:11 +0000 2014", "followers":49510304, "following":646777, "location":"washington, dc", "field8":"" }, { "user":"barackobama", "user name":"barack obama", "tweet":"the unemployment rate falling fast point in last 30 years. let's keep building momentum. pic.twitter.com/iitccvjm7t", "time":"fri nov 07 17:17:17 +0000 2014", "followers":49510304, "following":646777, "location":"washington, dc", "field8":"" }, { "user":"barackobama", "user name":"barack obama", "tweet":"for first time since 1990s, private sector has added @ least 200k jobs 9 consecutive months. #actonjobs", "time":"fri nov 07 19:28:31 +0000 2014", "followers":49510304, "following":646777, "location":"washington, dc", "field8":"" }
Comments
Post a Comment