use of org.apache.tapestry5.json.JSONArray in project JsonPath by jayway.
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);
}
use of org.apache.tapestry5.json.JSONArray in project JsonPath by jayway.
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);
}
use of org.apache.tapestry5.json.JSONArray 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');
}
}
}
use of org.apache.tapestry5.json.JSONArray in project IR_Base by Linda-sunshine.
the class HTSMAnalyzer method LoadNewEggDoc.
// Load a document and analyze it.
public void LoadNewEggDoc(String filename) {
JSONObject prod = null;
String item;
JSONArray itemIds, reviews;
try {
JSONObject json = LoadJSON(filename);
prod = json.getJSONObject(m_category);
itemIds = prod.names();
System.out.printf("Under %s category, Number of Items: %d\n", m_category, itemIds.length());
} catch (Exception e) {
System.out.print('X');
return;
}
for (int i = 0; i < itemIds.length(); i++) {
try {
item = itemIds.getString(i);
reviews = prod.getJSONArray(item);
for (int j = 0; j < reviews.length(); j++) {
if (this.m_stnDetector != null)
AnalyzeNewEggPostWithSentence(new _NewEggPost(reviews.getJSONObject(j), item));
else
AnalyzeNewEggPost(new _NewEggPost(reviews.getJSONObject(j), item));
}
} catch (JSONException e) {
System.out.print('P');
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
use of org.apache.tapestry5.json.JSONArray 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');
}
}
}
Aggregations