Java Code Examples for org.json.JSONObject#sortedKeys()

The following examples show how to use org.json.JSONObject#sortedKeys() . 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: JsonStoryUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static String getActorByRoleFromEvent (JSONObject event, String role) throws JSONException {
    String actor = "";
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
        //  System.out.println("key = " + key);
        if (key.equalsIgnoreCase(role)) {
            JSONArray actors = actorObject.getJSONArray(key);
            for (int j = 0; j < actors.length(); j++) {
                String nextActor = actors.getString(j);
                nextActor = nextActor.substring(nextActor.lastIndexOf("/")+1);
                if (actor.indexOf(nextActor)==-1) {
                    actor += ":" +nextActor;
                }
                //break;
            }
        }
    }
    return actor;
}
 
Example 2
Source File: JsonStoryUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static ArrayList<String> getActorsByRoleFromEvent (JSONObject event, String role) throws JSONException {
    ArrayList<String> actorList = new ArrayList<String>();
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
        //  System.out.println("key = " + key);
        if (key.equalsIgnoreCase(role)) {
            JSONArray actors = actorObject.getJSONArray(key);
            for (int j = 0; j < actors.length(); j++) {
                String nextActor = actors.getString(j);
                nextActor = nextActor.substring(nextActor.lastIndexOf("/")+1);
                if (!actorList.contains(nextActor)) {
                    actorList.add(nextActor);
                }
            }
        }
    }
    return actorList;
}
 
Example 3
Source File: JsonStoryUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static String getfirstActorByRoleFromEvent (JSONObject event, String role) throws JSONException {
    String actor = "";
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
        //  System.out.println("key = " + key);
        if (key.equalsIgnoreCase(role)) {
            JSONArray actors = actorObject.getJSONArray(key);
            for (int j = 0; j < actors.length(); j++) {
                String nextActor = actors.getString(j);
                nextActor = nextActor.substring(nextActor.lastIndexOf("/")+1);
                actor += ":" + nextActor;
                break;
            }
        }
    }
    return actor;
}
 
Example 4
Source File: JsonStoryUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static String getActorFromEvent (JSONObject event, String actorString) throws JSONException {
    String actor = "";
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
        //  System.out.println("key = " + key);
        JSONArray actors = actorObject.getJSONArray(key);
        for (int j = 0; j < actors.length(); j++) {
            String nextActor = actors.getString(j);
            nextActor = nextActor.substring(nextActor.lastIndexOf("/")+1);
            if (nextActor.indexOf(actorString)>-1) {
                if (actor.indexOf(nextActor)==-1) {
                    actor += ":" +nextActor;
                }
            }
        }
    }
    return actor;
}
 
