Search in sources :

Example 1 with JSONObject

use of json.JSONObject in project JsonPath by jayway.

the class TapestryJsonProviderTest method an_object_can_be_read.

@Test
public void an_object_can_be_read() {
    JSONObject book = using(TAPESTRY_JSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[0]");
    assertThat(book.get("author").toString()).isEqualTo("Nigel Rees");
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) Test(org.junit.Test)

Example 2 with JSONObject

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

the class ParentChildAnalyzer method LoadDoc.

public void LoadDoc(String fileName) {
    if (fileName == null || fileName.isEmpty())
        return;
    JSONObject json = LoadJSON(fileName);
    String content = Utils.getJSONValue(json, "content");
    String name = Utils.getJSONValue(json, "name");
    String parent = Utils.getJSONValue(json, "parent");
    _Doc d = new _Doc(m_corpus.getSize(), content, 0);
    d.setName(name);
    AnalyzeDoc(d);
}
Also used : JSONObject(json.JSONObject) structures._Doc(structures._Doc)

Example 3 with JSONObject

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

the class ParentChildAnalyzer method loadChildDoc.

public void loadChildDoc(String fileName) {
    if (fileName == null || fileName.isEmpty())
        return;
    JSONObject json = LoadJSON(fileName);
    String content = Utils.getJSONValue(json, "content");
    String name = Utils.getJSONValue(json, "name");
    String parent = Utils.getJSONValue(json, "parent");
    String title = Utils.getJSONValue(json, "title");
    // 
    // _ChildDoc4BaseWithPhi d = new _ChildDoc4BaseWithPhi(m_corpus.getSize(),
    // name, "", content, 0);
    // _ChildDoc4BaseWithPhi_Hard d = new _ChildDoc4BaseWithPhi_Hard(m_corpus.getSize(), name, "", content, 0) ;
    // _ChildDoc4ChildPhi d = new _ChildDoc4ChildPhi(m_corpus.getSize(),
    // name,
    // "", content, 0);
    // _ChildDoc4TwoPhi d = new _ChildDoc4TwoPhi(m_corpus.getSize(), name, "", content, 0);
    // _ChildDoc4ThreePhi d = new _ChildDoc4ThreePhi(m_corpus.getSize(), name,
    // "", content, 0);
    // _ChildDoc4OneTopicProportion d = new _ChildDoc4OneTopicProportion(m_corpus.getSize(), name, "", content, 0);
    _ChildDoc d = new _ChildDoc(m_corpus.getSize(), name, "", content, 0);
    if (parentHashMap.containsKey(parent)) {
        if (AnalyzeDoc(d)) {
            // this is a valid child document
            // if (parentHashMap.containsKey(parent)) {
            _ParentDoc pDoc = parentHashMap.get(parent);
            d.setParentDoc(pDoc);
            pDoc.addChildDoc(d);
        } else {
        // System.err.format("filtering comments %s!\n", parent);
        }
    } else {
    // System.err.format("[Warning]Missing parent document %s!\n", parent);
    }
}
Also used : structures._ChildDoc(structures._ChildDoc) JSONObject(json.JSONObject) structures._ParentDoc(structures._ParentDoc)

Example 4 with JSONObject

use of json.JSONObject in project tapestry5-hotel-booking by ccordenier.

the class AjaxLoader method initAjaxLoader.

@BeginRender
void initAjaxLoader(MarkupWriter writer) {
    loader = javascriptSupport.allocateClientId("loader");
    JSONObject data = new JSONObject();
    data.put("zone", zone);
    data.put("trigger", trigger);
    data.put("loader", loader);
    javascriptSupport.addInitializerCall(InitializationPriority.NORMAL, "initAjaxLoader", data);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) BeginRender(org.apache.tapestry5.annotations.BeginRender)

Example 5 with JSONObject

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

the class DocAnalyzer method LoadJsonDoc.

// Load a document and analyze it.
protected void LoadJsonDoc(String filename) {
    _Product prod = null;
    JSONArray jarray = null;
    try {
        JSONObject json = LoadJSON(filename);
        prod = new _Product(json.getJSONObject("ProductInfo"));
        jarray = json.getJSONArray("Reviews");
    } catch (Exception e) {
        // fail to parse a json document
        System.err.print('X');
        return;
    }
    for (int i = 0; i < jarray.length(); i++) {
        try {
            _Post post = new _Post(jarray.getJSONObject(i));
            if (post.isValid(m_dateFormatter)) {
                long timeStamp = m_dateFormatter.parse(post.getDate()).getTime();
                String content;
                // append document title into document content
                if (Utils.endWithPunct(post.getTitle()))
                    content = post.getTitle() + " " + post.getContent();
                else
                    content = post.getTitle() + ". " + post.getContent();
                // int ID, String name, String prodID, String title, String source, int ylabel, long timeStamp
                _Doc review = new _Doc(m_corpus.getSize(), post.getID(), prod.getID(), post.getTitle(), content, post.getLabel() - 1, timeStamp);
                if (this.m_stnDetector != null)
                    AnalyzeDocWithStnSplit(review);
                else
                    AnalyzeDoc(review);
            }
        } catch (ParseException e) {
            System.out.print('T');
        } catch (JSONException e) {
            System.out.print('P');
        }
    }
}
Also used : JSONObject(json.JSONObject) structures._Doc(structures._Doc) structures._Product(structures._Product) JSONArray(json.JSONArray) JSONException(json.JSONException) ParseException(java.text.ParseException) JSONException(json.JSONException) InvalidFormatException(opennlp.tools.util.InvalidFormatException) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) structures._Post(structures._Post)

Aggregations

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