Package org.json.simple

Examples of org.json.simple.JSONArray


                  Map params = new HashMap();
                  params.put( "id", new Long( id ));
                  if ( sid != null )params.put( "sid", sid );
                  params.put( "content", JSONObject.escape( content ));
 
                  JSONArray  l_matches = new JSONArray();
                 
                  params.put( "matches", l_matches );
                 
                  for (int i=0;i<matches.size();i++){
                   
                    String[]  match = (String[])matches.get(i);
                   
                    JSONArray  l_match = new JSONArray();
                   
                    l_matches.add( l_match );
                   
                    for (int j=0;j<match.length;j++){
                     
                      l_match.add( match[j] );
                    }
                  }
                               
                  sendBrowserMessage( "metasearch", "testTemplateCompleted", params );
       
View Full Code Here


    view.render(mav.getModel(), request, response);
    response.flushBuffer();
    Object json = new JSONParser().parse(response.getContentAsString());
    Assert.assertTrue(json instanceof JSONObject);
    JSONObject jsonObject = (JSONObject) json;
    JSONArray features = (JSONArray) jsonObject.get("features");
    JSONObject feature = (JSONObject) features.get(0);
    JSONObject geometry = (JSONObject) feature.get("geometry");
    GeometryJSON g = new GeometryJSON(0);
    Geometry m = g.read(geometry.toJSONString());
    Envelope envelope = new Envelope(0, 1, 0, 1);
    Geometry orig = JTS.toGeometry(envelope);
View Full Code Here

        File tempJson = File.createTempFile("Standard1", ".json");
        SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[]{asHex("rowExclude")});
       
        JSONObject json = (JSONObject)JSONValue.parse(new FileReader(tempJson));
       
        JSONArray rowA = (JSONArray)json.get(asHex("rowA"));
        JSONArray colA = (JSONArray)rowA.get(0);
        assert hexToBytes((String)colA.get(1)).equals(ByteBufferUtil.bytes("valA"));

        JSONArray colExp = (JSONArray)rowA.get(1);
        assert ((Long)colExp.get(4)) == 42;
        assert ((Long)colExp.get(5)) == nowInSec;
       
        JSONArray rowB = (JSONArray)json.get(asHex("rowB"));
        JSONArray colB = (JSONArray)rowB.get(0);
        assert !(Boolean)colB.get(3);

        JSONArray rowExclude = (JSONArray)json.get(asHex("rowExclude"));
        assert rowExclude == null;
    }
View Full Code Here

       
        JSONObject json = (JSONObject)JSONValue.parse(new FileReader(tempJson));
       
        JSONObject rowA = (JSONObject)json.get(asHex("rowA"));
        JSONObject superA = (JSONObject)rowA.get(cfamily.getComparator().getString(ByteBufferUtil.bytes("superA")));
        JSONArray subColumns = (JSONArray)superA.get("subColumns");
        JSONArray colA = (JSONArray)subColumns.get(0);
        JSONObject rowExclude = (JSONObject)json.get(asHex("rowExclude"));
        assert hexToBytes((String)colA.get(1)).equals(ByteBufferUtil.bytes("valA"));
        assert !(Boolean)colA.get(3);
        assert rowExclude == null;
    }
