List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:mas.MAS_VLDB.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 {//w ww. jav a2 s. 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("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_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_VLDB.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 {/*from w w w . java 2 s . 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_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 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 {/* ww w. j a v a 2s. 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_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:mas.MAS_VLDB.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 {/*from ww w .ja va2s . 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("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_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_VLDB.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 {/* ww w . j a v a 2 s .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("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_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_VLDB.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 ww w . ja va 2s . 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("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_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_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 {//w w w . ja v a 2s .c o 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:at.nonblocking.cliwix.cli.CliwixCliClient.java
private static void doExport(String cliwixServerUrl, Options options) { waitForServerReady(cliwixServerUrl, options); String exportFolder = options.getExportFolder(); if (exportFolder == null) { console.printlnError("Error: Property export.folder is required."); console.exit(EXIT_STATUS_FAIL);/* w ww. j a v a2 s . com*/ return; } File outputDir = null; try { outputDir = new File(exportFolder); outputDir.mkdirs(); } catch (Exception e) { console.printlnError("Error: Invalid export folder: " + exportFolder); console.exit(EXIT_STATUS_FAIL); return; } JSONObject exportSettings = options.getExportSettings(); JSONObject json = postJson(cliwixServerUrl, "/services/exports", exportSettings); JSONObject exportResult = (JSONObject) json.get("exportResult"); String exportId = (String) exportResult.get("exportId"); console.println("Export started. Id: " + exportId); boolean success = waitForImportExport(true, exportId, cliwixServerUrl, options); if (success) { console.println("Export succeeded."); String path = "/services/exports/" + exportId + "/zip"; if (debug) console.println("Sending GET request: " + path); Response zipResponse = getHandler.get(cliwixServerUrl, path, cookieManager); handleError(zipResponse); File tempFile = null; try { tempFile = File.createTempFile("export", ".zip"); } catch (IOException e) { if (debug) console.printStacktrace(e); console.printlnError("Error: Unable to create temporary zip file"); console.exit(EXIT_STATUS_FAIL); return; } long fileLength = zipResponse.getContentLength(); ProgressCallback progressCallback = new ProgressCallbackConsoleImpl(console); try (InputStream inputStream = zipResponse.getResponseStream(); OutputStream outputStream = new FileOutputStream(tempFile)) { byte[] buffer = new byte[BaseHttpHandler.CHUNK_SIZE]; long transferred = 0; int len = -1; while ((len = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, len); transferred = transferred + len; progressCallback.bytesTransferred(transferred, fileLength); } progressCallback.bytesTransferred(fileLength, fileLength); } catch (IOException e) { if (debug) console.printStacktrace(e); console.printlnError("Error: " + e.getMessage()); console.exit(EXIT_STATUS_FAIL); } finally { zipResponse.disconnect(); } if (options.isExtractZip()) { try { ZipFile zip = new ZipFile(tempFile); zip.extractAll(outputDir.getAbsolutePath()); } catch (ZipException e) { if (debug) console.printStacktrace(e); console.printlnError("Error: Corrupt ZIP file"); console.exit(EXIT_STATUS_FAIL); } finally { tempFile.delete(); } } else { File targetFile = new File(outputDir, "export_" + exportId + ".zip"); try (FileInputStream fis = new FileInputStream(tempFile)) { Files.copy(fis, targetFile.toPath()); } catch (IOException e) { if (debug) console.printStacktrace(e); console.printlnError("Error: " + e.getMessage()); console.exit(EXIT_STATUS_FAIL); } finally { tempFile.delete(); } } console.println("Export data written to: " + outputDir.getAbsolutePath()); } else { console.printlnError("Export failed!"); String path = "/services/exports/" + exportId + "/report"; if (debug) console.println("Sending GET request: " + path); Response reportResponse = getHandler.get(cliwixServerUrl, path, cookieManager); handleError(reportResponse); File reportFile = new File(outputDir, "export-report.html"); try (OutputStream outputStream = new FileOutputStream(reportFile)) { outputStream.write(reportResponse.getResponseAsString().getBytes("UTF-8")); console.println("Error report written to: " + reportFile.getAbsolutePath()); } catch (IOException e) { if (debug) console.printStacktrace(e); console.printlnError("Error: No report found"); } finally { reportResponse.disconnect(); } } if (options.isExportDeleteOnServerAfterTransfer()) { Response deleteResponse = deleteHandler.delete(cliwixServerUrl, "/services/exports/" + exportId, cookieManager); if (deleteResponse.getStatusCode() == 200) { console.println("Successfully deleted export folder on server."); } else { console.printlnError("Failed to delete export folder on server!"); } } if (!success) { console.exit(EXIT_STATUS_FAIL); } }
From source file:at.ac.tuwien.dsg.quelle.cloudServicesModel.util.conversions.ConvertToJSON.java
public static String convertToJSON(MultiLevelRequirements multiLevelRequirements) { //traverse the tree to do the JSON properly List<JSONObject> jsontree = new ArrayList<JSONObject>(); List<MultiLevelRequirements> multiLevelRequirementsTree = new ArrayList<MultiLevelRequirements>(); JSONObject root = processMultiLevelRequirementsElement(multiLevelRequirements); jsontree.add(root);//from ww w .j a v a 2 s .co m multiLevelRequirementsTree.add(multiLevelRequirements); //traverse the tree in a DFS manner while (!multiLevelRequirementsTree.isEmpty()) { MultiLevelRequirements currentlyProcessed = multiLevelRequirementsTree.remove(0); JSONObject currentlyProcessedJSONObject = jsontree.remove(0); JSONArray childrenArray = new JSONArray(); //process children for (MultiLevelRequirements child : currentlyProcessed.getContainedElements()) { JSONObject childJSON = processMultiLevelRequirementsElement(child); childrenArray.add(childJSON); //next to process are children jsontree.add(childJSON); multiLevelRequirementsTree.add(child); } if (currentlyProcessedJSONObject.containsKey("children")) { JSONArray array = (JSONArray) currentlyProcessedJSONObject.get("children"); array.addAll(childrenArray); } else { currentlyProcessedJSONObject.put("children", childrenArray); } } return root.toJSONString(); }
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 . ja v a 2s . 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_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); } } } }