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;
}
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);
}
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();
}
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);
}
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);
}
Aggregations