List of usage examples for org.json.simple JSONObject get
V get(Object key);
From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java
public static GameSummary parseGameSummary(JSONObject jsonObject) { JSONArray resultSets = (JSONArray) jsonObject.get("resultSets"); JSONObject infoObject = (JSONObject) resultSets.get(0); JSONArray rowSet = (JSONArray) infoObject.get("rowSet"); JSONArray row = (JSONArray) rowSet.get(0); String gameSummaryDateEst = (String) row.get(0); long gameSummarySequence = (Long) row.get(1); long gameSummaryId = Long.parseLong(row.get(2).toString().trim()); long gameStatusId = (Long) row.get(3); String gameStatusText = (String) row.get(4); String gameCode = (String) row.get(5); long homeTeamId = Long.parseLong(row.get(6).toString().trim()); long visitorTeamId = (Long) row.get(7); long season = Long.parseLong(row.get(8).toString().trim()); long livePeriod = (Long) row.get(9); String livePcTimeString = row.get(10).toString(); long livePcTime = livePcTimeString.isEmpty() ? 0 : Long.parseLong(livePcTimeString); String broadcasterAbbrev = (String) row.get(11); String livePeriodTimeBcast = (String) row.get(12); long whStatus = (Long) row.get(13); return GameSummary.newBuilder().setGameSummaryDateEst(gameSummaryDateEst) .setGameSummarySequence(gameSummarySequence).setGameGameSummaryId(gameSummaryId) .setGameStatusId(gameStatusId).setGameStatusText(gameStatusText).setGameCode(gameCode) .setGameSummaryHomeTeamId(homeTeamId).setGameSummaryVisitorTeamId(visitorTeamId).setSeason(season) .setLivePeriod(livePeriod).setLivePcTime(livePcTime) .setNatlTvBroadcasterAbbreviation(broadcasterAbbrev).setLivePeriodTimeBcast(livePeriodTimeBcast) .setWhStatus(whStatus).build(); }
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
public static ObirsQuery parseObirsJSONQuery(SM_Engine engine, String jsonQuery) throws ParseException, Exception { logger.info("parsing query: " + jsonQuery); URIFactory factory = URIFactoryMemory.getSingleton(); jsonQuery = jsonQuery.replace("\n", ""); jsonQuery = jsonQuery.replace("\r", ""); JSONParser parser = new JSONParser(); Object obj = parser.parse(jsonQuery); JSONObject jsonObject = (JSONObject) obj; String aggregator = (String) jsonObject.get("aggregator"); String similarityMeasure = (String) jsonObject.get("similarityMeasure"); Double aggregatorParameter;/*www . jav a2s . co m*/ if (jsonObject.get("aggregatorParameter") != null) { aggregatorParameter = Double.parseDouble(jsonObject.get("aggregatorParameter").toString()); } else { aggregatorParameter = 2.0; } Double scoreThreshold = (Double) jsonObject.get("scoreThreshold"); Integer numberOfResults = (Integer) jsonObject.get("numberOfResults"); JSONArray concepts = (JSONArray) jsonObject.get("concepts"); Map<URI, Double> conceptsMap = new HashMap<URI, Double>(); ObirsQuery query = new ObirsQuery(conceptsMap, aggregator, similarityMeasure, aggregatorParameter, scoreThreshold, numberOfResults); if (concepts != null) { Iterator<JSONObject> iterator = concepts.iterator(); while (iterator.hasNext()) { JSONObject concept = iterator.next(); Double weight = Double.parseDouble(concept.get("weight").toString()); Object uriString = concept.get("uri"); if (uriString == null) { throw new SLIB_Ex_Critic("Error a URI must be specified for each query concept"); } URI uri = factory.getURI(uriString.toString()); if (engine.getGraph().containsVertex(uri)) { query.addConcept(uri, weight); } else { throw new Exception("concept associated to URI '" + uri + "' does not exists..."); } } } return query; }
From source file:freebase.api.FreebaseAPIMusic.java
private static List<Recording> encodeJSON(JSONArray results) { List<Recording> recordings = new ArrayList<>(); for (Object recordingObj : results) { JSONObject recordingJObj = (JSONObject) recordingObj; Recording recording = new Recording(getId((String) recordingJObj.get("mid"), recording_map), (String) recordingJObj.get("mid"), (String) recordingJObj.get("name")); JSONArray recorded_by_arr = (JSONArray) recordingJObj.get("recorded_by"); JSONObject recorded_by = (JSONObject) recorded_by_arr.get(0); //Directedby directedby = new Directedby(); //directedby.setId(directedbyIDs.next()); Artist artist = new Artist(getId((String) recorded_by.get("mid"), artist_map), (String) recorded_by.get("mid"), (String) recorded_by.get("name")); recording.setArtist(artist);//from ww w . j ava 2 s . co m //directedby.setDirector(artist); //recording.setDirectedBy(directedby); recordings.add(recording); } return recordings; }
From source file:freebase.api.FreebaseAPI.java
public static List<Film> encodeJSON(JSONArray results) { List<Film> films = new ArrayList<>(); for (Object flmObj : results) { JSONObject flmJObj = (JSONObject) flmObj; Film film = new Film(getId((String) flmJObj.get("mid"), film_map), (String) flmJObj.get("mid"), (String) flmJObj.get("name")); JSONArray directed_by_arr = (JSONArray) flmJObj.get("directed_by"); JSONObject directed_by = (JSONObject) directed_by_arr.get(0); Directedby directedby = new Directedby(); directedby.setId(directedbyIDs.next()); Director director = new Director(getId((String) directed_by.get("mid"), director_map), (String) directed_by.get("mid"), (String) directed_by.get("name")); directedby.setDirector(director); film.setDirectedBy(directedby);//from ww w.ja va2 s . c o m JSONArray starrings = (JSONArray) flmJObj.get("starring"); for (Object starringObj : starrings) { JSONObject starringJObj = (JSONObject) starringObj; Starring starring = new Starring(); starring.setMid((String) starringJObj.get("mid")); starring.setId(getId((String) starringJObj.get("mid"), starring_map)); JSONArray actorJObj_arr = (JSONArray) starringJObj.get("actor"); JSONObject actorJObj = (JSONObject) actorJObj_arr.get(0); Actor actor = new Actor(getId((String) actorJObj.get("mid"), actor_map), (String) actorJObj.get("mid"), (String) actorJObj.get("name")); starring.setActor(actor); JSONArray characterJObj_arr = (JSONArray) starringJObj.get("character"); JSONObject characterJObj = (JSONObject) characterJObj_arr.get(0); freebase.api.entity.movie.FCharacter character = new freebase.api.entity.movie.FCharacter( getId((String) characterJObj.get("mid"), character_map), (String) characterJObj.get("mid"), (String) characterJObj.get("name")); starring.setCharacter(character); film.addStarring(starring); } films.add(film); } return films; }
From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java
public static List<TeamStats> parseTeamStats(JSONObject jsonObject) { JSONArray resultSets = (JSONArray) jsonObject.get("resultSets"); JSONObject infoObject = (JSONObject) resultSets.get(5); JSONArray rowSet = (JSONArray) infoObject.get("rowSet"); List<TeamStats> result = new ArrayList<TeamStats>(); for (Object rowObject : rowSet) { JSONArray row = (JSONArray) rowObject; result.add(TeamStats.newBuilder() .setGameTeamStatsId(row.get(0) == null ? -1 : Long.parseLong((String) row.get(0))) .setTeamStatsTeamId(row.get(1) == null ? -1 : (Long) row.get(1)) .setTeamStatsTeamName(row.get(2) == null ? "" : (String) row.get(2)) .setTeamStatsTeamAbbreviation(row.get(3) == null ? "" : (String) row.get(3)) .setTeamStatsTeamCity(row.get(4) == null ? "" : (String) row.get(4)) .setTeamStatsMin(row.get(5) == null ? "" : (String) row.get(5)) .setTeamStatsFgm(row.get(6) == null ? -1 : (Long) row.get(6)) .setTeamStatsFga(row.get(7) == null ? -1 : (Long) row.get(7)) .setTeamStatsfgPct(row.get(8) == null ? -1 : Math.round((Double.parseDouble(row.get(8).toString().trim())) * 100)) .setTeamStatsfg3m(row.get(9) == null ? -1 : (Long) row.get(9)) .setTeamStatsfg3a(row.get(10) == null ? -1 : (Long) row.get(10)) .setTeamStatsfg3Pct(row.get(11) == null ? -1 : Math.round((Double.parseDouble(row.get(11).toString().trim())) * 100)) .setTeamStatsftm(row.get(12) == null ? -1 : (Long) row.get(12)) .setTeamStatsfta(row.get(13) == null ? -1 : (Long) row.get(13)) .setTeamStatsftPct(row.get(14) == null ? -1 : Math.round((Double.parseDouble(row.get(14).toString().trim())) * 100)) .setTeamStatsoreb(row.get(15) == null ? -1 : (Long) row.get(15)) .setTeamStatsdreb(row.get(16) == null ? -1 : (Long) row.get(16)) .setTeamStatsreb(row.get(17) == null ? -1 : (Long) row.get(17)) .setTeamStatsast(row.get(18) == null ? -1 : (Long) row.get(18)) .setTeamStatsstl(row.get(19) == null ? -1 : (Long) row.get(19)) .setTeamStatsblk(row.get(20) == null ? -1 : (Long) row.get(20)) .setTeamStatsto(row.get(21) == null ? -1 : (Long) row.get(21)) .setTeamStatspf(row.get(22) == null ? -1 : (Long) row.get(22)) .setTeamStatsPts(row.get(23) == null ? -1 : (Long) row.get(23)) .setTeamStatsPlusMinus(row.get(24) == null ? -1 : (Long) row.get(24)).build()); }//w ww . ja v a 2s . co m return result; }
From source file:luceneindexdemo.LuceneIndexDemo.java
public static void searchIndex(String s) throws IOException, ParseException, SQLException, FileNotFoundException, org.json.simple.parser.ParseException { Directory directory = FSDirectory.getDirectory(INDEX_DIRECTORY); IndexReader reader = IndexReader.open(directory); IndexSearcher search = new IndexSearcher(reader); Analyzer analyzer = new StandardAnalyzer(); QueryParser queryparser = new QueryParser(FIELD_CONTENTS, analyzer); Query query = queryparser.parse(s); Hits hits = search.search(query);//from www.ja v a 2 s. co m Iterator<Hit> it = hits.iterator(); //System.out.println("hits:"+hits.length()); float f_score; List<String> names = new ArrayList<>(); while (it.hasNext()) { Hit hit = it.next(); f_score = hit.getScore(); //System.out.println(f_score); Document document = hit.getDocument(); Field f = document.getField(FIELD_PATH); //System.out.println(f.readerValue()); //System.out.println(document.getValues(FIELD_PATH)); String path = document.get(FIELD_PATH); System.out.println(document.getValues(path)); Field con = document.getField(FIELD_PATH); //System.out.println("hit:"+path+" "+hit.getId()+" "+con); names.add(new File(path).getName()); } //ProcessBuilder pb=new ProcessBuilder(); FileReader fReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/inntell.json"); JSONParser jsParser = new JSONParser(); //System.out.println("This is an assumption that you belong to US"); FileReader freReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/location.json"); Connection con = DriverManager.getConnection("jdbc:neo4j://localhost:7474/"); System.out.println(names); if (names.get(0).equals("miss")) { System.out.println(s); StringTokenizer stringTokenizer = new StringTokenizer(s); Connection con1 = DriverManager.getConnection("jdbc:neo4j://localhost:7474/"); String querySearch = "match ()-[r:KNOWS]-() where has(r.relType) return distinct r.relType"; ResultSet rSet = con.createStatement().executeQuery(querySearch); List<String> allRels = new ArrayList<>(); while (rSet.next()) { System.out.println(); allRels.add(rSet.getString("r.relType")); } //System.out.println(rSet); while (stringTokenizer.hasMoreTokens()) { String next = stringTokenizer.nextToken(); if (allRels.contains(next)) { missOperation(next); } //System.out.println(resSet.getString("r.relType")); } System.out.println(names.get(1)); //missOperation(names.get(1)); } else { try { JSONObject jsonObj = (JSONObject) jsParser.parse(fReader); System.out.println(names.get(0)); JSONObject jsObj = (JSONObject) jsonObj.get(names.get(0)); JSONObject results = new JSONObject(); System.out.println(jsObj.get("explaination")); results.put("explaination", jsObj.get("explaination")); JSONArray reqmts = (JSONArray) jsObj.get("true"); System.out.println("Let me look out for the places that contains "); List<String> lis = new ArrayList<>(); JSONObject locObj = (JSONObject) jsParser.parse(freReader); JSONArray jsArray = (JSONArray) locObj.get("CHENNAI"); Iterator<JSONArray> ite = reqmts.iterator(); int k = 0; String resQuery = "START n=node:restaurant('withinDistance:[" + jsArray.get(0) + "," + jsArray.get(1) + ",7.5]') where"; Iterator<JSONArray> ite1 = reqmts.iterator(); while (ite1.hasNext()) System.out.println(ite1.next()); while (ite.hasNext()) { lis.add("n.type=" + "'" + ite.next() + "'"); if (k == 0) resQuery += " " + lis.get(k); else resQuery += " or " + lis.get(k); //System.out.println(attrib); k++; } resQuery += " return n.name,n.place,n.type"; File writeTo = new File( "/home/rishav12/NetBeansProjects/LuceneIndexDemo/filestoIndex1/" + names.get(0)); FileOutputStream fop = new FileOutputStream(writeTo, true); String writeTOFile = s + "\n"; fop.write(writeTOFile.getBytes()); //System.out.println(resQuery); ResultSet res = con.createStatement().executeQuery(resQuery); JSONArray resSet = new JSONArray(); while (res.next()) { System.out.println(" name:" + res.getString("n.name") + " located:" + res.getString("n.place") + " type:" + res.getString("n.type")); JSONObject jsPart = new JSONObject(); jsPart.put("name", res.getString("n.name")); jsPart.put("located", res.getString("n.place")); jsPart.put("type", res.getString("n.type")); resSet.add(jsPart); } results.put("results", resSet); File resultFile = new File("result.json"); FileOutputStream fop1 = new FileOutputStream(resultFile); System.out.println(results); fop1.write(results.toJSONString().getBytes()); //String resQuery="START n=node:restaurant('withinDistance:[40.7305991, -73.9865812,10.0]') where n.coffee=true return n.name,n.address;"; //System.out.println("Sir these results are for some coffee shops nearby NEW YORK"); //ResultSet res=con.createStatement().executeQuery(resQuery); //while(res.next()) //System.out.println("name: "+res.getString("n.name")+" address: "+res.getString("n.address")); } catch (org.json.simple.parser.ParseException ex) { Logger.getLogger(LuceneIndexDemo.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:gov.nasa.jpl.xdata.nba.impoexpo.parse.ParseUtil.java
public static List<PlayerStats> parsePlayerStats(JSONObject jsonObject) { JSONArray resultSets = (JSONArray) jsonObject.get("resultSets"); JSONObject infoObject = (JSONObject) resultSets.get(4); JSONArray rowSet = (JSONArray) infoObject.get("rowSet"); List<PlayerStats> result = new ArrayList<PlayerStats>(); for (Object rowObject : rowSet) { JSONArray row = (JSONArray) rowObject; result.add(PlayerStats.newBuilder() .setGamePlayerStatsId(row.get(0) == null ? -1 : Long.parseLong((String) row.get(0))) .setPlayerStatsTeamId(row.get(1) == null ? -1 : (Long) row.get(1)) .setPlayerStatsTeamAbbreviation(row.get(2) == null ? "" : (String) row.get(2)) .setPlayerStatsTeamCity(row.get(3) == null ? "" : (String) row.get(3)) .setPlayerStatsPlayerId(row.get(4) == null ? -1 : (Long) row.get(4)) .setPlayerName(row.get(5) == null ? "" : (String) row.get(5)) .setStartPosition(row.get(6) == null ? "" : (String) row.get(6)) .setComment(row.get(7) == null ? "" : (String) row.get(7)) .setPlayerStatsMin(row.get(8) == null ? "" : (String) row.get(8)) .setPlayerStatsFgm(row.get(9) == null ? -1 : (Long) row.get(9)) .setPlayerStatsFga(row.get(10) == null ? -1 : (Long) row.get(10)) .setPlayerStatsfgPct(row.get(11) == null ? -1 : Math.round((Double.parseDouble(row.get(11).toString().trim())) * 100)) .setPlayerStatsfg3m(row.get(12) == null ? -1 : (Long) row.get(12)) .setPlayerStatsfg3a(row.get(13) == null ? -1 : (Long) row.get(13)) .setPlayerStatsfg3Pct(row.get(14) == null ? -1 : Math.round((Double.parseDouble(row.get(14).toString().trim())) * 100)) .setPlayerStatsftm(row.get(15) == null ? -1 : (Long) row.get(15)) .setPlayerStatsfta(row.get(16) == null ? -1 : (Long) row.get(16)) .setPlayerStatsftPct(row.get(17) == null ? -1 : Math.round((Double.parseDouble(row.get(17).toString().trim())) * 100)) .setPlayerStatsoreb(row.get(18) == null ? -1 : (Long) row.get(18)) .setPlayerStatsdreb(row.get(19) == null ? -1 : (Long) row.get(19)) .setPlayerStatsreb(row.get(20) == null ? -1 : (Long) row.get(20)) .setPlayerStatsast(row.get(21) == null ? -1 : (Long) row.get(21)) .setPlayerStatsstl(row.get(22) == null ? -1 : (Long) row.get(22)) .setPlayerStatsblk(row.get(23) == null ? -1 : (Long) row.get(23)) .setPlayerStatsto(row.get(24) == null ? -1 : (Long) row.get(24)) .setPlayerStatspf(row.get(25) == null ? -1 : (Long) row.get(25)) .setPlayerStatsPts(row.get(26) == null ? -1 : (Long) row.get(26)) .setPlayerStatsPlusMinus(row.get(27) == null ? -1 : (Long) row.get(27)).build()); }/* w w w . ja v a2 s . com*/ return result; }
From source file:com.apigee.edge.config.utils.ConsolidatedConfigReader.java
/** * Example Hierarchy/* w w w .j a va 2 s. co m*/ * orgConfig.developerApps.<developerId>.apps * * Returns Map of * <developerId> => [ {app1}, {app2}, {app3} ] */ public static Map<String, List<String>> getOrgConfigWithId(File configFile, String scope, String resource) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); Map<String, List<String>> out = null; List<String> outStrs = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONObject edgeConf = (JSONObject) parser.parse(bufferedReader); if (edgeConf == null) return null; // orgConfig JSONObject scopeConf = (JSONObject) edgeConf.get(scope); if (scopeConf == null) return null; // orgConfig.developerApps Map sConfig = (Map) scopeConf.get(resource); if (sConfig == null) return null; // orgConfig.developerApps.<developerId> Iterator it = sConfig.entrySet().iterator(); out = new HashMap<String, List<String>>(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); JSONArray confs = (JSONArray) pair.getValue(); outStrs = new ArrayList<String>(); for (Object conf : confs) { outStrs.add(((JSONObject) conf).toJSONString()); } out.put((String) pair.getKey(), outStrs); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }
From source file:com.hurence.logisland.processor.networkpacket.utils.PcapUtils.java
public static String getSessionKey(JSONObject message) { String srcIp = (String) message.get("ip_src_addr"); String dstIp = (String) message.get("ip_dst_addr"); Long protocol = (Long) message.get("ip_protocol"); Long srcPort = (Long) message.get("ip_src_port"); Long dstPort = (Long) message.get("ip_dst_port"); Long ipId = (Long) message.get("ip_id"); String ipIdString = ipId == null ? null : ipId.toString(); Long fragmentOffset = (Long) message.get("frag_offset"); String fragmentOffsetString = fragmentOffset == null ? null : fragmentOffset.toString(); return PcapUtils.getSessionKey(srcIp, dstIp, protocol.toString(), srcPort.toString(), dstPort.toString(), ipIdString, fragmentOffsetString); }
From source file:fr.zcraft.zlib.tools.mojang.UUIDFetcher.java
/** * Fetches the UUIDs of the given list of player names from the Mojang API with one request for * them all.//from w w w . jav a2 s .co m * * <p><b>WARNING: this method needs to be called from a dedicated thread, as the requests to * Mojang are executed directly in the current thread and, due to the Mojang API rate limit, the * thread may be frozen to wait a bit between requests if a lot of UUID are requested.</b></p> * * This method may not be able to retrieve UUIDs for some players with old accounts. For them, * use {@link #fetchRemaining(Collection, Map)}. * * @param names A list of player names. * * @return A map linking a player name to his Mojang {@link UUID}. * @throws IOException If an exception occurs while contacting the Mojang API. */ static private Map<String, UUID> rawFetch(List<String> names) throws IOException { Map<String, UUID> uuidMap = new HashMap<>(); HttpURLConnection connection = getPOSTConnection(PROFILE_URL); writeBody(connection, names); JSONArray array; try { array = (JSONArray) readResponse(connection); } catch (ParseException ex) { throw new IOException("Invalid response from server, unable to parse received JSON : " + ex.toString()); } if (array == null) return uuidMap; List<String> remainingNames = new ArrayList<String>(); remainingNames.addAll(names); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String foundName = (String) jsonProfile.get("name"); String name = null; for (String requestedName : remainingNames) { if (requestedName.equalsIgnoreCase(foundName)) { name = requestedName; break; } } if (name == null) { name = foundName; } else { remainingNames.remove(name); } String id = (String) jsonProfile.get("id"); uuidMap.put(name, fromMojangUUID(id)); } return uuidMap; }