Example 5
Source File: JsonStoryUtil.java    From EventCoreference with Apache License 2.0 6 votes vote down vote up
static boolean hasActorInEvent (JSONObject event, ArrayList<String> actorList) throws JSONException {
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
        //  System.out.println("key = " + key);
        JSONArray actors = actorObject.getJSONArray(key);
        for (int j = 0; j < actors.length(); j++) {
            String nextActor = actors.getString(j);
            nextActor = nextActor.substring(nextActor.lastIndexOf("/") + 1);
            if (actorList.contains(nextActor)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 6
Source File: Util.java    From SI with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void printJSONObject(JSONObject obj){
	Iterator<String> it = obj.sortedKeys();
	while(it.hasNext()){
		try{
			String key = it.next();
			Object value = obj.get(key);
			System.out.println("["+key+"]-["+value+"]");
		} catch(JSONException e){
			System.err.println(e.getMessage());
			if(Lwm2mServerConfig.getInstance().isDebug()){
				e.printStackTrace();
			}
		}
	}
}
 
Example 7
Source File: Util.java    From SI with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void printJSONObject(JSONObject obj){
	Iterator<String> it = obj.sortedKeys();
	while(it.hasNext()){
		try{
			String key = it.next();
			Object value = obj.get(key);
			System.out.println("["+key+"]-["+value+"]");
		} catch(JSONException e){
			System.err.println(e.getMessage());
			if(Lwm2mServerConfig.getInstance().isDebug()){
				e.printStackTrace();
			}
		}
	}
}
 
Example 8
Source File: CreateMicrostory.java    From EventCoreference with Apache License 2.0 4 votes vote down vote up
public static ArrayList<JSONObject> getEventsThroughCoparticipation(ArrayList<JSONObject> events,
                                                             JSONObject event, int intersection)
        throws JSONException {
    ArrayList<JSONObject> coPartipantEvents = new ArrayList<JSONObject>();
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
        if (key.toLowerCase().startsWith("pb/")
                || key.toLowerCase().startsWith("fn/")
                || key.toLowerCase().startsWith("eso/")
                ) {
            JSONArray actors = actorObject.getJSONArray(key);
            for (int i = 0; i < events.size(); i++) {
                JSONObject oEvent = events.get(i);
                if (!oEvent.get("instance").toString().equals(event.get("instance").toString())) {
                    ///skip event itself
                    JSONObject oActorObject = oEvent.getJSONObject("actors");
                    Iterator oKeys = oActorObject.sortedKeys();
                    int cnt = 0;
                    while (oKeys.hasNext()) {
                        String oKey = oKeys.next().toString();
                        if (oKey.toLowerCase().startsWith("pb/")
                                || oKey.toLowerCase().startsWith("fn/")
                                || oKey.toLowerCase().startsWith("eso/")
                                ) {
                            JSONArray oActors = oActorObject.getJSONArray(oKey);
                          //  System.out.println("oActors.length() = " + oActors.length());
                           // System.out.println("oActors.toString() = " + oActors.toString());
                            if (countIntersectingDBpActor(actors,oActors)>=intersection) {
                                cnt++;
                                if (!coPartipantEvents.contains(oEvent)) {
                                    coPartipantEvents.add(oEvent);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return coPartipantEvents;
}
 
Example 9
Source File: CreateMicrostory.java    From EventCoreference with Apache License 2.0 4 votes vote down vote up
public static ArrayList<JSONObject> getEventsThroughCoparticipation(String entityFilter, ArrayList<JSONObject> events,
                                                             JSONObject event)
        throws JSONException {
    ArrayList<JSONObject> coPartipantEvents = new ArrayList<JSONObject>();
    JSONObject actorObject = event.getJSONObject("actors");
    Iterator keys = actorObject.sortedKeys();
    while (keys.hasNext()) {
        String key = keys.next().toString(); //role
      //  System.out.println("key = " + key);
        if (key.toLowerCase().startsWith("pb/")
                || key.toLowerCase().startsWith("fn/")
                || key.toLowerCase().startsWith("eso/")) {
            JSONArray actors = actorObject.getJSONArray(key);
            // System.out.println("actors.toString() = " + actors.toString());
            for (int i = 0; i < events.size(); i++) {
                JSONObject oEvent = events.get(i);
                if (!oEvent.get("instance").toString().equals(event.get("instance").toString())) {
                    ///skip event itself
                    JSONObject oActorObject = oEvent.getJSONObject("actors");
                    Iterator oKeys = oActorObject.sortedKeys();
                    while (oKeys.hasNext()) {
                        String oKey = oKeys.next().toString();
                        if (oKey.toLowerCase().startsWith("pb/")
                                || oKey.toLowerCase().startsWith("fn/")
                                || oKey.toLowerCase().startsWith("eso/")) {
                            JSONArray oActors = oActorObject.getJSONArray(oKey);
                            // System.out.println("oActors.toString() = " + oActors.toString());
                            if (intersectingActor(entityFilter, actors, oActors)) {
                                if (!coPartipantEvents.contains(oEvent)) {
                                     coPartipantEvents.add(oEvent);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return coPartipantEvents;
}
 
Example 10
Source File: CreateMicrostory.java    From EventCoreference with Apache License 2.0 4 votes vote down vote up
public static ArrayList<JSONObject> getEventsThroughCoparticipation(ArrayList<JSONObject> events,
                                                                ArrayList<JSONObject> storyEvents)
        throws JSONException {
    ArrayList<JSONObject> coPartipantEvents = new ArrayList<JSONObject>();
    for (int j = 0; j < events.size(); j++) {
        JSONObject jsonObject = events.get(j);
        JSONObject actorObject = jsonObject.getJSONObject("actors");
        Iterator keys = actorObject.sortedKeys();
        while (keys.hasNext()) {
            String key = keys.next().toString(); //role
            //  System.out.println("key = " + key);
            if (key.equalsIgnoreCase("pb/A0")
                    || key.equalsIgnoreCase("pb/A1")
                    || key.equalsIgnoreCase("pb/A2")
                    || key.equalsIgnoreCase("pb/A3")
                    || key.equalsIgnoreCase("pb/A4")
                    || key.toLowerCase().startsWith("fn/")
                    || key.toLowerCase().startsWith("eso/")) {
                JSONArray actors = actorObject.getJSONArray(key);
                // System.out.println("actors.toString() = " + actors.toString());
                for (int i = 0; i < storyEvents.size(); i++) {
                    JSONObject oEvent = storyEvents.get(i);
                    if (!oEvent.get("instance").toString().equals(jsonObject.get("instance").toString())) {
                        ///skip event itself
                        JSONObject oActorObject = oEvent.getJSONObject("actors");
                        Iterator oKeys = oActorObject.sortedKeys();
                        while (oKeys.hasNext()) {
                            String oKey = oKeys.next().toString();
                            if (oKey.equalsIgnoreCase("pb/A0")
                                    || oKey.equalsIgnoreCase("pb/A1")
                                    || oKey.equalsIgnoreCase("pb/A2")
                                    || oKey.equalsIgnoreCase("pb/A3")
                                    || oKey.equalsIgnoreCase("pb/A4")
                                    || oKey.toLowerCase().startsWith("fn/")
                                    || oKey.toLowerCase().startsWith("eso/")) {
                                JSONArray oActors = oActorObject.getJSONArray(oKey);
                                // System.out.println("oActors.toString() = " + oActors.toString());
                                if (intersectingDBpActor(actors, oActors)) {
                                    if (!coPartipantEvents.contains(oEvent)) {
                                        coPartipantEvents.add(oEvent);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return coPartipantEvents;
}