Search in sources :

Example 41 with ArrayNode

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);
}
Also used : CorefFeature(org.apache.stanbol.enhancer.nlp.coref.CorefFeature) SpanTypeEnum(org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum) ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Span(org.apache.stanbol.enhancer.nlp.model.Span) HashSet(java.util.HashSet)

Example 42 with ArrayNode

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();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) CachedSearch(com.netflix.exhibitor.core.index.CachedSearch) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) LogSearch(com.netflix.exhibitor.core.index.LogSearch) ArrayNode(org.codehaus.jackson.node.ArrayNode) SimpleDateFormat(java.text.SimpleDateFormat) SearchItem(com.netflix.exhibitor.core.index.SearchItem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 43 with ArrayNode

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();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode)

Example 44 with ArrayNode

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;
}
Also used : Response(com.ning.http.client.Response) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) FstStats(de.spinscale.elasticsearch.action.suggest.statistics.FstStats) ShardId(org.elasticsearch.index.shard.ShardId) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ArrayNode (org.codehaus.jackson.node.ArrayNode)44 ObjectNode (org.codehaus.jackson.node.ObjectNode)29 JsonNode (org.codehaus.jackson.JsonNode)17 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)11 GET (javax.ws.rs.GET)10 Test (org.junit.Test)10 Path (javax.ws.rs.Path)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Date (java.util.Date)4 List (java.util.List)4 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Produces (javax.ws.rs.Produces)3 RegressionTestHelper (org.openmrs.module.htmlformentry.RegressionTestHelper)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2