use of org.codehaus.jackson.node.ArrayNode in project stanbol by apache.
the class CorefFeatureSupport method parse.
@Override
public CorefFeature parse(ObjectNode jCoref, AnalysedText at) {
JsonNode jIsRepresentative = jCoref.path(IS_REPRESENTATIVE_TAG);
if (!jIsRepresentative.isBoolean()) {
throw new IllegalStateException("Field 'isRepresentative' must have a true/false format");
}
JsonNode node = jCoref.path(MENTIONS_TAG);
Set<Span> mentions = new HashSet<Span>();
if (node.isArray()) {
ArrayNode jMentions = (ArrayNode) node;
for (int i = 0; i < jMentions.size(); i++) {
JsonNode member = jMentions.get(i);
if (member.isObject()) {
ObjectNode jMention = (ObjectNode) member;
SpanTypeEnum spanType = SpanTypeEnum.valueOf(jMention.path(MENTION_TYPE_TAG).getTextValue());
int spanStart = jMention.path(MENTION_START_TAG).asInt();
int spanEnd = jMention.path(MENTION_END_TAG).asInt();
Span mentionedSpan = null;
switch(spanType) {
case Chunk:
mentionedSpan = at.addChunk(spanStart, spanEnd);
break;
case Sentence:
case Text:
case TextSection:
break;
case Token:
mentionedSpan = at.addToken(spanStart, spanEnd);
break;
}
mentions.add(mentionedSpan);
}
}
}
return new CorefFeature(jIsRepresentative.asBoolean(), mentions);
}
use of org.codehaus.jackson.node.ArrayNode in project exhibitor by soabase.
the class IndexResource method getDataTableData.
@Path("dataTable/{index-name}/{search-handle}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getDataTableData(@PathParam("index-name") String indexName, @PathParam("search-handle") String searchHandle, @QueryParam("iDisplayStart") int iDisplayStart, @QueryParam("iDisplayLength") int iDisplayLength, @QueryParam("sEcho") String sEcho) throws Exception {
LogSearch logSearch = getLogSearch(indexName);
if (logSearch == null) {
return "{}";
}
ObjectNode node;
try {
CachedSearch cachedSearch = logSearch.getCachedSearch(searchHandle);
DateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT_STR);
ArrayNode dataTab = JsonNodeFactory.instance.arrayNode();
for (int i = iDisplayStart; i < (iDisplayStart + iDisplayLength); ++i) {
if (i < cachedSearch.getTotalHits()) {
ObjectNode data = JsonNodeFactory.instance.objectNode();
int docId = cachedSearch.getNthDocId(i);
SearchItem item = logSearch.toResult(docId);
data.put("DT_RowId", "index-query-result-" + docId);
data.put("0", getTypeName(EntryTypes.getFromId(item.getType())));
data.put("1", dateFormatter.format(item.getDate()));
data.put("2", trimPath(item.getPath()));
dataTab.add(data);
}
}
node = JsonNodeFactory.instance.objectNode();
node.put("sEcho", sEcho);
node.put("iTotalRecords", logSearch.getDocQty());
node.put("iTotalDisplayRecords", cachedSearch.getTotalHits());
node.put("aaData", dataTab);
} finally {
context.getExhibitor().getIndexCache().releaseLogSearch(logSearch.getFile());
}
return node.toString();
}
use of org.codehaus.jackson.node.ArrayNode in project exhibitor by soabase.
the class ExplorerResource method getNode.
@GET
@Path("node")
@Produces("application/json")
public String getNode(@QueryParam("key") String key) throws Exception {
ArrayNode children = JsonNodeFactory.instance.arrayNode();
try {
List<String> childrenNames = context.getExhibitor().getLocalConnection().getChildren().forPath(key);
SmartSort.sortChildren(childrenNames);
for (String name : childrenNames) {
ObjectNode node = children.addObject();
node.put("title", name);
node.put("key", ZKPaths.makePath(key, name));
node.put("isLazy", true);
node.put("expand", false);
}
} catch (Throwable e) {
context.getExhibitor().resetLocalConnection();
context.getExhibitor().getLog().add(ActivityLog.Type.ERROR, "getNode: " + key, e);
ObjectNode node = children.addObject();
node.put("title", "* Exception *");
node.put("key", ERROR_KEY);
node.put("isLazy", false);
node.put("expand", false);
}
return children.toString();
}
use of org.codehaus.jackson.node.ArrayNode in project elasticsearch-suggest-plugin by spinscale.
the class RestSuggestActionTest method getStatistics.
@Override
public FstStats getStatistics() throws Exception {
List<FstStats.FstIndexShardStats> stats = Lists.newArrayList();
Response r = httpClient.prepareGet("http://localhost:" + port + "/__suggestStatistics").execute().get();
assertThat(r.getStatusCode(), is(200));
System.out.println(r.getResponseBody());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootObj = objectMapper.readTree(r.getResponseBody());
FstStats fstStats = new FstStats();
ArrayNode jsonFstStats = (ArrayNode) rootObj.get("fstStats");
Iterator<JsonNode> nodesIterator = jsonFstStats.iterator();
while (nodesIterator.hasNext()) {
JsonNode fstStatsNodeEntry = nodesIterator.next();
if (fstStatsNodeEntry.isObject()) {
ShardId shardId = new ShardId(fstStatsNodeEntry.get("index").asText(), fstStatsNodeEntry.get("id").asInt());
FstStats.FstIndexShardStats fstIndexShardStats = new FstStats.FstIndexShardStats(shardId, null, null, fstStatsNodeEntry.get("sizeInBytes").getLongValue());
stats.add(fstIndexShardStats);
}
fstStats.getStats().addAll(stats);
}
return fstStats;
}
Aggregations