Search in sources :

Example 6 with JSONArray

use of json.JSONArray in project IR_Base by Linda-sunshine.

the class ParentChildAnalyzer method loadParentDoc.

public void loadParentDoc(String fileName) {
    if (fileName == null || fileName.isEmpty())
        return;
    JSONObject json = LoadJSON(fileName);
    String title = Utils.getJSONValue(json, "title");
    String content = Utils.getJSONValue(json, "content");
    String name = Utils.getJSONValue(json, "name");
    String[] sentences = null;
    // _ParentDoc d = new _ParentDoc(m_corpus.getSize(), name, title,
    // content, 0);
    _ParentDoc d = new _ParentDoc4DCM(m_corpus.getSize(), name, title, content, 0);
    try {
        JSONArray sentenceArray = json.getJSONArray("sentences");
        sentences = new String[sentenceArray.length()];
        // shall we add title into this sentence array
        for (int i = 0; i < sentenceArray.length(); i++) sentences[i] = Utils.getJSONValue(sentenceArray.getJSONObject(i), "sentence");
        if (AnalyzeDocByStn(d, sentences))
            parentHashMap.put(name, d);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : JSONObject(json.JSONObject) structures._ParentDoc(structures._ParentDoc) structures._ParentDoc4DCM(structures._ParentDoc4DCM) JSONArray(json.JSONArray) JSONException(json.JSONException)

Example 7 with JSONArray

use of json.JSONArray in project JsonPath by json-path.

the class TapestryJsonProvider method setArrayIndex.

@Override
public void setArrayIndex(final Object array, final int index, final Object newValue) {
    Object v = newValue == null ? JSONObject.NULL : newValue;
    JSONArray list = (JSONArray) array;
    list.put(index, v);
}
Also used : JSONArray(org.apache.tapestry5.json.JSONArray) JSONObject(org.apache.tapestry5.json.JSONObject)

Example 8 with JSONArray

use of json.JSONArray in project JsonPath by json-path.

the class TapestryJsonProviderTest method a_filter_can_be_applied.

@Test
public void a_filter_can_be_applied() {
    JSONArray fictionBooks = using(TAPESTRY_JSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[?(@.category == 'fiction')]");
    assertThat(fictionBooks.length()).isEqualTo(3);
}
Also used : JSONArray(org.apache.tapestry5.json.JSONArray) Test(org.junit.Test)

Aggregations

JSONArray (json.JSONArray)4 JSONException (json.JSONException)4 JSONObject (json.JSONObject)4 JSONArray (org.apache.tapestry5.json.JSONArray)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ParseException (java.text.ParseException)3 InvalidFormatException (opennlp.tools.util.InvalidFormatException)3 JSONObject (org.apache.tapestry5.json.JSONObject)2 Test (org.junit.Test)2 structures._Doc (structures._Doc)2 structures._Post (structures._Post)2 structures._Product (structures._Product)2 structures._NewEggPost (structures._NewEggPost)1 structures._ParentDoc (structures._ParentDoc)1 structures._ParentDoc4DCM (structures._ParentDoc4DCM)1