Skip to content

Instantly share code, notes, and snippets.

@UshaRani
Created December 2, 2011 10:20
Show Gist options
  • Select an option

  • Save UshaRani/1422694 to your computer and use it in GitHub Desktop.

Select an option

Save UshaRani/1422694 to your computer and use it in GitHub Desktop.
Trending Topics for an Industry Doesn't Seem to be displaying all results
public JSONObject getIndustryTrendingTopics(String industryName, int date, boolean sortByFrequency, String timeScale, int count, String corpus) {
JSONObject industryJSON = null;
System.out.println("count"+count);
try {
String url = "http://qa.generalsentiment.com:8080/api/trendingApi.php?";
url += "industry=" + URLEncoder.encode(industryName, "UTF-8");
url += "&entityCount=" + count;
url += "&endDate=" + date;
url += "&timeScale=" + timeScale;
url += "&sortByFrequency=" + sortByFrequency;
url += "&corpus=" + URLEncoder.encode(corpus, "UTF-8");
URL trendingUrl = null;
try {
trendingUrl = new URL(url);
} catch (MalformedURLException ex) {
Logger.getLogger(IndustryTrendingTopicsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
try {
URLConnection tc = trendingUrl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));
String inputLine = in.readLine();
if (inputLine != null) {
try {
industryJSON = new JSONObject(inputLine);
} catch (JSONException ex) {
Logger.getLogger(IndustryTrendingTopicsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
in.close();
if (industryJSON != null && industryJSON.has("output")) {
JSONArray industryArray = industryJSON.getJSONArray("output");
}
} catch (JSONException ex) {
Logger.getLogger(IndustryTrendingTopicsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(IndustryTrendingTopicsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(IndustryTrendingTopicsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
return industryJSON;
}
@UshaRani
Copy link
Author

UshaRani commented Dec 2, 2011

Please check whether there are any mistakes in these lines of above code.
URLConnection tc = trendingUrl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));
String inputLine = in.readLine();
if (inputLine != null) {
try {
industryJSON = new JSONObject(inputLine);
} catch (JSONException ex) {
Logger.getLogger(IndustryTrendingTopicsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment