Search in sources :

Example 86 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.

the class CorefFeatureSupport method serialize.

@Override
public ObjectNode serialize(ObjectMapper mapper, CorefFeature coref) {
    ObjectNode jCoref = mapper.createObjectNode();
    jCoref.put(IS_REPRESENTATIVE_TAG, coref.isRepresentative());
    Set<Span> mentions = coref.getMentions();
    ArrayNode jMentions = mapper.createArrayNode();
    for (Span mention : mentions) {
        ObjectNode jMention = mapper.createObjectNode();
        jMention.put(MENTION_TYPE_TAG, mention.getType().toString());
        jMention.put(MENTION_START_TAG, mention.getStart());
        jMention.put(MENTION_END_TAG, mention.getEnd());
        jMentions.add(jMention);
    }
    jCoref.put(MENTIONS_TAG, jMentions);
    return jCoref;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Span(org.apache.stanbol.enhancer.nlp.model.Span)

Example 87 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode 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 88 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project YCSB by brianfrankcooper.

the class MemcachedClient method toJson.

protected static String toJson(Map<String, ByteIterator> values) throws IOException {
    ObjectNode node = MAPPER.createObjectNode();
    Map<String, String> stringMap = StringByteIterator.getStringMap(values);
    for (Map.Entry<String, String> pair : stringMap.entrySet()) {
        node.put(pair.getKey(), pair.getValue());
    }
    JsonFactory jsonFactory = new JsonFactory();
    Writer writer = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
    MAPPER.writeTree(jsonGenerator, node);
    return writer.toString();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) StringWriter(java.io.StringWriter) JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) HashMap(java.util.HashMap) Map(java.util.Map) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 89 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project apex-malhar by apache.

the class CouchDBTestHelper method createAndFetchViewQuery.

public static ViewQuery createAndFetchViewQuery() {
    if (!connector.contains(DESIGN_DOC_ID)) {
        // The design document doesn't exist in the database so we create it.
        JsonNode rootNode = mapper.createObjectNode();
        ((ObjectNode) rootNode).put("language", "javascript");
        ((ObjectNode) rootNode).putObject("views").putObject(TEST_VIEW).put("map", "function(doc) {\n  emit(doc._id, doc);\n}");
        connector.create(DESIGN_DOC_ID, rootNode);
    }
    return new ViewQuery().designDocId(DESIGN_DOC_ID).viewName(TEST_VIEW);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ViewQuery(org.ektorp.ViewQuery) JsonNode(org.codehaus.jackson.JsonNode)

Example 90 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project helix by apache.

the class WorkflowAccessor method getWorkflow.

@GET
@Path("{workflowId}")
public Response getWorkflow(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
    TaskDriver taskDriver = getTaskDriver(clusterId);
    WorkflowConfig workflowConfig = taskDriver.getWorkflowConfig(workflowId);
    WorkflowContext workflowContext = taskDriver.getWorkflowContext(workflowId);
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    TextNode id = JsonNodeFactory.instance.textNode(workflowId);
    root.put(Properties.id.name(), id);
    ObjectNode workflowConfigNode = JsonNodeFactory.instance.objectNode();
    ObjectNode workflowContextNode = JsonNodeFactory.instance.objectNode();
    if (workflowConfig != null) {
        getWorkflowConfigNode(workflowConfigNode, workflowConfig.getRecord());
    }
    if (workflowContext != null) {
        getWorkflowContextNode(workflowContextNode, workflowContext.getRecord());
    }
    root.put(WorkflowProperties.WorkflowConfig.name(), workflowConfigNode);
    root.put(WorkflowProperties.WorkflowContext.name(), workflowContextNode);
    JobDag jobDag = workflowConfig.getJobDag();
    ArrayNode jobs = OBJECT_MAPPER.valueToTree(jobDag.getAllNodes());
    ObjectNode parentJobs = OBJECT_MAPPER.valueToTree(jobDag.getChildrenToParents());
    root.put(WorkflowProperties.Jobs.name(), jobs);
    root.put(WorkflowProperties.ParentJobs.name(), parentJobs);
    return JSONRepresentation(root);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) WorkflowContext(org.apache.helix.task.WorkflowContext) TextNode(org.codehaus.jackson.node.TextNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) JobDag(org.apache.helix.task.JobDag) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3