View Full Code Here

    ApplicationStatus as = fireApplication.getStatus();
    JSONObject jsonObject = new JSONObject();

    jsonObject.put("status", new Integer(as.getCurrentState()));

    JSONArray errorCodeJson = new JSONArray();
    errorCodeJson.addAll(as.getErrorCodes());
    jsonObject.put("errorCodes", errorCodeJson);

    response.setStatus(HttpServletResponse.SC_OK);
    try {
      response.getWriter().println(jsonObject.toString());
View Full Code Here

      HttpServletResponse resp) {
    JSONObject devices = new JSONObject();

    // pumps
    List pumps = fireApplication.getPumps();
    JSONArray pumpsArray = new JSONArray();
    for (Iterator it = pumps.iterator(); it.hasNext();) {
      EndPointService es = (EndPointService) it.next();
      String name = es.getName();
      String friendlyName = getDeviceFriendlyNameId(es);
      name = name + " " + friendlyName;

      // remove first # from friendlyname
      friendlyName = friendlyName.replaceAll("#", "");

      String id = PUMP_PREFIX_ID + friendlyName;
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, ZIGBEE_TECHNO);
      properties.put(IMG_PROP, PUMP_IMG);
      JSONObject pumpJs = new JSONObject(properties);
      pumpsArray.add(pumpJs);
    }
   
    // GreenNet switches is also viewed as a pump (i.e. actuator)
    List greenNetSwitches = fireApplication.getGreenNetSwitches();
    for(Iterator it = greenNetSwitches.iterator(); it.hasNext();) {
      Device greenNetSwitch = (Device) it.next();
      String id = ((Actuator)greenNetSwitch).getNode().getIdentifier();
      String name = "Air extractor";
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, GREENNET_TECHNO);
      properties.put(IMG_PROP, GREENNET_AIR_EJECTOR_IMG);
      JSONObject pumpJs = new JSONObject(properties);
      pumpsArray.add(pumpJs);
    }
    devices.put(PUMPS_PROP, pumpsArray);

    // ias zones
    List zones = fireApplication.getZoneDevices();
    JSONArray zonesArray = new JSONArray();
    for (Iterator it = zones.iterator(); it.hasNext();) {
      EndPointService es = (EndPointService) it.next();
      String name = es.getName();
      String friendlyName = getDeviceFriendlyNameId(es);
      name = name + " " + friendlyName;

      // remove first # from friendlyname
      friendlyName = friendlyName.replaceAll("#", "");
      String id = IAS_ZONES_PREFIX_ID + friendlyName;
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, ZIGBEE_TECHNO);
      properties.put(IMG_PROP, SMOKE_DETECTOR_IMG);
      JSONObject zoneJs = new JSONObject(properties);
      zonesArray.add(zoneJs);
    }
    devices.put(IAS_ZONES_PROP, zonesArray);

    // warning devices
    List warnings = fireApplication.getWarningDevices();
    JSONArray warningArray = new JSONArray();
    for (Iterator it = warnings.iterator(); it.hasNext();) {
      EndPointService es = (EndPointService) it.next();
      String name = es.getName();
      String friendlyName = getDeviceFriendlyNameId(es);
      name = name + " " + friendlyName;

      // remove first # from friendlyname
      friendlyName = friendlyName.replaceAll("#", "");
      String id = IAS_WARNING_PREFIX_ID + friendlyName;
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, ZIGBEE_TECHNO);
      properties.put(IMG_PROP, WARNING_IMG);
      JSONObject warningJs = new JSONObject(properties);
      warningArray.add(warningJs);
    }
   
    // x3d dimmers are also considered as warning devices
    List x3dDimmers = fireApplication.getX3DDimmers();
    int index = 1;
    for(Iterator it = x3dDimmers.iterator(); it.hasNext();) {
      X3DLightDimmer dimmer = (X3DLightDimmer) it.next();
     
      String id = X3D_DIMMER_PREFIX_ID + dimmer.getX3DDevice().getDeviceUri();
      id = id.replaceAll(" ", "");
      id = id.replaceAll("/", "");
      id = id.replaceAll(":", "");
      String name = "X3D Dimmer #" + index;
      index++;
     
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, X3D_TECHNO);
      properties.put(IMG_PROP, X3D_DIMMER_IMG);
      JSONObject warningJs = new JSONObject(properties);
      warningArray.add(warningJs);
    }
   
    // hue light are also considered as warning devices
    List hueLights = fireApplication.getHueLights();
    for(Iterator it = hueLights.iterator(); it.hasNext();) {
      HueLightDevice hld = (HueLightDevice) it.next();
      String name = hld.getName();
      String id = HUE_PREFIX_ID + hld.getId();
     
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, HUE_TECHNO);
      properties.put(IMG_PROP, HUE_LIGHT_IMG);
      JSONObject warningJs = new JSONObject(properties);
      warningArray.add(warningJs);
    }
    devices.put(IAS_WARNING_PROP, warningArray);
   
   
View Full Code Here

        if (this.localizedAlertKey != null) {
          alert.put(ALERT_LOC_KEY, this.localizedAlertKey);

          if (this.localizedAlertArguments != null) {
            final JSONArray alertArgs = new JSONArray();

            for (final String arg : this.localizedAlertArguments) {
              alertArgs.add(arg);
            }

            alert.put(ALERT_ARGS_KEY, alertArgs);
          }
        }
View Full Code Here

      final JSONObject aps = this.extractApsObjectFromPayloadString(this.builder.buildWithDefaultMaximumLength());
      final JSONObject alert = (JSONObject) aps.get("alert");

      assertEquals(alertKey, alert.get("loc-key"));

      final JSONArray argsArray = (JSONArray) alert.get("loc-args");
      assertEquals(alertArgs.length, argsArray.size());
      assertTrue(argsArray.containsAll(java.util.Arrays.asList(alertArgs)));
    }
  }
