Search in sources :

Example 1 with structures._Product

use of structures._Product 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)

Example 2 with structures._Product

use of structures._Product in project IR_Base by Linda-sunshine.

the class MultiThreadedLMAnalyzer method LoadJsonDoc.

// Load a document and analyze it.
@Override
public void LoadJsonDoc(String filename) {
    _Product prod = null;
    JSONArray jarray = null;
    try {
        JSONObject json = LoadJSON(filename);
        prod = new _Product(json.getJSONObject("asin"));
        jarray = json.getJSONArray("related");
    } 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

FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 JSONArray (json.JSONArray)2 JSONException (json.JSONException)2 JSONObject (json.JSONObject)2 InvalidFormatException (opennlp.tools.util.InvalidFormatException)2 structures._Doc (structures._Doc)2 structures._Post (structures._Post)2 structures._Product (structures._Product)2