List of usage examples for org.json.simple JSONArray size
public int size()
From source file:mas.MAS.java
public static void extractAffilition(int start) { String file_prefix = "affilitions"; 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/Affiliation?"; url += "$format=json"; while (true) { try {//from ww w . j a v a2 s . com 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("Affilition: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; Long id = (Long) paperObj.get("ID"); String officialName = normalized((String) paperObj.get("OfficialName")); String displayName = normalized((String) paperObj.get("DisplayName")); String nativeName = normalized((String) paperObj.get("NativeName")); Long parentID = (Long) paperObj.get("ParentID"); String homepage = normalized((String) paperObj.get("Homepage")); String shortName = normalized((String) paperObj.get("ShortName")); Long type = (Long) paperObj.get("Type"); csv_str.append(id).append(SEPERATOR).append(officialName).append(SEPERATOR) .append(displayName).append(SEPERATOR).append(nativeName).append(SEPERATOR) .append(parentID).append(SEPERATOR).append(homepage).append(SEPERATOR) .append(shortName).append(SEPERATOR).append(type).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 extractPaper_Author(int start) { String file_prefix = "paper_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/Paper_Author?"; url += "$format=json"; while (true) { try {//from w w w .j a va2s .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("Paper_Author: start = " + start + " results# = " + results.size()); for (Object paper : results) { JSONObject paperObj = (JSONObject) paper; Long paperID = (Long) paperObj.get("PaperID"); Long seqID = (Long) paperObj.get("SeqID"); Long authorID = (Long) paperObj.get("authorID"); String name = normalized((String) paperObj.get("Name")); String affiliation = normalized((String) paperObj.get("Affiliation")); Long affiliationID = (Long) paperObj.get("AffiliationID"); csv_str.append(paperID).append(SEPERATOR).append(seqID).append(SEPERATOR).append(authorID) .append(SEPERATOR).append(name).append(SEPERATOR).append(affiliation) .append(SEPERATOR).append(affiliationID).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 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 ww w . j a v a2 s .c om 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.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 extractPaperCategory(int start, int domain, int subdomain) { String csv_file_path = "data/papers_d" + domain + "_sd" + subdomain + ".csv"; String json_dump_file_path = "data/papers_dump_d" + domain + "_sd" + subdomain + ".json"; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper_Category?$filter=DomainID%20eq%20" + domain + "%20and%20SubDomainID%20eq%20" + subdomain + "&$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 . j a va 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(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 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(400L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(10000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(10000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:mas.MAS.java
public static void getPapers(int start, String papers_filter, String csvFile, String jsonFile) { String csv_file_path = csvFile; String json_dump_file_path = jsonFile; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper?$select=ID,Title&$filter=" + papers_filter + "&$format=json"; while (true) { IOUtils.writeDataIntoFile(start + "", paper_last, false); try {/*w w w. ja v a2s . 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 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(title).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(400L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(10000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(10000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:mas.MAS.java
public static void getAuthors(int start, String authors_filter, String csvFile, String jsonFile) { String csv_file_path = csvFile; String json_dump_file_path = jsonFile; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Author?$select=ID,Name,NativeName,AffiliationID&$filter=" + authors_filter + "&$format=json"; // String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper_Author?$select=PaperID,SeqID,AuthorID,Name,AffiliationID&$filter=" + papers_filter + "&$format=json"; while (true) { IOUtils.writeDataIntoFile(start + "", paper_last, false); try {//from w w w . java2 s. 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(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 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(affiliationID).append(NEWLINE); } IOUtils.writeDataIntoFile(json + "\n", json_dump_file_path); IOUtils.writeDataIntoFile(csv_str.toString(), csv_file_path); start += 100; Thread.sleep(400L); } // 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.java
public static void extractPapers(int start) { String csv_file_path = "data/papers_" + start + ".csv"; String json_dump_file_path = "data/papers_dump_" + start + ".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 .j a va 2s. 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(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 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(docType).append(SEPERATOR).append(year) .append(SEPERATOR).append(jourID).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(400L); } // System.out.println("json= " + jsonObj); } catch (ParseException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(10000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex1); } } catch (InterruptedException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex); start += 100; try { Thread.sleep(10000L); } catch (InterruptedException ex1) { Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex1); } } } }
From source file:mas.MAS.java
public static void getPaperAuthors(int start, String papers_filter, String csvFile, String jsonFile) { String csv_file_path = csvFile; String json_dump_file_path = jsonFile; String url = "https://api.datamarket.azure.com/MRC/MicrosoftAcademic/v2/Paper_Author?$select=PaperID,SeqID,AuthorID,Name,AffiliationID&$filter=" + papers_filter + "&$format=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 {// ww w. j av a2 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 paper : results) { JSONObject paperObj = (JSONObject) paper; Long paperID = (Long) paperObj.get("PaperID"); Long seqID = (Long) paperObj.get("SeqID"); Long authorID = (Long) paperObj.get("AuthorID"); String name = normalized((String) paperObj.get("Name")); // String affiliation = normalized((String) paperObj.get("Affiliation")); Long affiliationID = (Long) paperObj.get("AffiliationID"); csv_str.append(paperID).append(SEPERATOR).append(seqID).append(SEPERATOR).append(authorID) .append(SEPERATOR).append(name).append(SEPERATOR).append(affiliationID) .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:com.jts.rest.profileservice.utils.RestServiceHelper.java
/** * Gets the recent challenges and splits them to active and past challenges * Maximum 3 past challenges and all active challenges will be returned * @param sessionId/*from w w w . j a va2 s .co m*/ * @param username * @return * @throws MalformedURLException * @throws IOException */ @SuppressWarnings("unchecked") public static JSONObject getProcessedChallengesM2(String sessionId, String username) throws MalformedURLException, IOException { JSONArray recentChallenges = getRecentParticipantChallengesByUsername(sessionId, username); JSONArray activeChallenges = new JSONArray(); JSONArray pastChallenges = new JSONArray(); Iterator<JSONObject> iterator = recentChallenges.iterator(); while (iterator.hasNext()) { JSONObject participantChallenge = iterator.next(); JSONObject challenge = (JSONObject) participantChallenge.get("Challenge__r"); if (challenge.get("Status__c").equals(PSContants.STATUS_CREATED)) { //active challenge activeChallenges.add(participantChallenge); JSONArray categories = getCategoriesByChallenge(sessionId, (String) participantChallenge.get("Challenge__c")); participantChallenge.put("categories", categories); } else { //past challenges if (pastChallenges.size() < 3) { pastChallenges.add(participantChallenge); JSONArray categories = getCategoriesByChallenge(sessionId, (String) participantChallenge.get("Challenge__c")); participantChallenge.put("categories", categories); } } } JSONObject challenges = new JSONObject(); challenges.put("activeChallenges", activeChallenges); challenges.put("pastChallenges", pastChallenges); challenges.put("totalChallenges", getChallengeCountByUser(sessionId, username)); return challenges; }
From source file:com.intel.genomicsdb.GenomicsDBImporter.java
/** * Utility function that returns a list of ChromosomeInterval objects for * the column partition specified by the loader JSON file and rank/partition index * @param loaderJSONFile path to loader JSON file * @param partitionIdx rank/partition index * @return list of ChromosomeInterval objects for the specified partition * @throws ParseException when there is a bug in the JNI interface and a faulty JSON is returned *///from w w w .j ava 2 s . c om public static ArrayList<ChromosomeInterval> getChromosomeIntervalsForColumnPartition( final String loaderJSONFile, final int partitionIdx) throws ParseException { final String chromosomeIntervalsJSONString = jniGetChromosomeIntervalsForColumnPartition(loaderJSONFile, partitionIdx); /* JSON format { "contigs": [ { "chr1": [ 100, 200] }, { "chr2": [ 500, 600] } ] } */ ArrayList<ChromosomeInterval> chromosomeIntervals = new ArrayList<ChromosomeInterval>(); JSONParser parser = new JSONParser(); JSONObject topObj = (JSONObject) (parser.parse(chromosomeIntervalsJSONString)); assert topObj.containsKey("contigs"); JSONArray listOfDictionaries = (JSONArray) (topObj.get("contigs")); for (Object currDictObj : listOfDictionaries) { JSONObject currDict = (JSONObject) currDictObj; assert currDict.size() == 1; //1 entry for (Object currEntryObj : currDict.entrySet()) { Map.Entry<String, JSONArray> currEntry = (Map.Entry<String, JSONArray>) currEntryObj; JSONArray currValue = currEntry.getValue(); assert currValue.size() == 2; chromosomeIntervals.add(new ChromosomeInterval(currEntry.getKey(), (Long) (currValue.get(0)), (Long) (currValue.get(1)))); } } return chromosomeIntervals; }