Created
December 2, 2011 10:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);
}
}