use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.
the class AnalyzedTextParser method parseSpan.
private void parseSpan(AnalysedText at, JsonNode node) throws IOException {
if (node.isObject()) {
ObjectNode jSpan = (ObjectNode) node;
int[] spanPos = new int[] { -1, -1 };
Collection<Entry<String, JsonNode>> jAnnotations = new ArrayList<Entry<String, JsonNode>>(4);
SpanTypeEnum spanType = parseSpanData(jSpan, spanPos, jAnnotations);
if (spanType == null || spanPos[0] < 0 || spanPos[1] < 0) {
log.warn("Illegal or missing span type, start and/or end position (ignored, json: " + jSpan);
return;
}
// now create the Span
Span span;
switch(spanType) {
case Text:
log.warn("Encounterd 'Text' span that is not the first span in the " + "'spans' array (ignored, json: " + node + ")");
return;
case TextSection:
log.warn("Encountered 'TextSection' span. This SpanTypeEnum entry " + "is currently unused. If this is no longer the case please " + "update this implementation (ignored, json: " + node + ")");
return;
case Sentence:
span = at.addSentence(spanPos[0], spanPos[1]);
break;
case Chunk:
span = at.addChunk(spanPos[0], spanPos[1]);
break;
case Token:
span = at.addToken(spanPos[0], spanPos[1]);
break;
default:
log.warn("Unsupported SpanTypeEnum '" + spanType + "'!. Please " + "update this implementation (ignored, json: " + node + ")");
return;
}
if (!jAnnotations.isEmpty()) {
parseAnnotations(span, jAnnotations);
}
} else {
log.warn("Unable to parse Span form JsonNode " + node + " (expected JSON object)!");
}
}
use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.
the class DependencyRelationSupport method serialize.
@Override
public ObjectNode serialize(ObjectMapper mapper, DependencyRelation relation) {
ObjectNode jDependencyRelation = mapper.createObjectNode();
GrammaticalRelationTag gramRelTag = relation.getGrammaticalRelationTag();
jDependencyRelation.put(RELATION_TYPE_TAG, gramRelTag.getTag());
jDependencyRelation.put(RELATION_STANBOL_TYPE_TAG, gramRelTag.getGrammaticalRelation().ordinal());
jDependencyRelation.put(RELATION_IS_DEPENDENT_TAG, (relation.isDependent()));
Span partner = relation.getPartner();
if (partner != null) {
jDependencyRelation.put(RELATION_PARTNER_TYPE_TAG, partner.getType().toString());
jDependencyRelation.put(RELATION_PARTNER_START_TAG, partner.getStart());
jDependencyRelation.put(RELATION_PARTNER_END_TAG, partner.getEnd());
} else {
jDependencyRelation.put(RELATION_PARTNER_TYPE_TAG, ROOT_TAG);
jDependencyRelation.put(RELATION_PARTNER_START_TAG, 0);
jDependencyRelation.put(RELATION_PARTNER_END_TAG, 0);
}
return jDependencyRelation;
}
use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.
the class PosTagSupport method serialize.
@Override
public ObjectNode serialize(ObjectMapper mapper, PosTag value) {
ObjectNode jPosTag = mapper.createObjectNode();
jPosTag.put("tag", value.getTag());
if (value.getPos().size() == 1) {
jPosTag.put("pos", value.getPos().iterator().next().ordinal());
} else if (!value.getPos().isEmpty()) {
ArrayNode jPos = mapper.createArrayNode();
for (Pos pos : value.getPos()) {
jPos.add(pos.ordinal());
}
jPosTag.put("pos", jPos);
}
if (!value.getCategories().isEmpty()) {
// we need only the categories not covered by Pos elements
EnumSet<LexicalCategory> categories = EnumSet.noneOf(LexicalCategory.class);
categories.addAll(value.getCategories());
for (Pos pos : value.getPos()) {
categories.removeAll(pos.categories());
}
if (categories.size() == 1) {
jPosTag.put("lc", categories.iterator().next().ordinal());
} else if (!categories.isEmpty()) {
ArrayNode jCategory = mapper.createArrayNode();
for (LexicalCategory lc : categories) {
jCategory.add(lc.ordinal());
}
jPosTag.put("lc", jCategory);
}
}
return jPosTag;
}
use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.
the class AnalyzedTextSerializer method writeSpan.
private ObjectNode writeSpan(Span span) throws IOException {
log.trace("wirte {}", span);
ObjectNode jSpan = mapper.createObjectNode();
jSpan.put("type", span.getType().name());
jSpan.put("start", span.getStart());
jSpan.put("end", span.getEnd());
for (String key : span.getKeys()) {
List<Value<?>> values = span.getValues(key);
if (values.size() == 1) {
jSpan.put(key, writeValue(values.get(0)));
} else {
ArrayNode jValues = jSpan.putArray(key);
for (Value<?> value : values) {
jValues.add(writeValue(value));
}
jSpan.put(key, jValues);
}
}
log.trace(" ... {}", jSpan);
return jSpan;
}
use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.
the class AnalyzedTextSerializer method writeValue.
@SuppressWarnings({ "rawtypes", "unchecked" })
private ObjectNode writeValue(Value<?> value) {
ObjectNode jValue;
Class<?> valueType = value.value().getClass();
ValueTypeSerializer vts = valueTypeSerializerRegistry.getSerializer(valueType);
if (vts != null) {
jValue = vts.serialize(mapper, value.value());
// TODO assert that jValue does not define "class" and "prob"!
} else {
// use the default binding and the "data" field
jValue = mapper.createObjectNode();
jValue.put("value", mapper.valueToTree(value.value()));
}
jValue.put("class", valueType.getName());
if (value.probability() != Value.UNKNOWN_PROBABILITY) {
jValue.put("prob", value.probability());
}
return jValue;
}
Aggregations