List of usage examples for org.json.simple JSONArray size
public int size()
From source file:mas.MAS_VLDB.java
public static void extractPaper_Category(int start) { String file_prefix = "paper_categories"; String csv_file_path = "data/" + file_prefix + ".csv"; String json_dump_file_path = "data/" + file_prefix + "_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper_Category?"; url += "$format=json"; while (true) { try {/*from w ww .j a v a 2 s .co m*/ StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); if (json == null) { System.out.println("json is null. skip. old start=" + start); start += 100; Thread.sleep(5000L); continue; } JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Paper_Category: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; Long cPaperID = (Long) paperObj.get("CPaperID"); Long domainID = (Long) paperObj.get("DomainID"); Long subDomainID = (Long) paperObj.get("SubDomainID"); csv_str.append(cPaperID).append(SEPERATOR).append(domainID).append(SEPERATOR) .append(subDomainID).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(300L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:mas.MAS_TOP_PAPERS.java
public static void extractCitation(int start, String papers_filter) { String csv_file_path = "data/citations_30_conf.csv"; String json_dump_file_path = "data/citations_30_conf_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper_Ref?$select=SrcID,DstID,SeqID&$filter=" + papers_filter + "&$format=json"; while (true) { IOUtils.writeDataIntoFile(start + "", paper_last, false); try {//from w w w . j a v a2 s.c o m StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); // System.out.println("json=" + json); if (json == null) { System.out.println("json is null. skip. old start=" + start); start += 100; Thread.sleep(1000L); continue; } JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Paper: start = " + start + " results# = " + results.size()); for (Object cite : results) { JSONObject citeObj = (JSONObject) cite; // Long docType = (Long) paperObj.get("DocType"); // Long year = (Long) paperObj.get("Year"); // Long jourID = (Long) paperObj.get("JourID"); Long srcID = (Long) citeObj.get("SrcID"); Long dstID = (Long) citeObj.get("DstID"); // String title = (String) citeObj.get("Title"); // title = normalized(title); csv_str.append(srcID).append(SEPERATOR).append(dstID).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(300L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(5000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(5000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:mas.MAS_TOP_PAPERS.java
public static void extractPapers(int start, int conf) { String csv_file_path = "data/papers_200_conf.csv"; String json_dump_file_path = "data/papers_200_conf_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper?$select=ID,Title,Year,ConfID,JourID&$filter=Year%20ge%202000%20and%20ConfID%20eq%20" + conf + "&$format=json"; // String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper?$select=ID,DocType,Title,Year,ConfID,JourID&$filter=Year%20gt%202001&$format=json"; while (true) { IOUtils.writeDataIntoFile(start + "", paper_last, false); try {// ww w.ja va 2 s . c om StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); // System.out.println("json=" + json); if (json == null) { System.out.println("json is null. skip. old start=" + start); start += 100; Thread.sleep(10000L); continue; } JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Paper: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; // Long docType = (Long) paperObj.get("DocType"); // Long year = (Long) paperObj.get("Year"); // Long jourID = (Long) paperObj.get("JourID"); Long confID = (Long) paperObj.get("ConfID"); Long id = (Long) paperObj.get("ID"); String title = (String) paperObj.get("Title"); title = normalized(title); csv_str.append(id).append(SEPERATOR).append(confID).append(SEPERATOR).append(title) .append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(250L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(1000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(1000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:mas.MAS_VLDB.java
public static void extractCitation(int start, String papers_filter, String csv_file, String json_file) { String csv_file_path = csv_file; String json_dump_file_path = json_file; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper_Ref?$select=SrcID,DstID&$filter=" + papers_filter + "&$format=json"; while (true) { IOUtils.writeDataIntoFile(start + "", paper_last, false); try {/*from w w w.j a v a 2 s.co m*/ StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); // System.out.println("json=" + json); if (json == null) { System.out.println("json is null. skip. old start=" + start); start += 100; Thread.sleep(1000L); continue; } JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Paper: start = " + start + " results# = " + results.size()); for (Object cite : results) { JSONObject citeObj = (JSONObject) cite; // Long docType = (Long) paperObj.get("DocType"); // Long year = (Long) paperObj.get("Year"); // Long jourID = (Long) paperObj.get("JourID"); Long srcID = (Long) citeObj.get("SrcID"); Long dstID = (Long) citeObj.get("DstID"); // String title = (String) citeObj.get("Title"); // title = normalized(title); csv_str.append(srcID).append(SEPERATOR).append(dstID).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(300L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(5000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(5000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:mas.MAS_VLDB.java
public static void extractPapers(int start, int conf) { String csv_file_path = "data/papers_200_conf.csv"; String json_dump_file_path = "data/papers_200_conf_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper?$select=ID,Title,Year,ConfID,JourID&$filter=Year%20ge%202000%20and%20ConfID%20eq%20" + conf + "&$format=json"; // String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper?$select=ID,DocType,Title,Year,ConfID,JourID&$filter=Year%20gt%202001&$format=json"; while (true) { IOUtils.writeDataIntoFile(start + "", paper_last, false); try {//from w w w. jav a 2s. com StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); // System.out.println("json=" + json); if (json == null) { System.out.println("json is null. skip. old start=" + start); start += 100; Thread.sleep(10000L); continue; } JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Paper: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; // Long docType = (Long) paperObj.get("DocType"); // Long year = (Long) paperObj.get("Year"); // Long jourID = (Long) paperObj.get("JourID"); Long confID = (Long) paperObj.get("ConfID"); Long id = (Long) paperObj.get("ID"); String title = (String) paperObj.get("Title"); title = normalized(title); csv_str.append(id).append(SEPERATOR).append(confID).append(SEPERATOR).append(title) .append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(250L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(1000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(1000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:org.openimaj.image.dataset.BingImageDataset.java
private static List<ImageDataSourceResponse> performSinglePageQuery(ImageDataSourceQuery query) { final HttpClient httpclient = HttpClients.createDefault(); try {//w w w. j ava 2s .c o m final URI uri = query.buildURI(); final HttpGet request = new HttpGet(uri); request.setHeader("Ocp-Apim-Subscription-Key", query.accountKey); final HttpResponse response = httpclient.execute(request); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { throw new IOException( "HTTP ERROR 401: Unauthorized Recieved. " + "You probably have the incorrect API Key"); } final HttpEntity entity = response.getEntity(); if (entity != null) { try { final JSONParser parser = new JSONParser(); final JSONObject o = (JSONObject) parser.parse(EntityUtils.toString(entity)); final JSONArray jresults = ((JSONArray) o.get("value")); final List<ImageDataSourceResponse> results = new ArrayList<>(jresults.size()); for (final Object jro : jresults) { results.add(new ImageDataSourceResponse((JSONObject) jro)); } return results; } catch (final Exception e) { e.printStackTrace(); } } } catch (final IOException e) { e.printStackTrace(); } catch (final URISyntaxException e) { e.printStackTrace(); } return null; }
From source file:com.googlecode.fascinator.redbox.plugins.curation.external.FormDataParser.java
/** * Get a child JSON Object from an incoming JSON array. If the child does * not exist it will be created, along with any smaller index values. The * index is expected to be 1 based (like form data). * /*from www.j av a 2 s .c o m*/ * It is only valid for form arrays to hold JSON Objects. * * @param array The incoming array we are to look inside * @param index The child index we are looking for (1 based) * @return JsonObject The child we found or created * @throws IOException if anything other than an object is found, or an * invalid index is provided */ private static JsonObject getObject(JSONArray array, int index) throws IOException { // We can't just jam an entry into the array without // checking that earlier indexes exist. Also we need // to account for 0 versus 1 based indexing. // Index changed to 0 based if (index < 1) { throw new IOException("Invalid index value provided in form data."); } index -= 1; // Nice and easy, it already exists if (array.size() > index) { Object object = array.get(index); if (object instanceof JsonObject) { return (JsonObject) object; } throw new IOException("Non-Object found in array!"); // Slightly more annoying, we need to fill in // all the indices up to this point } else { for (int i = array.size(); i <= index; i++) { JsonObject object = new JsonObject(); array.add(object); } return (JsonObject) array.get(index); } }
From source file:mas.MAS.java
public static void extractConference(int start) { String file_prefix = "conferences"; String csv_file_path = "data/" + file_prefix + ".csv"; String json_dump_file_path = "data/" + file_prefix + "_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Conference?"; url += "$format=json"; while (true) { try {/* www . j a v a 2s . c o m*/ StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Conference: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; Long id = (Long) paperObj.get("ID"); String shortName = normalized((String) paperObj.get("ShortName")); String fullName = normalized((String) paperObj.get("FullName")); String homepage = normalized((String) paperObj.get("Homepage")); csv_str.append(id).append(SEPERATOR).append(shortName).append(SEPERATOR).append(fullName) .append(SEPERATOR).append(homepage).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(300L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:mas.MAS.java
public static void extractJournal(int start) { String file_prefix = "journals"; String csv_file_path = "data/" + file_prefix + ".csv"; String json_dump_file_path = "data/" + file_prefix + "_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Journal?"; url += "$format=json"; while (true) { try {/* w ww . j a v a2s .c om*/ StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Journals: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; Long id = (Long) paperObj.get("ID"); String shortName = normalized((String) paperObj.get("ShortName")); String fullName = normalized((String) paperObj.get("FullName")); String homepage = normalized((String) paperObj.get("Homepage")); csv_str.append(id).append(SEPERATOR).append(shortName).append(SEPERATOR).append(fullName) .append(SEPERATOR).append(homepage).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(300L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:mas.MAS.java
public static void extractAuthor(int start) { String file_prefix = "authors"; String csv_file_path = "data/" + file_prefix + ".csv"; String json_dump_file_path = "data/" + file_prefix + "_dump.json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Author?$select=ID,Name,NativeName,Affiliation,AffiliationID,Version"; url += "&$format=json"; while (true) { try {//ww w .j a va2s.co m StringBuilder csv_str = new StringBuilder(); final String json = getData2(url, start); JSONParser parser = new JSONParser(); JSONObject jsonObj = (JSONObject) parser.parse(json); final JSONObject dObj = (JSONObject) jsonObj.get("d"); final JSONArray results = (JSONArray) dObj.get("results"); if (results.size() == 0) { System.out.println("results is Empty, break."); break; } else { System.out.println("Author: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; Long id = (Long) paperObj.get("ID"); String name = normalized((String) paperObj.get("Name")); String nativeName = normalized((String) paperObj.get("NativeName")); String affiliation = normalized((String) paperObj.get("Affiliation")); Long affiliationID = (Long) paperObj.get("AffiliationID"); Long version = (Long) paperObj.get("Version"); csv_str.append(id).append(SEPERATOR).append(name).append(SEPERATOR).append(nativeName) .append(SEPERATOR).append(affiliation).append(SEPERATOR).append(affiliationID) .append(SEPERATOR).append(version).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(300L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); } } }