List of usage examples for org.json.simple.parser JSONParser parse
public Object parse(Reader in) throws IOException, ParseException
From source file:it.polimi.logging.LogMessageUtils.java
public static String getTopicReply(String message) { JSONParser parser = new JSONParser(); JSONObject jsonMsg;/* ww w . ja va2 s .co m*/ String topic = ""; try { jsonMsg = (JSONObject) parser.parse(message); topic = (String) jsonMsg.get(JsonStrings.TOPIC_REPLY); return topic; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.apigee.edge.config.utils.ConfigReader.java
/** * Example Hierarchy//from w w w. j av a 2 s . co m * envConfig.cache.<env>.caches * * Returns List of * [ {cache1}, {cache2}, {cache3} ] */ public static List getEnvConfig(String env, File configFile) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); ArrayList out = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONArray configs = (JSONArray) parser.parse(bufferedReader); if (configs == null) return null; out = new ArrayList(); for (Object config : configs) { out.add(((JSONObject) config).toJSONString()); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }
From source file:com.github.lgi2p.obirs.utils.JSONConverter.java
public static RefinedObirsQuery parseRefinedObirsQuery(SM_Engine engine, String jsonQuery) throws ParseException, IOException, Exception { logger.info("parsing json refined query"); logger.info("query: " + jsonQuery); jsonQuery = jsonQuery.replace("\n", ""); jsonQuery = jsonQuery.replace("\r", ""); JSONParser parser = new JSONParser(); Object obj = parser.parse(jsonQuery); JSONObject jsonObject = (JSONObject) obj; JSONObject _query = (JSONObject) jsonObject.get("query"); StringWriter jsQuery = new StringWriter(); _query.writeJSONString(jsQuery);//from w w w . j a v a 2s. co m ObirsQuery obirsQuery = parseObirsJSONQuery(engine, jsQuery.toString()); List<URI> selectedItemURIs = toURIs((List<String>) jsonObject.get("selectedItemURIs")); List<URI> rejectedItemURIs = toURIs((List<String>) jsonObject.get("rejectedItemURIs")); return new RefinedObirsQuery(obirsQuery, selectedItemURIs, rejectedItemURIs); }
From source file:com.apigee.edge.config.utils.ConfigReader.java
/** * Example Hierarchy/*from ww w. j av a 2 s .c o m*/ * orgConfig.apiProducts * * Returns List of * [ {apiProduct1}, {apiProduct2}, {apiProduct3} ] */ // TODO convert parse exception error message more human friendly public static List getOrgConfig(File configFile) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); ArrayList out = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONArray configs = (JSONArray) parser.parse(bufferedReader); if (configs == null) return null; out = new ArrayList(); for (Object config : configs) { out.add(((JSONObject) config).toJSONString()); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }
From source file:it.polimi.logging.LogMessageUtils.java
public static LogType getLogType(String message) { JSONParser parser = new JSONParser(); JSONObject jsonMsg;//from ww w. ja v a 2s . co m String logType = ""; try { jsonMsg = (JSONObject) parser.parse(message); logType = (String) jsonMsg.get(JsonStrings.LOG_TYPE); return LogType.valueOf(logType); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:IrqaQuery.java
public static void batch_query(String basedir, String indexpath) throws Exception { indexpath = basedir + "/index_all" + indexpath + "/"; String stopwords = basedir + "/stopwords.txt"; IrqaQuery lp = new IrqaQuery(); JSONParser parser = new JSONParser(); JSONArray questions = (JSONArray) parser.parse(new FileReader(basedir + "/data/questions.json")); long startTime = System.currentTimeMillis(); int answercount = 0; int questioncount = 0; for (Object o : questions) { JSONObject q = (JSONObject) o;// ww w. j a v a 2 s . co m String query = (String) q.get("question"); String gold_id = (String) q.get("paragraph_id"); List<Document> docs = lp.query(indexpath, stopwords, query, 5, "BM25"); questioncount++; for (Document d : docs) { String docid = d.get("docid"); if (docid.equals(gold_id)) { // System.out.println(docid); answercount = answercount + 1; break; } } if (questioncount % 1000 == 0) { long midtime = System.currentTimeMillis() - startTime; System.out.format("[%d] midtime=%f\n", questioncount, midtime / 1000.0); } } System.out.format("acc=%f\t%d\t%d\n", answercount * 1.0 / questioncount * 100, answercount, questioncount); long estimatedTime = System.currentTimeMillis() - startTime; System.out.println(estimatedTime / 1000.0); }
From source file:it.polimi.logging.LogMessageUtils.java
public static String getSenderID(String msgJson) { JSONParser parser = new JSONParser(); JSONObject jsonMsg;/*from w w w . j a v a 2 s . c om*/ String senderID = ""; try { jsonMsg = (JSONObject) parser.parse(msgJson); senderID = (String) jsonMsg.get(JsonStrings.SENDER); return senderID; } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.apigee.edge.config.utils.ConfigReader.java
/** * API Config//from www.j av a 2 s. c o m * [ {apiProduct1}, {apiProduct2}, {apiProduct3} ] */ public static List getAPIConfig(File configFile) throws ParseException, IOException { Logger logger = LoggerFactory.getLogger(ConfigReader.class); JSONParser parser = new JSONParser(); ArrayList out = null; try { BufferedReader bufferedReader = new BufferedReader(new java.io.FileReader(configFile)); JSONArray resourceConfigs = (JSONArray) parser.parse(bufferedReader); if (resourceConfigs == null) return null; out = new ArrayList(); for (Object config : resourceConfigs) { out.add(((JSONObject) config).toJSONString()); } } catch (IOException ie) { logger.info(ie.getMessage()); throw ie; } catch (ParseException pe) { logger.info(pe.getMessage()); throw pe; } return out; }
From source file:luceneindexdemo.LuceneIndexDemo.java
public static void missOperation(String type) throws FileNotFoundException, IOException, org.json.simple.parser.ParseException, SQLException { //JSONObject jsObject=new JSONObject(); System.out.println("this brings out all your connection with the person you miss"); String query = "match (n:People)-[r:KNOWS]-(b:People) where n.name='" + user + "' and r.relType='" + type + "' return filter(x in n.interest where x in b.interest) as common,b.name"; Connection con = DriverManager.getConnection("jdbc:neo4j://localhost:7474/"); ResultSet rs = con.createStatement().executeQuery(query); JSONParser jsParser = new JSONParser(); FileReader freReader = new FileReader("/home/rishav12/NetBeansProjects/LuceneIndexDemo/location.json"); JSONObject jsono = (JSONObject) jsParser.parse(freReader); JSONArray jslocArray = (JSONArray) jsono.get("CHENNAI"); int count = 0; while (rs.next()) { System.out.println(rs.getString("b.name")); String searchQuery = "start n=node:restaurant('withinDistance:[" + jslocArray.get(0) + "," + jslocArray.get(1) + ",13.5]') where "; JSONArray jsArray = (JSONArray) jsParser.parse(rs.getString("common")); Iterator<JSONArray> iterJsArray = jsArray.iterator(); count++;//from w w w . j a v a2 s.co m int k = 0; int flag = 0; while (iterJsArray.hasNext()) { flag = 1; if (k == 0) { searchQuery = searchQuery + "n.type='" + iterJsArray.next() + "'"; k = k + 1; } else searchQuery = searchQuery + " or n.type='" + iterJsArray.next() + "'"; } if (flag == 1) { searchQuery += " return n.name,n.type"; ResultSet commonInterest = con.createStatement().executeQuery(searchQuery); System.out.println("Sir based on your common interests with " + rs.getString("b.name") + " \ni will plan out something nearby you"); while (commonInterest.next()) { System.out .println(commonInterest.getString("n.name") + " " + commonInterest.getString("n.type")); } } else { System.err.println("you do not seem to share any common interest with" + rs.getString("b.name")); } } return; }
From source file:co.mcme.animations.animations.MCMEAnimation.java
public static MCMEAnimation createInstance(File configFile) throws IOException, ParseException { JSONParser parser = new JSONParser(); Object obj = parser.parse(new FileReader(configFile)); JSONObject conf = (JSONObject) obj;//w w w . j a v a 2 s .c om String animationType = (String) conf.get("type"); if (animationType.equals("one-time")) { OneTimeAnimation result = new OneTimeAnimation(configFile); return result; } else if (animationType.equals("two-way")) { TwoWayAnimation result = new TwoWayAnimation(configFile); return result; } else if (animationType.equals("loop")) { LoopAnimation result = new LoopAnimation(configFile); return result; } else { return null; } }