org.apache.wink.json4j.JSONException Java Examples
The following examples show how to use
org.apache.wink.json4j.JSONException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GaussianProcessLDPLMeanModel.java From BLELocalization with MIT License | 6 votes |
public JSONObject toJSON(){ JSONObject json = new JSONObject(); JSONObject LDPLJSON = new JSONObject(); JSONObject GPJSON = new JSONObject(); JSONObject optJSON = new JSONObject(); try { double[] params = getParams(); LDPLJSON.put("n", params[0]).put("A", params[1]).put("fa", params[2]).put("fb", params[3]).put(HDIFF, hDiff); GPJSON.put("lengthes", new Double[]{lengthes[0], lengthes[1], lengthes[2]}); GPJSON.put("sigmaP", stdev).put("sigmaN", sigmaN).put("useMask", gpLDPL.getUseMask()?1:0).put("constVar", gpLDPL.getOptConstVar()); optJSON.put("optimizeHyperParameters", doHyperParameterOptimize?1:0); json.put(LDPLParameters, LDPLJSON); json.put(GPParameters, GPJSON); json.put(OPTIONS, optJSON); } catch (JSONException e) { e.printStackTrace(); } return json; }
Example #2
Source File: FrameWriterJSONL.java From systemds with Apache License 2.0 | 6 votes |
public void writeFrameToHDFS(FrameBlock src, String fname, Map<String, Integer> schemaMap, long rlen, long clen) throws IOException, DMLRuntimeException, JSONException { //prepare file access JobConf job = new JobConf(ConfigurationManager.getCachedJobConf()); Path path = new Path( fname ); //if the file already exists on HDFS, remove it. HDFSTool.deleteFileIfExistOnHDFS( fname ); //validity check frame dimensions if( src.getNumRows() != rlen || src.getNumColumns() != clen ) { throw new IOException("Frame dimensions mismatch with metadata: " + src.getNumRows()+"x"+src.getNumColumns()+" vs "+rlen+"x"+clen+"."); } //core write (sequential/parallel) writeJSONLFrameToHDFS(path, job, src, rlen, clen, schemaMap); }
Example #3
Source File: GaussianProcessLDPLMeanMultiModel.java From BLELocalization with MIT License | 6 votes |
public void settingFromJSON(JSONObject json){ super.settingFromJSON(json); try { JSONObject ldplParams = json.getJSONObject(LDPLParameters); //LDPLParameters if(ldplParams.containsKey("lambdas")){ JSONArray jarray = ldplParams.getJSONArray("lambdas"); double[] lambdas = JSONUtils.array1DfromJSONArray(jarray); System.out.println("lambdas = "+jarray.toString()); gpLDPL.setStabilizeParameter(lambdas); }else{ System.out.println("The key for [lambdas] was not found."); optMultiHP = true; } } catch (JSONException e) { e.printStackTrace(); } }
Example #4
Source File: FrameWriterJSONL.java From systemds with Apache License 2.0 | 6 votes |
protected void writeJSONLFrameToFile(Path path, FileSystem fileSystem, FrameBlock src, int lowerRowBound, int upperRowBound, Map<String, Integer> schemaMap) throws IOException, JSONException { BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileSystem.create(path, true))); try { Iterator<String[]> stringRowIterator = src.getStringRowIterator(lowerRowBound, upperRowBound); while (stringRowIterator.hasNext()) { String[] row = stringRowIterator.next(); bufferedWriter.write(formatToJSONString(row, schemaMap) + "\n"); } } finally { IOUtilFunctions.closeSilently(bufferedWriter); } }
Example #5
Source File: FrameReaderJSONL.java From systemds with Apache License 2.0 | 6 votes |
public FrameBlock readFrameFromHDFS(String fname, Types.ValueType[] schema, Map<String, Integer> schemaMap, long rlen, long clen) throws IOException, DMLRuntimeException, JSONException { //prepare file access JobConf jobConf = new JobConf(ConfigurationManager.getCachedJobConf()); Path path = new Path(fname); FileSystem fileSystem = IOUtilFunctions.getFileSystem(path, jobConf); FileInputFormat.addInputPath(jobConf, path); //check existence and non-empty file checkValidInputFile(fileSystem, path); Types.ValueType[] lschema = createOutputSchema(schema, clen); String[] lnames = createOutputNamesFromSchemaMap(schemaMap); FrameBlock ret = createOutputFrameBlock(lschema, lnames, rlen); readJSONLFrameFromHDFS(path, jobConf, fileSystem, ret, schema, schemaMap); return ret; }
Example #6
Source File: FrameWriterJSONL.java From systemds with Apache License 2.0 | 6 votes |
protected JSONObject gernerateJSONObjectFromPath(String[] path, int index, Object value, JSONObject jsonObject) throws JSONException { JSONObject temp = new JSONObject(); if(index == path.length - 1){ if(jsonObject != null){ jsonObject.put(path[index], value); return jsonObject; } temp.put(path[index], value); return temp; } JSONObject newJsonObject = (jsonObject == null)? null : jsonObject.optJSONObject(path[index]); JSONObject ret = gernerateJSONObjectFromPath(path, index + 1, value, newJsonObject); if(newJsonObject == null && jsonObject != null){ jsonObject.put(path[index], ret); return null; } else if( ret == null){ return null; } temp.put(path[index], ret); return temp; }
Example #7
Source File: PoseRandomWalker.java From BLELocalization with MIT License | 6 votes |
@Override public void settingFromJSON(JSONObject json){ paramsJSON = json; try { double sigma = json.getDouble("sigma"); setSigma(sigma); // Set parameters for sensor data JSONObject oriParams = json.getJSONObject(SensorData.ORIENTATION_METER); ori = OrientationMeterFactory.create(oriParams); JSONObject pedoParams = json.getJSONObject(SensorData.PEDOMETER); pedo = PedometerFactory.create(pedoParams); // PoseSetting JSONObject poseSettingJSON = json.getJSONObject(PoseSetting.SIMPLE_NAME); this.poseSetting = PoseSetting.createFromJSON(poseSettingJSON); System.out.println("PoseData.setting : "+poseSetting.toString()); this.poseMotion = PoseMotion.create(poseSetting); } catch (JSONException e) { e.printStackTrace(); } }
Example #8
Source File: SyntheticDataGenerator.java From BLELocalization with MIT License | 6 votes |
public static SyntheticDataGenerator create(JSONObject json){ SyntheticDataGenerator gen = new SyntheticDataGenerator(); try{ JSONObject beaconJSON = json.getJSONObject("Beacon"); JSONObject motionJSON = json.getJSONObject("Motion"); gen.beaconGen = new SyntheticBeaconDataGenerator(beaconJSON); gen.motionGen = new SyntheticMotionDataGenerator(motionJSON); JSONObject randomJSON = json.getJSONObject("Random"); int seed = randomJSON==null ? 1234 : randomJSON.getInt("seed"); gen.beaconGen.setRandom(new Random(seed)); gen.motionGen.setRandom(new Random(seed)); }catch(JSONException e){ e.printStackTrace(); } return gen; }
Example #9
Source File: FrameWriterJSONL.java From systemds with Apache License 2.0 | 6 votes |
protected void writeJSONLFrameToFile(Path path, FileSystem fileSystem, FrameBlock src, int lowerRowBound, int upperRowBound, Map<String, Integer> schemaMap) throws IOException, JSONException { BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileSystem.create(path, true))); try { Iterator<String[]> stringRowIterator = src.getStringRowIterator(lowerRowBound, upperRowBound); while (stringRowIterator.hasNext()) { String[] row = stringRowIterator.next(); bufferedWriter.write(formatToJSONString(row, schemaMap) + "\n"); } } finally { IOUtilFunctions.closeSilently(bufferedWriter); } }
Example #10
Source File: BeaconFilterFactory.java From BLELocalization with MIT License | 6 votes |
public static BeaconFilter create(JSONObject json){ BeaconFilter bf = null; try{ String name = json.getString("name"); JSONObject params = json.getJSONObject("parameters"); for(BeaconFilter bfTemp: loader){ if(name.equals(bfTemp.getClass().getSimpleName())){ bf = bfTemp; bf.settingFromJSON(params); break; } } if(bf==null){ System.err.println(name + " is not supported in "+BeaconFilterFactory.class.getSimpleName()+"."); } }catch(JSONException e){ e.printStackTrace(); } return bf; }
Example #11
Source File: JSONGroupParser.java From ade with GNU General Public License v3.0 | 6 votes |
/** * Main logic for parsing the groups from the JSON file. Also does validation of the groups attributes. * @param groups JSONArray object that contains the groups parsed from the JSON file. * @param groupType the type of the groups in the JSONArray Object. * @return An ArrayList of Group Objects that contain the parsed information. * @throws JSONException * @throws AdeUsageException */ private List<Group> parseGroups(JSONArray groups, String groupType) throws JSONException, AdeUsageException{ if (groups.length() == 0) throw new AdeUsageException("No groups specified for group of type " + groupType); List<Group> currentGroups = new ArrayList<Group>(); for (int i = 0; i < groups.length(); i++){ JSONObject group = groups.getJSONObject(i); String name = group.getString("name"); String dataType = group.getString("dataType"); short evalOrder = group.getShort("evaluationOrder"); String ruleName = group.getString("ruleName"); if (!verifyStringParam(name, 200, "[a-zA-Z0-9_ ]*") || name.equalsIgnoreCase("unassigned") || !validateDataType(dataType) || evalOrder < 1 || !verifyStringParam(ruleName, 200, "[a-zA-Z0-9_ ]*")){ throw new AdeUsageException("Invalid parameters for a group of type " + groupType + " was specified"); } currentGroups.add(new Group(name, GroupType.valueOf(groupType), DataType.valueOf(dataType.toUpperCase()), evalOrder, ruleName)); } validateEvaluationOrderAndName(currentGroups); return currentGroups; }
Example #12
Source File: ModelBuilderCore.java From BLELocalization with MIT License | 6 votes |
public static ObservationModel buildObservationModel(JSONObject json, ProjectData projData){ ObservationModel model=null; try { String name = json.getString("name"); System.out.println("Building an observation model : "+name); for(ObservationModelFactory obsProv: obsLoader){ System.out.println("ObservationModelProvider="+obsProv.getClass().getSimpleName()); if(obsProv.hasModel(json)){ System.out.println("ObservationModelProvider="+obsProv.getClass().getSimpleName() +" is creating an observation model."); model = obsProv.create(json, projData); } } if(model==null){ System.err.println("Unknown observation model name: "+name); throw new RuntimeException(); } } catch (JSONException e) { e.printStackTrace(); } return model; }
Example #13
Source File: EncoderBin.java From systemds with Apache License 2.0 | 6 votes |
public EncoderBin(JSONObject parsedSpec, String[] colnames, int clen) throws JSONException, IOException { super( null, clen ); if ( !parsedSpec.containsKey(TfMethod.BIN.toString()) ) return; //parse column names or column ids List<Integer> collist = TfMetaUtils.parseBinningColIDs(parsedSpec, colnames); initColList(ArrayUtils.toPrimitive(collist.toArray(new Integer[0]))); //parse number of bins per column boolean ids = parsedSpec.containsKey("ids") && parsedSpec.getBoolean("ids"); JSONArray group = (JSONArray) parsedSpec.get(TfMethod.BIN.toString()); _numBins = new int[collist.size()]; for(int i=0; i < _numBins.length; i++) { JSONObject colspec = (JSONObject) group.get(i); int pos = collist.indexOf(ids ? colspec.getInt("id") : ArrayUtils.indexOf(colnames, colspec.get("name"))+1); _numBins[pos] = colspec.containsKey("numbins") ? colspec.getInt("numbins"): 1; } }
Example #14
Source File: ParticleFilterModelFactory.java From BLELocalization with MIT License | 5 votes |
@Override public boolean hasModel(JSONObject json) { try { String name = json.getString("name"); if(name.equals(ParticleFilter.class.getSimpleName())){ return true; }else if(name.equals(ParticleFilterWithSensor.class.getSimpleName())){ return true; } } catch (JSONException e) { e.printStackTrace(); } return false; }
Example #15
Source File: JSONUtils.java From BLELocalization with MIT License | 5 votes |
static public double[] array1DfromJSONArray(JSONArray jarray){ int n=jarray.size(); double[] vec = new double[n]; for(int i=0; i<n; i++){ try { vec[i] = jarray.getDouble(i); } catch (JSONException e) { e.printStackTrace(); } } return vec; }
Example #16
Source File: ObservationModelBuilder.java From BLELocalization with MIT License | 5 votes |
public ProjectData.Info loadInformation(JSONObject formatJSON){ ProjectData.Info projInfo = null; if(formatJSON.has(INFORMATION)){ try { JSONObject info = formatJSON.getJSONObject(INFORMATION); projInfo = new ProjectData.Info(info); System.out.println("information="+info.toString()); } catch (JSONException e) { e.printStackTrace(); } } return projInfo; }
Example #17
Source File: LikelihoodModelFactory.java From BLELocalization with MIT License | 5 votes |
public static LikelihoodModel create(JSONObject json){ LikelihoodModel likelihoodModel = null; try { if(json==null){ likelihoodModel = new NormalDist(); } else if(json!=null){ String name = json.getString("name"); JSONObject paramsJSON = json.getJSONObject("parameters"); for(LikelihoodModel lmTemp: loader){ if(name.equals(lmTemp.getClass().getSimpleName())){ likelihoodModel = lmTemp; likelihoodModel.settingFromJSON(paramsJSON); System.out.println(likelihoodModel.toString() + " was created."); break; } } if(likelihoodModel==null){ System.err.println(name+ " is not supported in " + LikelihoodModelFactory.class.getSimpleName() + "."); } } } catch (JSONException e) { e.printStackTrace(); } return likelihoodModel; }
Example #18
Source File: FederatedL2SVMTest.java From systemds with Apache License 2.0 | 5 votes |
@Test public void federatedL2SVMCPPrivateAggregationX1Exception() throws JSONException { rows = 1000; cols = 1; Map<String, PrivacyConstraint> privacyConstraints = new HashMap<>(); privacyConstraints.put("X1", new PrivacyConstraint(PrivacyLevel.PrivateAggregation)); federatedL2SVM(Types.ExecMode.SINGLE_NODE, privacyConstraints, null, PrivacyLevel.PrivateAggregation, false, null, true, DMLException.class); }
Example #19
Source File: FrameWriterJSONL.java From systemds with Apache License 2.0 | 5 votes |
protected String formatToJSONString(String[] values, Map<String, Integer> schemaMap) throws IOException, JSONException { if(schemaMap.size() != values.length){ throw new IOException("Schema Map and row mismatch. Cannot map " + values.length + " values to " + schemaMap.size() + " JSON Objects"); } JSONObject jsonObject = new JSONObject(); for (Map.Entry<String, Integer> entry : schemaMap.entrySet()) { String[] splits = entry.getKey().split("/"); Integer value = entry.getValue(); gernerateJSONObjectFromPath(splits, 1, values[value],jsonObject); } return jsonObject.toString(); }
Example #20
Source File: FederatedL2SVMTest.java From systemds with Apache License 2.0 | 5 votes |
@Test public void federatedL2SVMCPPrivatePrivateAggregationFederatedX1X2() throws JSONException { Map<String, PrivacyConstraint> privacyConstraints = new HashMap<>(); privacyConstraints.put("X1", new PrivacyConstraint(PrivacyLevel.Private)); privacyConstraints.put("X2", new PrivacyConstraint(PrivacyLevel.PrivateAggregation)); federatedL2SVM(Types.ExecMode.SINGLE_NODE, privacyConstraints, null, PrivacyLevel.Private, false, null, true, DMLException.class); }
Example #21
Source File: MapDataReaderBase.java From BLELocalization with MIT License | 5 votes |
protected String parseReadMethodBeacons(JSONObject formatJSON){ String readMethodBeacons = null; try { if(formatJSON.containsKey("map")){ readMethodBeacons = formatJSON.getJSONObject("map").getJSONObject("beacons").getString("readMethod"); }else{ readMethodBeacons = formatJSON.getJSONObject("beacons").getString("readMethod"); } } catch (JSONException e) { e.printStackTrace(); } return readMethodBeacons; }
Example #22
Source File: Pose.java From BLELocalization with MIT License | 5 votes |
public JSONObject toJSONObject(){ JSONObject json = null; try{ Pose p = this; json = super.toJSONObject(); json.put("orientation",p.orientation) .put("velocity",p.velocity); }catch(JSONException e){ e.printStackTrace(); } return json; }
Example #23
Source File: DBServlet.java From BLELocalization with MIT License | 5 votes |
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub List<String> list = MongoService.getInstance().getDBNames(); try { JSONArray json = new JSONArray(list); response.getWriter().append(json.toString()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example #24
Source File: DataManagerImpl.java From BLELocalization with MIT License | 5 votes |
@Override public String getProjectsDir() { if (settings == null) { return null; } try { return settings.getString("projects_path"); } catch (JSONException e) { e.printStackTrace(); } return null; }
Example #25
Source File: JSONHelper.java From systemds with Apache License 2.0 | 5 votes |
public static Object get(JSONObject jsonObject, String key) { Object result = null; try { if(jsonObject != null) { result = jsonObject.get(key); } } catch (JSONException e) { // ignore and return null } return result; }
Example #26
Source File: SyntheticMotionDataGenerator.java From BLELocalization with MIT License | 5 votes |
SyntheticMotionDataGenerator setJSON(JSONObject json){ try{ accStds = JSONUtils.array1DfromJSONArray(json.getJSONArray("accStds")); attStds = JSONUtils.array1DfromJSONArray(json.getJSONArray("attStds")); freq = json.getInt("freq"); dTS = 1000/freq; ampG = json.getDouble("ampG"); stepPerSec = json.getDouble("stepPerSec"); }catch(JSONException e){ e.printStackTrace(); } return this; }
Example #27
Source File: LocalizationStatus.java From BLELocalization with MIT License | 5 votes |
public void putJSONAdditional(String key, Object value){ try { jsonAdditional.put(key, value); } catch (JSONException e) { e.printStackTrace(); } }
Example #28
Source File: TestJSONGroupParser.java From ade with GNU General Public License v3.0 | 5 votes |
/** * Test to see if the groups and rules are parsed correctly. i.e. all the fields for both groups and rules * are the same before parsing the JSON and after parsing the JSON. * @throws JSONException * @throws IOException * @throws AdeException */ @Test public void testGroupsAndRulesCorrectlyParsed() throws JSONException, IOException, AdeException { List<Group> modelGroups = new ArrayList<Group>(); modelGroups.add(new Group("ModelGName1", GroupType.getGroupType(1), DataType.getDataType((short)1), 3, "prefixRule")); modelGroups.add(new Group("ModelGName2", GroupType.getGroupType(1), DataType.getDataType((short)1), 1, "postfixRule")); modelGroups.add(new Group("ModelGName3", GroupType.getGroupType(1), DataType.getDataType((short)1), 2, "SYS1Rule")); JSONObject modelGroup1 = createGroupFromList(modelGroups.get(0)); JSONObject modelGroup2 = createGroupFromList(modelGroups.get(1)); JSONObject modelGroup3 = createGroupFromList(modelGroups.get(2)); List<Rule> rules = new ArrayList<Rule>(); rules.add(new Rule("prefixRule", "PREFIX*", "Matches systems that start with PREFIX")); rules.add(new Rule("postfixRule", "*POSTFIX", "Matches systems that end with POSTFIX")); rules.add(new Rule("SYS1Rule", "SYS1", "Matches systems named SYS1")); JSONObject rule1 = createRuleFromList(rules.get(0)); JSONObject rule2 = createRuleFromList(rules.get(1)); JSONObject rule3 = createRuleFromList(rules.get(2)); modelArray.put(modelGroup1); modelArray.put(modelGroup2); modelArray.put(modelGroup3); rulesArray.put(rule1); rulesArray.put(rule2); rulesArray.put(rule3); writeToFileAndParseJSON(); Map<Integer, List<Group>> parsedGroupsByType = jsonGroupParser.getParsedGroupsByType(); List<Rule> parsedRules = jsonGroupParser.getParsedRules(); for (int i = 0 ; i < parsedRules.size(); i++){ assertRulesEqual(rules.get(i),parsedRules.get(i)); } for (GroupType group : GroupType.values()){ List<Group> parsedGroups = parsedGroupsByType.get(group.getValue()); for (int i = 0 ; i < parsedGroups.size(); i++){ assertGroupsEqual(modelGroups.get(i), parsedGroups.get(i)); } } }
Example #29
Source File: TestJSONGroupParser.java From ade with GNU General Public License v3.0 | 5 votes |
private void initializeJSON() throws JSONException{ rulesArray = new JSONArray(); jsonGroupObject.put("rules", rulesArray); JSONObject modelInfo = new JSONObject(); modelArray = new JSONArray(); modelInfo.put("modelgroups", modelArray); jsonGroupObject.put("groups", modelInfo); }
Example #30
Source File: TestJSONGroupParser.java From ade with GNU General Public License v3.0 | 5 votes |
/** * Preliminary initialization. Creates the skeleton of the JSON file. * @throws JSONException * @throws IOException */ @Before public void initialize() throws JSONException, IOException{ jsonGroupParser = new JSONGroupParser(); jsonGroupObject = new JSONObject(); initializeJSON(); jsonFile = new File(JSON_FILE_PATH); fileWriter = new FileWriter(jsonFile); }