View Full Code Here

      Set<String> topics = topicObj.keySet();
      Iterator<String> topicIt = topics.iterator();
      while (topicIt.hasNext()) { // for each topic
        String topic = topicIt.next();
        clusterMembership.put(topic, new Clusters());
        JSONArray clusters = (JSONArray) ((JSONObject) topicObj.get(topic)).get("clusters");
        Iterator<JSONArray> clusterIt = clusters.iterator();
        while (clusterIt.hasNext()) { // for each cluster in the topic
          JSONArray cluster = (JSONArray) clusterIt.next();
          Cluster c = new Cluster();
          Iterator<String> clusterMemberIt = cluster.iterator();
          while (clusterMemberIt.hasNext()) { // for each docId in the cluster
            String member = clusterMemberIt.next();
            long memberId = Long.parseLong(member);
            c.add(memberId);
          }
          clusterMembership.get(topic).add(c);
        }
      }
    } catch (Exception e) {
      err.println("Error reading training data.");
      e.printStackTrace();
      System.exit(-1);
    }
   
    // instantiate search client
    TrecSearchThriftClient client = new TrecSearchThriftClient(params.getParamValue(HOST_OPTION),
        trainingPort, group, token);

    SimpleSearcher searcher = new SimpleSearcher(client, numResults);
   
    err.println("=== Train Queries ===");
   
    List<Double> thresholds = new ArrayList<Double>();
    double averageThreshold = 0;
    Iterator<GQuery> queryIterator = trainingQueries.iterator();
    while(queryIterator.hasNext()) {
      GQuery query = queryIterator.next();
     
      Map<Long, TResult> seenResults = searcher.search(query);
     
      SimpleJaccardClusterer clusterer = new SimpleJaccardClusterer(new ArrayList<TResult>(seenResults.values()));
     
      // sweep through jaccard steps, calculating F1
      double maxF1 = 0;
      double maxF1Threshold = 1;
      for (double j = 1.0; j >= 0.0; j -= stepSize) { // for each jaccard threshold step
        Clusters clusters = clusterer.cluster(j);
       
        // all clusters are created now, get a finalized set of results
        Set<Long> allResults = new HashSet<Long>(seenResults.keySet());
        allResults.removeAll(clusters.getAllClusteredResults()); // allResults includes unclustered plus one representative from each cluster
        for (Cluster c : clusters) {
          allResults.add(c.getFirstMember());
        }
       
        // calculate f1 on the finalized set
        Clusters seenClusters = new Clusters();
        Clusters trueClusters = clusterMembership.get(query.getTitle());
        Iterator<Long> resultIt = allResults.iterator();
        while (resultIt.hasNext()) {
          long result = resultIt.next();
          Cluster trueCluster = trueClusters.findCluster(result);
          if (trueCluster != null) { // if it is relevant, it will have a true cluster; if this is null, it's non-relevant
            seenClusters.add(trueCluster);
          }
        }
       
        int numRetrievedClusters = seenClusters.size();
        int numResultsReturned = allResults.size();
        int numTrueClusters = trueClusters.size();

        double precision = 0;
        double recall = 0;
        double f1 = 0;
        if (evalType.equals("unweighted")) {
          precision = numRetrievedClusters / (double) numResultsReturned;
          recall = numRetrievedClusters / (double) numTrueClusters;
          f1 = 2 * precision * recall / (precision + recall);
        } else {       
          // for weighted measurements, we need the weight of each cluster
          int retrievedWeight = 0;
          for (Cluster cluster : seenClusters) {
            int w = cluster.getWeight(query, qrels);
            retrievedWeight += w;
          }
          int resultsWeight = 0;
          for (long result : allResults) {
            int w = 0;
            if (seenClusters.findCluster(result) == null)
            resultsWeight += w;
          }
          int trueWeight = 0;
          for (Cluster cluster : trueClusters) {
            int w = cluster.getWeight(query, qrels);
            trueWeight += w;
          }
         
          precision = retrievedWeight / (double) resultsWeight; // <--- ??????
          recall = retrievedWeight / (double) trueWeight;
View Full Code Here

      JSONObject configs,
      JSONObject prefs) {
    Set<String> settings = new LinkedHashSet<>();
    Set<String> settingsToRemove = new HashSet<>();
    { // settings from config
      JSONArray s = (JSONArray) configs.get(settingsListName);
      if (s != null) {
        @SuppressWarnings("unchecked")
        Iterator<String> iterator = s.iterator();
        while (iterator.hasNext()) {
          settings.add(iterator.next());
        }
      }
    }
    { // settings from preference
      JSONArray s = (JSONArray) prefs.get(settingsListName);
      if (s != null) {
        @SuppressWarnings("unchecked")
        Iterator<String> iterator = s.iterator();
        while (iterator.hasNext()) {
          settings.add(iterator.next());
        }
      }
    }
    { // to-remove settings from preference
      JSONArray s = (JSONArray) prefs.get(TO_REMOVE_PREFIX + settingsListName);
      if (s != null) {
        @SuppressWarnings("unchecked")
        Iterator<String> iterator = s.iterator();
        while (iterator.hasNext()) {
          settingsToRemove.add(iterator.next());
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.json.simple.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.